private ResponseMessage HandleMessage(RequestMessage msg)
        {
            IndexingServiceRequest isr = (IndexingServiceRequest)msg;

            LuceneQueryable backend = this;

            if (isr.Source != null)
            {
                Queryable target = QueryDriver.GetQueryable(isr.Source);

                if (target == null)
                {
                    string err = String.Format("Unable to find backend matching '{0}'", isr.Source);

                    Log.Error(err);
                    return(new ErrorResponse(err));
                }

                if (!(target.IQueryable is LuceneQueryable))
                {
                    string err = String.Format("Backend '{0}' is not an indexed backend", isr.Source);

                    Log.Error(err);
                    return(new ErrorResponse(err));
                }

                backend = (LuceneQueryable)target.IQueryable;
                Log.Debug("Found backend for IndexingServiceRequest: {0}", backend.IndexName);
            }

            // FIXME: There should be a way for the request to control the
            // scheduler priority of the task.

            if (isr.ToAdd.Count > 0 || isr.ToRemove.Count > 0)
            {
                Log.Debug("IndexingService: Adding {0} indexables, removing {1} indexables.", isr.ToAdd.Count, isr.ToRemove.Count);

                IndexableGenerator ind_gen;
                ind_gen = new IndexableGenerator(isr.ToAdd, isr.ToRemove, this);
                Scheduler.Task task = backend.NewAddTask(ind_gen);
                task.Priority = Scheduler.Priority.Immediate;
                ThisScheduler.Add(task);
            }

            // FIXME: There should be an asynchronous response  (fired by a Scheduler.Hook)
            // that fires when all of the items have been added to the index.

            // No response
            return(new EmptyResponse());
        }
        public void Add(Indexable indexable, Scheduler.Priority priority)
        {
            lock (indexables) {
                indexables.Enqueue(indexable);

                if (priority > highest_prio)
                {
                    highest_prio = priority;
                }

                if (self_task == null)
                {
                    self_task          = queryable.NewAddTask(this);
                    self_task.Priority = highest_prio;
                    queryable.ThisScheduler.Add(self_task);
                }
                else
                {
                    self_task.Priority = highest_prio;
                }
            }
        }