Package org.jppf.node.protocol
Interface Task<T>
- Type Parameters:
T- the type of results produced by the task.
- All Superinterfaces:
Interruptibility,PositionalElement<Task<T>>,Runnable,Serializable
- All Known Subinterfaces:
TaskNode<T>
- All Known Implementing Classes:
AbstractTask,AbstractTaskNode,CommandLineTask,CrossoverTask,FitnessTask,JPPFAnnotatedTask,JPPFExceptionResult,JPPFExceptionResultEx,JPPFTask,ScriptedTask
public interface Task<T>
extends Runnable, Serializable, Interruptibility, PositionalElement<Task<T>>
Interface for all tasks submitted to the execution server.
- Author:
- Laurent Cohen
-
Method Summary
Modifier and TypeMethodDescription<V> Vcompute(JPPFCallable<V> callable) Compute a value on the client-side, as the result of the execution of aJPPFCallable.fireNotification(Object userObject, boolean sendViaJmx) Causes the task to send a notification to all listeners.Get the provider of shared data for this task.getId()Get the user-assigned id for this task.getJob()Get the job this task is a part of.intGet the maximum number of times a task can resubmit itself.getNode()Get the node this task is executing in, if any.Get the result of the task execution.Get the class loader used to load this task, or the object it wraps if any.Get theJPPFRunnable-annotated object or POJO wrapped by this task.Get the Throwable that was raised by this task's execution.Get the task timeout schedule configuration.booleanisInNode()Determine whether this task is executing within a node, or locally on the client side.booleanDetermine whether this task should be resubmitted by the server.voidonCancel()Callback invoked when this task is cancelled.voidCallback invoked when this task times out.setDataProvider(DataProvider dataProvider) Set the provider of shared data for this task.Set the user-assigned id for this task.setInNode(boolean inNode) Determine whether this task is executing within a node, or locally on the client side.setJob(JPPFDistributedJob job) set the job this task is a part of.setMaxResubmits(int maxResubmits) Set the maximum number of times a task can resubmit itself.Set the node in which this task is executing, if any.setResubmit(boolean resubmit) Specify whether this task should be resubmitted by the server.Set the result of the task execution.setThrowable(Throwable throwable) Sets the Throwable that was raised by this task's execution in therun()method.setTimeoutSchedule(JPPFSchedule timeoutSchedule) Get the task timeout schedule configuration.Methods inherited from interface org.jppf.node.protocol.Interruptibility
isInterruptibleMethods inherited from interface org.jppf.node.protocol.PositionalElement
getPosition, setPosition
-
Method Details
-
getResult
T getResult()Get the result of the task execution.- Returns:
- the task result.
-
setResult
Set the result of the task execution.- Parameters:
result- the result of this task's execution.- Returns:
- this task, for method chaining.
-
getThrowable
Throwable getThrowable()Get the Throwable that was raised by this task's execution.- Returns:
- a
Throwableinstance, ornullif no exception was raised. - Since:
- 4.0
-
setThrowable
Sets the Throwable that was raised by this task's execution in therun()method. The Throwable is normally set by the JPPF framework.- Parameters:
throwable- aThrowableinstance.- Returns:
- this task, for method chaining.
- Since:
- 4.0
-
getDataProvider
DataProvider getDataProvider()Get the provider of shared data for this task.- Returns:
- a
DataProviderinstance.
-
setDataProvider
Set the provider of shared data for this task.- Parameters:
dataProvider- aDataProviderinstance.- Returns:
- this task, for method chaining.
-
getId
String getId()Get the user-assigned id for this task.- Returns:
- the id as a string.
-
setId
Set the user-assigned id for this task.- Parameters:
id- the id as a string.- Returns:
- this task, for method chaining.
-
onCancel
void onCancel()Callback 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
void onTimeout()Callback 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. -
getTaskObject
Object getTaskObject()Get theJPPFRunnable-annotated object or POJO wrapped by this task.- Returns:
- an object or class that is JPPF-annotated.
-
getTimeoutSchedule
JPPFSchedule getTimeoutSchedule()Get the task timeout schedule configuration.- Returns:
- a
JPPFScheduleinstance.
-
setTimeoutSchedule
Get the task timeout schedule configuration.- Parameters:
timeoutSchedule- aJPPFScheduleinstance.- Returns:
- this task, for method chaining.
-
isInNode
boolean isInNode()Determine whether this task is executing within a node, or locally on the client side.- Returns:
trueif this task is executing in a node,falseif it is on the client side.
-
setInNode
Determine whether this task is executing within a node, or locally on the client side.- Parameters:
inNode-trueif this task is executing in a node,falseif it is on the client side.- Returns:
- this task, for method chaining.
-
compute
Compute a value on the client-side, as the result of the execution of aJPPFCallable.Any
Throwableraised in the callable'scall()method will be thrown as the result of this method. If the Throwable is an instance ofExceptionor one of its subclasses, it is thrown as such, otherwise it is wrapped into aJPPFException.- Type Parameters:
V- the type of results returned by the callable.- Parameters:
callable- the callable to execute on the client side.- Returns:
- the value computed on the client, or null if the value could not be computed.
- Throws:
Exception- if the execution of the callable in the client resulted in aThrowablebeing raised.
-
fireNotification
Causes the task to send a notification to all listeners. This method can be called at any time during the execution of the task, i.e. while in the execution scope of theRunnable.run(),onTimeout()oronCancel()methods.If the parameter
sendViaJmxistrue, then a notfication will also be sent by theJPPFNodeTaskMonitorMBeanmbean, otherwise only local listeners will be notified.- Parameters:
userObject- a user-defined object to send as part of the notification.sendViaJmx- iftruethen also send the notification via the JMX MBean, otherwise only send to local listeners. If the task is executing within a client local executor, this parameter has no effect.- Returns:
- this task, for method chaining.
- Since:
- 4.0
-
isResubmit
boolean isResubmit()Determine whether this task should be resubmitted by the server.- Returns:
trueto indicate this task will be resubmitted,falseotherwise.- Since:
- 4.2
-
setResubmit
Specify whether this task should be resubmitted by the server.- Parameters:
resubmit-trueto indicate this task will be resubmitted,falseotherwise.- Returns:
- this task, for method chaining.
- Since:
- 4.2
-
getMaxResubmits
int getMaxResubmits()Get the maximum number of times a task can resubmit itself.- Returns:
- a positive integer, or -1 if this attribute was never set, in which case the value set in the job SLA will be used.
-
setMaxResubmits
Set the maximum number of times a task can resubmit itself. If the specified value is greater than or equal to zero, it will override the job-wide value provided byJobSLA.getMaxTaskResubmits().- Parameters:
maxResubmits- the maximum number of resubmits.- Returns:
- this task, for method chaining.
-
getTaskClassLoader
ClassLoader getTaskClassLoader()Get the class loader used to load this task, or the object it wraps if any.- Returns:
- a
ClassLoaderinstance. - Since:
- 5.0
-
getNode
Node getNode()Get the node this task is executing in, if any.- Returns:
- A
Nodeinstance, ornullif this task is not running in a node, e.g. in a client local executor. - Since:
- 6.0
-
setNode
Set the node in which this task is executing, if any.- Parameters:
node- the JPPF node instance.- Returns:
- this task, for method chaining.
-
getJob
JPPFDistributedJob getJob()Get the job this task is a part of.- Returns:
- the job as an instance of
JPPFDistributedJob.
-
setJob
set the job this task is a part of.- Parameters:
job- the job as an instance ofJPPFDistributedJob.- Returns:
- this task, for method call chaining.
-