Interface GearmanClient

  • All Superinterfaces:
    Executor, ExecutorService
    All Known Implementing Classes:
    GearmanClientImpl

    public interface GearmanClient
    extends ExecutorService
    This interface through which users of the Gearman Java Libaray will use to submit jobs for execution by the Gearman System and to track the progess of those jobs.

    Users of a GearmanClient will first instantiate a GearmanClient instance. After the instance has been created, the user will need to register the set of GearmanJobServerConnection connections which are to be availble to client for job submission.

    Once the GearmanClient has been configured with the appropriate set of GearmanJobServerConnection, the user may begin using the GearmanClient to submit jobs for execution. This is accomplished by passing a GearmanJob to either the ExecutorService.submit(java.util.concurrent.Callable) or the ExecutorService.invokeAll(java.util.Collection) methods. Both of these methods return a Future object which can be used to track the state of that job.

    A GearmanClient can be shut down, which will cause it to stop accepting new tasks. After being shut down, the client will eventually terminate, at which point no tasks are actively executing, no tasks are awaiting execution, and no new tasks can be submitted

    Usage Example

    Here is an example of how to use a GearmanClient to submit and monitor the execution of a GearmanJob (Note, this example does not show the creation of the GearmanClient instance nor the creation of the GearmanJob or Connection as these details are implementation specific):
         org.gearman.common.GearmanJobServerConnection conn;
         org.gearman.client.GearmanClient client;
         org.gearman.client.GearmanJob job;
    
         // Here you would instantiate the client and job
    
         client.addJobServer(conn);
    
         Future jobFuture = client.submit(job);
    
         GearmanJobResult result = jobFuture.get();
         ...