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 Details

    • getResult

      T getResult()
      Get the result of the task execution.
      Returns:
      the task result.
    • setResult

      Task<T> setResult(T result)
      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 Throwable instance, or null if no exception was raised.
      Since:
      4.0
    • setThrowable

      Task<T> setThrowable(Throwable throwable)
      Sets the Throwable that was raised by this task's execution in the run() method. The Throwable is normally set by the JPPF framework.
      Parameters:
      throwable - a Throwable instance.
      Returns:
      this task, for method chaining.
      Since:
      4.0
    • getDataProvider

      DataProvider getDataProvider()
      Get the provider of shared data for this task.
      Returns:
      a DataProvider instance.
    • setDataProvider

      Task<T> setDataProvider(DataProvider dataProvider)
      Set the provider of shared data for this task.
      Parameters:
      dataProvider - a DataProvider instance.
      Returns:
      this task, for method chaining.
    • getId

      String getId()
      Get the user-assigned id for this task.
      Returns:
      the id as a string.
    • setId

      Task<T> setId(String id)
      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 the JPPFRunnable-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 JPPFSchedule instance.
    • setTimeoutSchedule

      Task<T> setTimeoutSchedule(JPPFSchedule timeoutSchedule)
      Get the task timeout schedule configuration.
      Parameters:
      timeoutSchedule - a JPPFSchedule instance.
      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:
      true if this task is executing in a node, false if it is on the client side.
    • setInNode

      Task<T> setInNode(boolean inNode)
      Determine whether this task is executing within a node, or locally on the client side.
      Parameters:
      inNode - true if this task is executing in a node, false if it is on the client side.
      Returns:
      this task, for method chaining.
    • compute

      <V> V compute(JPPFCallable<V> callable) throws Exception
      Compute a value on the client-side, as the result of the execution of a JPPFCallable.

      Any Throwable raised in the callable's call() method will be thrown as the result of this method. If the Throwable is an instance of Exception or one of its subclasses, it is thrown as such, otherwise it is wrapped into a JPPFException.

      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 a Throwable being raised.
    • fireNotification

      Task<T> fireNotification(Object userObject, boolean sendViaJmx)
      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 the Runnable.run(), onTimeout() or onCancel() methods.

      If the parameter sendViaJmx is true, then a notfication will also be sent by the JPPFNodeTaskMonitorMBean mbean, otherwise only local listeners will be notified.

      Parameters:
      userObject - a user-defined object to send as part of the notification.
      sendViaJmx - if true then 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:
      true to indicate this task will be resubmitted, false otherwise.
      Since:
      4.2
    • setResubmit

      Task<T> setResubmit(boolean resubmit)
      Specify whether this task should be resubmitted by the server.
      Parameters:
      resubmit - true to indicate this task will be resubmitted, false otherwise.
      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

      Task<T> setMaxResubmits(int maxResubmits)
      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 by JobSLA.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 ClassLoader instance.
      Since:
      5.0
    • getNode

      Node getNode()
      Get the node this task is executing in, if any.
      Returns:
      A Node instance, or null if this task is not running in a node, e.g. in a client local executor.
      Since:
      6.0
    • setNode

      Task<T> setNode(Node node)
      Set the node in which this task is executing, if any.
      Parameters:
      node - the JPPF node instance.
      Returns:
      this task, for method chaining.
    • getJob

      Get the job this task is a part of.
      Returns:
      the job as an instance of JPPFDistributedJob.
    • setJob

      Task<T> setJob(JPPFDistributedJob job)
      set the job this task is a part of.
      Parameters:
      job - the job as an instance of JPPFDistributedJob.
      Returns:
      this task, for method call chaining.