org.apache.spark
Class TaskContext

Object
  extended by org.apache.spark.TaskContext
All Implemented Interfaces:
java.io.Serializable

public abstract class TaskContext
extends Object
implements java.io.Serializable

Contextual information about a task which can be read or mutated during execution. To access the TaskContext for a running task, use:


   org.apache.spark.TaskContext.get()
 

See Also:
Serialized Form

Constructor Summary
TaskContext()
           
 
Method Summary
abstract  void addOnCompleteCallback(scala.Function0<scala.runtime.BoxedUnit> f)
          Adds a callback function to be executed on task completion.
abstract  TaskContext addTaskCompletionListener(scala.Function1<TaskContext,scala.runtime.BoxedUnit> f)
          Adds a listener in the form of a Scala closure to be executed on task completion.
abstract  TaskContext addTaskCompletionListener(TaskCompletionListener listener)
          Adds a (Java friendly) listener to be executed on task completion.
abstract  long attemptId()
           
abstract  int attemptNumber()
          How many times this task has been attempted.
static TaskContext get()
          Return the currently active TaskContext.
abstract  boolean isCompleted()
          Returns true if the task has completed.
abstract  boolean isInterrupted()
          Returns true if the task has been killed.
abstract  boolean isRunningLocally()
          Returns true if the task is running locally in the driver program.
abstract  int partitionId()
          The ID of the RDD partition that is computed by this task.
abstract  boolean runningLocally()
           
abstract  int stageId()
          The ID of the stage that this task belong to.
abstract  long taskAttemptId()
          An ID that is unique to this task attempt (within the same SparkContext, no two task attempts will share the same attempt ID).
abstract  org.apache.spark.executor.TaskMetrics taskMetrics()
          ::DeveloperApi::
 
Methods inherited from class Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskContext

public TaskContext()
Method Detail

get

public static TaskContext get()
Return the currently active TaskContext. This can be called inside of user functions to access contextual information about running tasks.

Returns:
(undocumented)

isCompleted

public abstract boolean isCompleted()
Returns true if the task has completed.

Returns:
(undocumented)

isInterrupted

public abstract boolean isInterrupted()
Returns true if the task has been killed.

Returns:
(undocumented)

runningLocally

public abstract boolean runningLocally()

isRunningLocally

public abstract boolean isRunningLocally()
Returns true if the task is running locally in the driver program.

Returns:

addTaskCompletionListener

public abstract TaskContext addTaskCompletionListener(TaskCompletionListener listener)
Adds a (Java friendly) listener to be executed on task completion. This will be called in all situation - success, failure, or cancellation. An example use is for HadoopRDD to register a callback to close the input stream.

Parameters:
listener - (undocumented)
Returns:
(undocumented)

addTaskCompletionListener

public abstract TaskContext addTaskCompletionListener(scala.Function1<TaskContext,scala.runtime.BoxedUnit> f)
Adds a listener in the form of a Scala closure to be executed on task completion. This will be called in all situations - success, failure, or cancellation. An example use is for HadoopRDD to register a callback to close the input stream.

Parameters:
f - (undocumented)
Returns:
(undocumented)

addOnCompleteCallback

public abstract void addOnCompleteCallback(scala.Function0<scala.runtime.BoxedUnit> f)
Adds a callback function to be executed on task completion. An example use is for HadoopRDD to register a callback to close the input stream. Will be called in any situation - success, failure, or cancellation.

Parameters:
f - Callback function.

stageId

public abstract int stageId()
The ID of the stage that this task belong to.

Returns:
(undocumented)

partitionId

public abstract int partitionId()
The ID of the RDD partition that is computed by this task.

Returns:
(undocumented)

attemptNumber

public abstract int attemptNumber()
How many times this task has been attempted. The first task attempt will be assigned attemptNumber = 0, and subsequent attempts will have increasing attempt numbers.

Returns:
(undocumented)

attemptId

public abstract long attemptId()

taskAttemptId

public abstract long taskAttemptId()
An ID that is unique to this task attempt (within the same SparkContext, no two task attempts will share the same attempt ID). This is roughly equivalent to Hadoop's TaskAttemptID.

Returns:
(undocumented)

taskMetrics

public abstract org.apache.spark.executor.TaskMetrics taskMetrics()
::DeveloperApi::