Scheduler.java
上传用户:qing5858
上传日期:2015-10-27
资源大小:6056k
文件大小:3k
源码类别:

搜索引擎

开发平台:

Java

  1. package net.javacoding.jspider.core.task;
  2. import net.javacoding.jspider.core.exception.TaskAssignmentException;
  3. import net.javacoding.jspider.core.task.work.DecideOnSpideringTask;
  4. import java.net.URL;
  5. /**
  6.  * Interface that will be implemented upon each object that will act as a task
  7.  * scheduler.
  8.  * The Task scheduler will keep track of all work that is being done and all
  9.  * tasks that still have to be carried out.
  10.  *
  11.  * $Id: Scheduler.java,v 1.10 2003/04/25 21:28:59 vanrogu Exp $
  12.  *
  13.  * @author  G黱ther Van Roey
  14.  */
  15. public interface Scheduler {
  16.     /**
  17.      * Schedules a Worker Task to be executed.  The scheduler will keep a
  18.      * reference to the task and return it later on to be processed.
  19.      * @param task task to be scheduled
  20.      */
  21.     public void schedule(WorkerTask task);
  22.     /**
  23.      * Block a task for a certain siteURL.  This is used to block any
  24.      * resource handling for a site for which we didn't interpret the
  25.      * robots.txt file yet.
  26.      * @param siteURL the site for which the task is
  27.      * @param task the task to be temporarily blocked
  28.      */
  29.     public void block( URL siteURL, DecideOnSpideringTask task);
  30.     /**
  31.      * Returns all tasks that were blocked for the specified site, and
  32.      * removes them from the blocked resources pool.
  33.      * @param siteURL the site we want to unblock all resources for
  34.      * @return array with all tasks that were blocked for this site
  35.      */
  36.     public DecideOnSpideringTask[] unblock(URL siteURL);
  37.     /**
  38.      * Flags a task as done.  This way, we are able to remove the task from
  39.      * the in-process list.
  40.      * @param task task that was completed
  41.      */
  42.     public void flagDone(WorkerTask task);
  43.     /**
  44.      * Returns a thinker task to be processed
  45.      * @return Task to be carried out
  46.      * @throws TaskAssignmentException if all the work is done or no suitable
  47.      * items are found for the moment.
  48.      */
  49.     public WorkerTask getThinkerTask() throws TaskAssignmentException;
  50.     /**
  51.      * Returns a fetch task to be processed
  52.      * @return Task to be carried out
  53.      * @throws TaskAssignmentException if all the work is done or no suitable
  54.      * items are found for the moment.
  55.      */
  56.     public WorkerTask getFethTask() throws TaskAssignmentException;
  57.     /**
  58.      * Determines whether all the tasks are done.   If there are no more tasks
  59.      * scheduled for process, and no ongoing tasks, it is impossible that new
  60.      * work will arrive, so the spidering is done.
  61.      * @return boolean value determining whether all work is done
  62.      */
  63.     public boolean allTasksDone();
  64.     /**
  65.      * Statistics method.
  66.      * @return blocked jobs counter
  67.      */
  68.     public int getBlockedCount( );
  69.     /**
  70.      * Statistics method.
  71.      * @return assigned jobs counter
  72.      */
  73.     public int getAssignedCount( );
  74.     /**
  75.      * Statistics method.
  76.      * @return total jobs counter
  77.      */
  78.     public int getJobCount ( );
  79.     /**
  80.      * Statistics method.
  81.      * @return total thinker jobs counter
  82.      */
  83.     public int getThinkerJobCount ( );
  84.     /**
  85.      * Statistics method.
  86.      * @return total spider jobs counter
  87.      */
  88.     public int getSpiderJobCount ( );
  89.     /**
  90.      * Statistics method.
  91.      * @return jobs finished counter
  92.      */
  93.     public int getJobsDone ( );
  94.     /**
  95.      * Statistics method.
  96.      * @return finished spider jobs counter
  97.      */
  98.     public int getSpiderJobsDone ( );
  99.     /**
  100.      * Statistics method.
  101.      * @return finished thinker jobs counter
  102.      */
  103.     public int getThinkerJobsDone ( );
  104. }