Package org.gearman.client
Class GearmanJobImpl
- java.lang.Object
-
- org.gearman.client.GearmanJobImpl
-
- All Implemented Interfaces:
Callable<GearmanJobResult>
,Future<GearmanJobResult>
,GearmanJob
,GearmanServerResponseHandler
public final class GearmanJobImpl extends Object implements GearmanJob, GearmanServerResponseHandler
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.gearman.client.GearmanJob
GearmanJob.JobPriority
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GearmanJobResult
call()
boolean
cancel(boolean mayInterruptIfRunning)
static GearmanJob
createBackgroundJob(String functionName, byte[] data, String id)
static GearmanJob
createBackgroundJob(String functionName, byte[] data, GearmanJob.JobPriority priority, String id)
static GearmanJob
createJob(String functionName, byte[] data, String id)
static GearmanJob
createJob(String functionName, byte[] data, GearmanJob.JobPriority priority, String id)
GearmanJobResult
get()
GearmanJobResult
get(long timeout, TimeUnit unit)
byte[]
getData()
Retrieve the data against which the job is executed.String
getFunctionName()
Retrieve the name of theGearmanFunction
registered with this job.byte[]
getHandle()
Retrieves the handle used by the Gearman Job Server to which this job was submitted to as a means to identify this job.byte[]
getID()
Retrieves a unique ID used to identify this job.GearmanJob.JobPriority
getPriority()
Retrieve the priority associated with this job.void
handleEvent(GearmanPacket event)
boolean
isBackgroundJob()
Determines if this job is a background job.boolean
isCancelled()
boolean
isDone()
void
registerEventListener(GearmanIOEventListener listener)
As a GearmanJob progress through its' lifecycle, it will receives a series of events notifications from the Gearman Job Server.void
registerFunction(Callable<GearmanJobResult> function)
Registers a particularGearmanFunction
with this job.boolean
removeEventListener(GearmanIOEventListener listener)
removes aGearmanIOEventListener
from recieving event notifications.void
setJobServerSession(GearmanJobServerSession sess)
String
toString()
-
-
-
Method Detail
-
createJob
public static GearmanJob createJob(String functionName, byte[] data, GearmanJob.JobPriority priority, String id) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
createJob
public static GearmanJob createJob(String functionName, byte[] data, String id) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
createBackgroundJob
public static GearmanJob createBackgroundJob(String functionName, byte[] data, GearmanJob.JobPriority priority, String id) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
createBackgroundJob
public static GearmanJob createBackgroundJob(String functionName, byte[] data, String id) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
getHandle
public byte[] getHandle()
Description copied from interface:GearmanJob
Retrieves the handle used by the Gearman Job Server to which this job was submitted to as a means to identify this job.- Specified by:
getHandle
in interfaceGearmanJob
- Returns:
- The handle assigned to the job by the Gearman Job Server. If the job has not been submitted to a Gearman Job Server, then returns an empty array.
-
getID
public byte[] getID()
Description copied from interface:GearmanJob
Retrieves a unique ID used to identify this job. The ID is created when the Job is created, as opposed to the handle which is created by the Job Server once the job has been submitted.- Specified by:
getID
in interfaceGearmanJob
- Returns:
- A unique used to identify this job.
-
getData
public byte[] getData()
Description copied from interface:GearmanJob
Retrieve the data against which the job is executed. This data is contained inGearmanFunction
that has been registered with this job.- Specified by:
getData
in interfaceGearmanJob
- Returns:
- The data against which the job is executed or if no data has been specified, returns an empty array.
-
getFunctionName
public String getFunctionName()
Description copied from interface:GearmanJob
Retrieve the name of theGearmanFunction
registered with this job.- Specified by:
getFunctionName
in interfaceGearmanJob
- Returns:
- function name
-
isBackgroundJob
public boolean isBackgroundJob()
Description copied from interface:GearmanJob
Determines if this job is a background job. A background job is a job which does not send status updates back to theGearmanClient
that submitted the job. Unlike non-background jobs, executingFuture.get()
will not block until job completion. Nor will a background job return aGearmanJobResult
when it has finished execution. To determine the status of background job, you must executeGearmanClient.getJobStatus(org.gearman.client.GearmanJob)
.- Specified by:
isBackgroundJob
in interfaceGearmanJob
- Returns:
- true if the job is a background job, else returns false.
-
getPriority
public GearmanJob.JobPriority getPriority()
Description copied from interface:GearmanJob
Retrieve the priority associated with this job.- Specified by:
getPriority
in interfaceGearmanJob
- Returns:
- Job Priority
-
isCancelled
public boolean isCancelled()
- Specified by:
isCancelled
in interfaceFuture<GearmanJobResult>
-
isDone
public boolean isDone()
- Specified by:
isDone
in interfaceFuture<GearmanJobResult>
- Specified by:
isDone
in interfaceGearmanServerResponseHandler
-
setJobServerSession
public void setJobServerSession(GearmanJobServerSession sess)
-
registerFunction
public void registerFunction(Callable<GearmanJobResult> function)
Description copied from interface:GearmanJob
Registers a particularGearmanFunction
with this job. The GearmanFunction contains the definition for how the job will be executed and the data against which the execution will occurr.- Specified by:
registerFunction
in interfaceGearmanJob
- Parameters:
function
- The function defining job execution and data.
-
registerEventListener
public void registerEventListener(GearmanIOEventListener listener)
Description copied from interface:GearmanJob
As a GearmanJob progress through its' lifecycle, it will receives a series of events notifications from the Gearman Job Server. For example when the job has been successfully submitted to the sever, it will receive a JOB_CREATED notification, or when some intermediate data has been sent back from the worker, than a WORK_DATA event is generated.This method lets user register listeners who will receive notifications when a particular event has been received from the Gearman Job Server. See
GearmanIOEventListener
for the list of events that can listened for and handled by the listener.- Specified by:
registerEventListener
in interfaceGearmanJob
- Parameters:
listener
- the listener to which event notifications will be sent.
-
removeEventListener
public boolean removeEventListener(GearmanIOEventListener listener)
Description copied from interface:GearmanJob
removes aGearmanIOEventListener
from recieving event notifications.- Specified by:
removeEventListener
in interfaceGearmanJob
- Parameters:
listener
- the listener to be removed.- Returns:
- true if the listener has been removed, else false.
-
call
public GearmanJobResult call()
- Specified by:
call
in interfaceCallable<GearmanJobResult>
-
get
public GearmanJobResult get() throws InterruptedException, ExecutionException
- Specified by:
get
in interfaceFuture<GearmanJobResult>
- Throws:
InterruptedException
ExecutionException
-
get
public GearmanJobResult get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
- Specified by:
get
in interfaceFuture<GearmanJobResult>
- Throws:
InterruptedException
ExecutionException
TimeoutException
-
handleEvent
public void handleEvent(GearmanPacket event) throws GearmanException
- Specified by:
handleEvent
in interfaceGearmanServerResponseHandler
- Throws:
GearmanException
-
cancel
public boolean cancel(boolean mayInterruptIfRunning)
- Specified by:
cancel
in interfaceFuture<GearmanJobResult>
-
-