Class TaskResult

java.lang.Object
com.onenetwork.platform.grid.TaskResult

public class TaskResult
extends java.lang.Object
At the end of task execution, a TaskPerformer returns a TaskResult to indicate whether the task succeeded or failed, if it failed then why, and finally whether a retry should be attempted.

The createSucceed(String) method or SUCCEED member should be used to indicate that the task succeeded.

One of the createRetry(String) methods should be used to indicate that execution failed (and why), and that the task should be retried (as long as the max attempts has not been consumed).

One of the createFail(String) methods should be used to indicate that execution failed (and why), and that no attempt should be made to retry.

  • Field Summary

    Fields 
    Modifier and Type Field Description
    static TaskResult FAIL
    Indicates failed execution without recording a failure reason.
    static TaskResult RETRY
    Indicates failed execution with desired retry, without recording a failure reason.
    static TaskResult SUCCEED
    Indicates successful execution without any need for recorded output
  • Method Summary

    Modifier and Type Method Description
    static TaskResult createFail​(java.lang.String reason)
    Create a fail result (with no retry), with a reason for the failure.
    static TaskResult createFail​(java.lang.String reason, java.lang.Throwable e)
    Create a fail result (with no retry), with a reason and an exception.
    static TaskResult createFail​(java.lang.Throwable e)
    Create a fail result (with no retry), with an exception.
    static TaskResult createRetry​(java.lang.String reason)
    Create a retry result with a reason for the retry.
    static TaskResult createRetry​(java.lang.String reason, java.lang.Throwable e)
    Create a retry result with a reason and an exception.
    static TaskResult createRetry​(java.lang.Throwable e)
    Create a retry result with an exception.
    static TaskResult createSucceed​(java.lang.String output)
    Create a successful result, attaching the specified output which will be written to the database and available as GridTask.getTaskResult().
    java.lang.String getFailReason()
    Return the fail reason.
    java.lang.String getTaskOutput()
    Returns the task output.
    boolean isFail()
    Returns true iff result is FAIL
    boolean isRetry()
    Returns true iff result is RETRY
    boolean isSucceed()
    Returns true iff result is SUCCEED
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
  • Field Details

  • Method Details

    • createSucceed

      public static TaskResult createSucceed​(java.lang.String output)
      Create a successful result, attaching the specified output which will be written to the database and available as GridTask.getTaskResult().
      Parameters:
      output - successful output
      Returns:
      a succeed result with output attached
    • createFail

      public static TaskResult createFail​(java.lang.String reason)
      Create a fail result (with no retry), with a reason for the failure.
      Parameters:
      reason - why the task failed
      Returns:
      a fail task result with the specified reason
    • createFail

      public static TaskResult createFail​(java.lang.String reason, java.lang.Throwable e)
      Create a fail result (with no retry), with a reason and an exception.
      Parameters:
      reason - The reason for the failure
      e - the exception that caused the failure
      Returns:
      a fail task result with the reason and stack trace
    • createFail

      public static TaskResult createFail​(java.lang.Throwable e)
      Create a fail result (with no retry), with an exception.
      Parameters:
      e - the exception that caused the failure
      Returns:
      a fail task result with the stack trace as the reason
    • createRetry

      public static TaskResult createRetry​(java.lang.String reason)
      Create a retry result with a reason for the retry.
      Parameters:
      reason - why the task needs to be retried
      Returns:
      a retry task result with the specified reason
    • createRetry

      public static TaskResult createRetry​(java.lang.String reason, java.lang.Throwable e)
      Create a retry result with a reason and an exception.
      Parameters:
      reason - The reason for the need to retry
      e - the exception that caused the need to retry
      Returns:
      a retry task result with the reason and stack trace
    • createRetry

      public static TaskResult createRetry​(java.lang.Throwable e)
      Create a retry result with an exception.
      Parameters:
      e - the exception that caused the need to retry
      Returns:
      a retry task result with the stack trace as the reason
    • isSucceed

      public boolean isSucceed()
      Returns true iff result is SUCCEED
      Returns:
      true iff result is SUCCEED
    • isFail

      public boolean isFail()
      Returns true iff result is FAIL
      Returns:
      true iff result is FAIL
    • isRetry

      public boolean isRetry()
      Returns true iff result is RETRY
      Returns:
      true iff result is RETRY
    • getFailReason

      public java.lang.String getFailReason()
      Return the fail reason. If this result is not a failure, the fail reason will always be null.
      Returns:
      the fail reason
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • getTaskOutput

      public java.lang.String getTaskOutput()
      Returns the task output. If this result is not a success, the task output will always be null.
      Returns:
      task output