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 aGearmanJob
to either theExecutorService.submit(java.util.concurrent.Callable)
or theExecutorService.invokeAll(java.util.Collection)
methods. Both of these methods return aFuture
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 aGearmanJob
(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(); ...
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description boolean
addJobServer(GearmanJobServerConnection conn)
Register a new Gearman Job Server with the client.GearmanJobStatus
getJobStatus(GearmanJob job)
Sends a WORK_STATUS request to the Gearman Job Server running theGearmanJob
and then returnsGearmanJobStatus
representing the current status of the job.List<GearmanJobServerConnection>
getSetOfJobServers()
Retrieve the list of Gearman Job Servers connections that have been registered with this client.void
removeJobServer(GearmanJobServerConnection conn)
Unregisters a Gearman Job Server Connection from use by this client.-
Methods inherited from interface java.util.concurrent.ExecutorService
awaitTermination, invokeAll, invokeAll, invokeAny, invokeAny, isShutdown, isTerminated, shutdown, shutdownNow, submit, submit, submit
-
-
-
-
Method Detail
-
addJobServer
boolean addJobServer(GearmanJobServerConnection conn) throws IllegalArgumentException, IllegalStateException
Register a new Gearman Job Server with the client.- Parameters:
conn
- The connection to the Gearman Job Server.- Returns:
- returns true if a connection to the server was established and the server was added to the client, else false.
- Throws:
IllegalArgumentException
- If an invalid connection has been specified.IllegalStateException
- If the client has already been stopped.
-
getSetOfJobServers
List<GearmanJobServerConnection> getSetOfJobServers() throws IllegalStateException
Retrieve the list of Gearman Job Servers connections that have been registered with this client.- Returns:
- the list of registered Gearman Job Servers.
- Throws:
IllegalStateException
- If the client has already been stopped.
-
removeJobServer
void removeJobServer(GearmanJobServerConnection conn) throws IllegalArgumentException, IllegalStateException
Unregisters a Gearman Job Server Connection from use by this client.- Parameters:
conn
- The connection to the Gearman Job Server to be unregistered.- Throws:
IllegalArgumentException
- If an invalid connection has been specified.IllegalStateException
- If the client has already been stopped or the connection is currently processing one or more requests.
-
getJobStatus
GearmanJobStatus getJobStatus(GearmanJob job) throws IOException, IllegalStateException
Sends a WORK_STATUS request to the Gearman Job Server running theGearmanJob
and then returnsGearmanJobStatus
representing the current status of the job.- Parameters:
job
- The job for which status request is being made.- Returns:
- The status of the specified job.
- Throws:
IOException
IllegalStateException
- If the client has already been stopped.
-
-