Package org.gearman.worker
Interface GearmanFunction
-
- All Superinterfaces:
Callable<GearmanJobResult>
- All Known Implementing Classes:
AbstractGearmanFunction
,DigestFunction
,ReverseFunction
public interface GearmanFunction extends Callable<GearmanJobResult>
A Gearman Function represents the work to be accomplished by aGearmanJob
. It defines how the job is executed and the data, if any, against which that execution will occurr.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description 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
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
-
-
-
Method Detail
-
getName
String getName()
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.- Returns:
- the name of the function.
-
setData
void setData(Object data)
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.- Parameters:
data
- The data used by the function at execution time.
-
setJobHandle
void setJobHandle(byte[] handle) throws IllegalArgumentException
Set the handle of the job for which this function is executing.- Parameters:
handle
- the job handle.- Throws:
IllegalArgumentException
- if the handle is null or empty.
-
getJobHandle
byte[] getJobHandle()
Retrieves the handle for the job that is executing this function.- Returns:
- The jobhandle or an empty array if the handle is not set.
-
registerEventListener
void registerEventListener(GearmanIOEventListener listener) throws IllegalArgumentException
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 thefireEvent(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.- Parameters:
listener
-- Throws:
IllegalArgumentException
- if the listener is null or deemed to be invalid by the function.
-
fireEvent
void fireEvent(GearmanPacket event)
Allows allGearmanIOEventListener
registered with this function to handle the specified event.- Parameters:
event
- The event to be handled by the listeners.
-
setUniqueId
void setUniqueId(byte[] uuid)
Set the Unique ID given to this job by the client
-
getUniqueId
byte[] getUniqueId()
Returns the Unique ID given to this job by the client
-
-