Package org.gearman.client
Class GearmanClientImpl
- java.lang.Object
-
- org.gearman.client.GearmanClientImpl
-
- All Implemented Interfaces:
Executor
,ExecutorService
,GearmanClient
,GearmanSessionEventHandler
public class GearmanClientImpl extends Object implements GearmanClient, GearmanSessionEventHandler
-
-
Constructor Summary
Constructors Constructor Description GearmanClientImpl()
Create a new GearmanClient instance.GearmanClientImpl(long driveRequestTimeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addJobServer(String host, int port)
boolean
addJobServer(String host, int port, boolean serverForwardsExceptions)
boolean
addJobServer(GearmanJobServerConnection newconn)
Register a new Gearman Job Server with the client.boolean
addJobServer(GearmanJobServerConnection newconn, boolean serverForwardsExceptions)
boolean
awaitTermination(long timeout, TimeUnit unit)
byte[]
echo(byte[] data)
void
execute(Runnable command)
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.int
getNumberofActiveJobs()
List<GearmanJobServerConnection>
getSetOfJobServers()
Retrieve the list of Gearman Job Servers connections that have been registered with this client.void
handleSessionEvent(GearmanSessionEvent event)
boolean
hasConnection(GearmanJobServerConnection conn)
List
invokeAll(Collection tasks)
List
invokeAll(Collection tasks, long timeout, TimeUnit unit)
Future
invokeAny(Collection tasks)
Future
invokeAny(Collection tasks, long timeout, TimeUnit unit)
boolean
isShutdown()
boolean
isTerminated()
void
removeJobServer(GearmanJobServerConnection conn)
Unregisters a Gearman Job Server Connection from use by this client.void
shutdown()
List<Runnable>
shutdownNow()
Future<?>
submit(Runnable task)
<T> Future<T>
submit(Runnable task, T result)
<T> Future<T>
submit(Callable<T> task)
String
toString()
-
-
-
Method Detail
-
addJobServer
public boolean addJobServer(String host, int port)
-
addJobServer
public boolean addJobServer(String host, int port, boolean serverForwardsExceptions)
-
addJobServer
public boolean addJobServer(GearmanJobServerConnection newconn) throws IllegalArgumentException, IllegalStateException
Description copied from interface:GearmanClient
Register a new Gearman Job Server with the client.- Specified by:
addJobServer
in interfaceGearmanClient
- Parameters:
newconn
- 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.
-
addJobServer
public boolean addJobServer(GearmanJobServerConnection newconn, boolean serverForwardsExceptions) throws IllegalArgumentException, IllegalStateException
-
hasConnection
public boolean hasConnection(GearmanJobServerConnection conn)
-
getSetOfJobServers
public List<GearmanJobServerConnection> getSetOfJobServers() throws IllegalStateException
Description copied from interface:GearmanClient
Retrieve the list of Gearman Job Servers connections that have been registered with this client.- Specified by:
getSetOfJobServers
in interfaceGearmanClient
- Returns:
- the list of registered Gearman Job Servers.
- Throws:
IllegalStateException
- If the client has already been stopped.
-
removeJobServer
public void removeJobServer(GearmanJobServerConnection conn) throws IllegalArgumentException, IllegalStateException
Description copied from interface:GearmanClient
Unregisters a Gearman Job Server Connection from use by this client.- Specified by:
removeJobServer
in interfaceGearmanClient
- 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.
-
submit
public <T> Future<T> submit(Callable<T> task)
- Specified by:
submit
in interfaceExecutorService
-
submit
public <T> Future<T> submit(Runnable task, T result)
- Specified by:
submit
in interfaceExecutorService
-
submit
public Future<?> submit(Runnable task)
- Specified by:
submit
in interfaceExecutorService
-
invokeAll
public List invokeAll(Collection tasks) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAll
public List invokeAll(Collection tasks, long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
invokeAll
in interfaceExecutorService
- Throws:
InterruptedException
-
invokeAny
public Future invokeAny(Collection tasks) throws InterruptedException, ExecutionException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
-
invokeAny
public Future invokeAny(Collection tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
invokeAny
in interfaceExecutorService
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
getJobStatus
public GearmanJobStatus getJobStatus(GearmanJob job) throws IOException, GearmanException, IllegalStateException
Description copied from interface:GearmanClient
Sends a WORK_STATUS request to the Gearman Job Server running theGearmanJob
and then returnsGearmanJobStatus
representing the current status of the job.- Specified by:
getJobStatus
in interfaceGearmanClient
- 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.GearmanException
-
echo
public byte[] echo(byte[] data) throws IOException, GearmanException
- Throws:
IOException
GearmanException
-
getNumberofActiveJobs
public int getNumberofActiveJobs() throws IllegalStateException
- Throws:
IllegalStateException
-
handleSessionEvent
public void handleSessionEvent(GearmanSessionEvent event) throws IllegalArgumentException, IllegalStateException
- Specified by:
handleSessionEvent
in interfaceGearmanSessionEventHandler
- Throws:
IllegalArgumentException
IllegalStateException
-
shutdown
public void shutdown()
- Specified by:
shutdown
in interfaceExecutorService
-
shutdownNow
public List<Runnable> shutdownNow()
- Specified by:
shutdownNow
in interfaceExecutorService
-
isShutdown
public boolean isShutdown()
- Specified by:
isShutdown
in interfaceExecutorService
-
isTerminated
public boolean isTerminated()
- Specified by:
isTerminated
in interfaceExecutorService
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException
- Specified by:
awaitTermination
in interfaceExecutorService
- Throws:
InterruptedException
-
-