Package org.jppf.client.taskwrapper
Class JPPFAnnotatedTask
- All Implemented Interfaces:
Serializable,Runnable,CancellationHandler,Interruptibility,PositionalElement<Task<Object>>,Task<Object>
JPPF task wrapper for an object whose class is annotated with
JPPFRunnable.- Author:
- Laurent Cohen
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected JPPFTaskCallback<Object>A delegate for theonCancel()method.protected TaskObjectWrapperWrapper around a task that is not an instance ofTask.protected JPPFTaskCallback<Object>A delegate for theonTimeout()method. -
Constructor Summary
ConstructorsConstructorDescriptionJPPFAnnotatedTask(Object taskObject, Object... args) Initialize this task with an object whose class is either annotated withJPPFRunnable, an instance ofRunnableor an instance ofCallable.JPPFAnnotatedTask(Object taskObject, String method, Object... args) Initialize this task from a POJO, given a method and its arguments to execute it. -
Method Summary
Modifier and TypeMethodDescriptionvoidInvoked immediately when a task is cancelled.Get theJPPFRunnable-annotated object or POJO wrapped by this task.booleanDetermine whether the thread executing the task can be interrupted.voidonCancel()Callback invoked when this task is cancelled.voidCallback invoked when this task times out.voidrun()Run theJPPFRunnable-annotated method of the task object.setCancelCallback(JPPFTaskCallback<Object> cancelCallback) Set the delegate for theonCancel()method.setDataProvider(DataProvider dataProvider) Override ofTask.setDataProvider(DataProvider)to enable setting the data provider onto tasks that are not subclasses ofTaskand which implementDataProviderHolder.setTimeoutCallback(JPPFTaskCallback<Object> timeoutCallback) Set the delegate for theonTimeout()method.Methods inherited from class org.jppf.node.protocol.AbstractTask
compute, fireNotification, getDataProvider, getId, getJob, getMaxResubmits, getNode, getPosition, getResult, getTaskClassLoader, getThrowable, getTimeoutSchedule, isInNode, isResubmit, setExecutionDispatcher, setId, setInNode, setJob, setMaxResubmits, setNode, setPosition, setResubmit, setResult, setThrowable, setTimeoutSchedule
-
Field Details
-
taskObjectWrapper
Wrapper around a task that is not an instance ofTask. -
cancelCallback
A delegate for theonCancel()method. -
timeoutCallback
A delegate for theonTimeout()method.
-
-
Constructor Details
-
JPPFAnnotatedTask
Initialize this task with an object whose class is either annotated withJPPFRunnable, an instance ofRunnableor an instance ofCallable.- Parameters:
taskObject- an object that encapsulates the task to execute.args- the optional arguments for a class that has one of its methods annotated withJPPFRunnable.- Throws:
JPPFException- if an error is raised while initializing this task.
-
JPPFAnnotatedTask
Initialize this task from a POJO, given a method and its arguments to execute it.- Parameters:
taskObject- either an instance of the POJO class if the method is non-static, or a class object if the method is static.method- the name of the method to execute.args- the arguments for the method to execute.- Throws:
JPPFException- if an error is raised while initializing this task.
-
-
Method Details
-
run
public void run()Run theJPPFRunnable-annotated method of the task object.- Specified by:
runin interfaceRunnable- Overrides:
runin classAbstractTask<Object>
-
getTaskObject
Get theJPPFRunnable-annotated object or POJO wrapped by this task.- Specified by:
getTaskObjectin interfaceTask<Object>- Overrides:
getTaskObjectin classAbstractTask<Object>- Returns:
- an object or class that is JPPF-annotated.
-
setCancelCallback
Set the delegate for theonCancel()method.- Parameters:
cancelCallback- aJPPFTaskCallbackinstance.- Returns:
- this task, for method chaining.
-
setTimeoutCallback
Set the delegate for theonTimeout()method.- Parameters:
timeoutCallback- aJPPFTaskCallbackinstance.- Returns:
- this task, for method chaining.
-
onCancel
public void onCancel()Description copied from interface:TaskCallback invoked when this task is cancelled. The default implementation does nothing and should be overriden by subclasses that desire to implement a specific behaviour on cancellation. -
onTimeout
public void onTimeout()Description copied from interface:TaskCallback invoked when this task times out. The default implementation does nothing and should be overriden by subclasses that desire to implement a specific behaviour on timeout. -
setDataProvider
Override ofTask.setDataProvider(DataProvider)to enable setting the data provider onto tasks that are not subclasses ofTaskand which implementDataProviderHolder.- Specified by:
setDataProviderin interfaceTask<Object>- Overrides:
setDataProviderin classAbstractTask<Object>- Parameters:
dataProvider- the data provider to set onto the task.- Returns:
- this task, for method chaining.
-
isInterruptible
public boolean isInterruptible()Description copied from interface:InterruptibilityDetermine whether the thread executing the task can be interrupted.- Specified by:
isInterruptiblein interfaceInterruptibility- Overrides:
isInterruptiblein classAbstractTask<Object>- Returns:
trueif the task can be interrupted,falseotherwise.
-
doCancelAction
Description copied from interface:CancellationHandlerInvoked immediately when a task is cancelled.- Specified by:
doCancelActionin interfaceCancellationHandler- Throws:
Exception- if any error occurs while this callback is executing.
-