Package org.gearman.worker
Class AbstractGearmanFunction
- java.lang.Object
-
- org.gearman.worker.AbstractGearmanFunction
-
- All Implemented Interfaces:
Callable<GearmanJobResult>
,GearmanFunction
- Direct Known Subclasses:
DigestFunction
,ReverseFunction
public abstract class AbstractGearmanFunction extends Object implements GearmanFunction
-
-
Constructor Summary
Constructors Constructor Description AbstractGearmanFunction()
AbstractGearmanFunction(String name)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description GearmanJobResult
call()
abstract GearmanJobResult
executeFunction()
void
fireEvent(GearmanPacket event)
Allows allGearmanIOEventListener
registered with this function to handle the specified event.byte[]
getJobHandle()
Retrieves the handle for the job that is executing this function.String
getName()
Retrieves the name of the funcion to be executed by the job.byte[]
getUniqueId()
Returns the Unique ID given to this job by the clientvoid
registerEventListener(GearmanIOEventListener listener)
As a function executes, it can generate a series of I/O Events -- in the form of aGearmanPacket
-- that can be handled by a series of listeners.void
sendData(byte[] data)
void
sendException(byte[] exception)
void
sendStatus(int denominator, int numerator)
void
sendWarning(byte[] warning)
void
setData(Object data)
Some functions require a dataset upon which to operate.void
setJobHandle(byte[] handle)
Set the handle of the job for which this function is executing.void
setUniqueId(byte[] uuid)
Set the Unique ID given to this job by the client
-
-
-
Field Detail
-
name
protected final String name
-
data
protected Object data
-
jobHandle
protected byte[] jobHandle
-
listeners
protected Set<GearmanIOEventListener> listeners
-
uniqueId
protected byte[] uniqueId
-
-
Constructor Detail
-
AbstractGearmanFunction
public AbstractGearmanFunction()
-
AbstractGearmanFunction
public AbstractGearmanFunction(String name)
-
-
Method Detail
-
getName
public String getName()
Description copied from interface:GearmanFunction
Retrieves the name of the funcion to be executed by the job. This is used by aGearmanWorker
to determine if the function has been regisitered with the worker and therefor can be executed by the Worker.- Specified by:
getName
in interfaceGearmanFunction
- Returns:
- the name of the function.
-
setData
public void setData(Object data)
Description copied from interface:GearmanFunction
Some functions require a dataset upon which to operate. This method is used to load that data so that it is available when the function is called.- Specified by:
setData
in interfaceGearmanFunction
- Parameters:
data
- The data used by the function at execution time.
-
setJobHandle
public void setJobHandle(byte[] handle) throws IllegalArgumentException
Description copied from interface:GearmanFunction
Set the handle of the job for which this function is executing.- Specified by:
setJobHandle
in interfaceGearmanFunction
- Parameters:
handle
- the job handle.- Throws:
IllegalArgumentException
- if the handle is null or empty.
-
getJobHandle
public byte[] getJobHandle()
Description copied from interface:GearmanFunction
Retrieves the handle for the job that is executing this function.- Specified by:
getJobHandle
in interfaceGearmanFunction
- Returns:
- The jobhandle or an empty array if the handle is not set.
-
registerEventListener
public void registerEventListener(GearmanIOEventListener listener) throws IllegalArgumentException
Description copied from interface:GearmanFunction
As a function executes, it can generate a series of I/O Events -- in the form of aGearmanPacket
-- that can be handled by a series of listeners. This method registers an instance of a listener with this function. When the function calls theGearmanFunction.fireEvent(org.gearman.common.GearmanPacket)
all registered listeners should be given a chance to handle the event. An exampe of this would be a function that generates intermediate data. As the data is generated, the function can call this method to allow any listeners to act upon that data.- Specified by:
registerEventListener
in interfaceGearmanFunction
- Throws:
IllegalArgumentException
- if the listener is null or deemed to be invalid by the function.
-
fireEvent
public void fireEvent(GearmanPacket event) throws IllegalArgumentException
Description copied from interface:GearmanFunction
Allows allGearmanIOEventListener
registered with this function to handle the specified event.- Specified by:
fireEvent
in interfaceGearmanFunction
- Parameters:
event
- The event to be handled by the listeners.- Throws:
IllegalArgumentException
-
sendData
public void sendData(byte[] data)
-
sendWarning
public void sendWarning(byte[] warning)
-
sendException
public void sendException(byte[] exception)
-
sendStatus
public void sendStatus(int denominator, int numerator)
-
executeFunction
public abstract GearmanJobResult executeFunction()
-
call
public GearmanJobResult call()
- Specified by:
call
in interfaceCallable<GearmanJobResult>
-
setUniqueId
public void setUniqueId(byte[] uuid)
Description copied from interface:GearmanFunction
Set the Unique ID given to this job by the client- Specified by:
setUniqueId
in interfaceGearmanFunction
-
getUniqueId
public byte[] getUniqueId()
Description copied from interface:GearmanFunction
Returns the Unique ID given to this job by the client- Specified by:
getUniqueId
in interfaceGearmanFunction
-
-