SMILA 1.0 API documentation

org.eclipse.smila.taskworker.internal
Class TaskContextImpl

java.lang.Object
  extended by org.eclipse.smila.taskworker.internal.TaskContextImpl
All Implemented Interfaces:
TaskContext

public class TaskContextImpl
extends java.lang.Object
implements TaskContext

Implementation of TaskContext.


Constructor Summary
TaskContextImpl(Task task, TaskLog taskLog, ObjectStoreService objectStore)
          create instance.
TaskContextImpl(Task task, TaskLog taskLog, ObjectStoreService objectStore, java.util.Map<java.lang.String,java.util.Collection<OutputMode>> outputModes)
          create instance.
 
Method Summary
 void addDuration(java.lang.String name, double duration)
          On each call, the value is added to the existing duration value for the given name.
 void addDuration(java.lang.String name, long duration)
          On each call, the value is added to the existing duration value for the given name.
 void addToCounter(java.lang.String name, double value)
          On each call, the value is added to the existing counter value for the given name.
 void addToCounter(java.lang.String name, long value)
          On each call, the value is added to the existing counter value for the given name.
 void cancel()
          cancel task execution.
 java.util.Map<java.lang.String,java.lang.Number> getFinalCounters()
           
 Inputs getInputs()
          
 TaskLog getLog()
           
 ObjectStoreService getObjectStore()
          
 Outputs getOutputs()
          
 Task getTask()
          
 AnyMap getTaskParameters()
           
 long getTimestamp()
           
 boolean isCanceled()
          
 void measureTime(java.lang.String name, long startTime)
          measure time that has elapsed since the startTime value and add the duration to the named counter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TaskContextImpl

public TaskContextImpl(Task task,
                       TaskLog taskLog,
                       ObjectStoreService objectStore)
create instance.


TaskContextImpl

public TaskContextImpl(Task task,
                       TaskLog taskLog,
                       ObjectStoreService objectStore,
                       java.util.Map<java.lang.String,java.util.Collection<OutputMode>> outputModes)
create instance.

Method Detail

getTask

public Task getTask()

Specified by:
getTask in interface TaskContext
Returns:
the current task

getTaskParameters

public AnyMap getTaskParameters()
Specified by:
getTaskParameters in interface TaskContext
Returns:
the task parameters.

getInputs

public Inputs getInputs()

Specified by:
getInputs in interface TaskContext
Returns:
Inputs object, for accessing objects of the input slots of the worker.

getOutputs

public Outputs getOutputs()

Specified by:
getOutputs in interface TaskContext
Returns:
Outputs object, for accessing objects of the output slots of the worker.

getFinalCounters

public java.util.Map<java.lang.String,java.lang.Number> getFinalCounters()
Specified by:
getFinalCounters in interface TaskContext
Returns:
calculate and aggregate all counters in this task context and return the complete map. Call this immediately after the worker has finished.

addToCounter

public void addToCounter(java.lang.String name,
                         long value)
Description copied from interface: TaskContext
On each call, the value is added to the existing counter value for the given name. No conversion (e.g. milliseconds to seconds or sth. like that) is done. An example would be counting the numbers of objects in processing. The counters will appear in the final task counters.

Specified by:
addToCounter in interface TaskContext
Parameters:
name - the name of the counter
value - the value to add to the counter

addToCounter

public void addToCounter(java.lang.String name,
                         double value)
Description copied from interface: TaskContext
On each call, the value is added to the existing counter value for the given name. No conversion (e.g. milliseconds to seconds or sth. like that) is done. An example would be counting the object sizes in processing. The counters will appear in the final task counters.

Specified by:
addToCounter in interface TaskContext
Parameters:
name - the name of the counter
value - the value to add to the counter

getTimestamp

public long getTimestamp()
Specified by:
getTimestamp in interface TaskContext
Returns:
a start time value to use in TaskContext.measureTime(String, long) to measure a duration.

measureTime

public void measureTime(java.lang.String name,
                        long startTime)
Description copied from interface: TaskContext
measure time that has elapsed since the startTime value and add the duration to the named counter.

Specified by:
measureTime in interface TaskContext
Parameters:
name - the name of the counter
startTime - the start time

addDuration

public void addDuration(java.lang.String name,
                        long duration)
Description copied from interface: TaskContext
On each call, the value is added to the existing duration value for the given name. Values are assumed to describe the duration in nanoseconds and are converted to a double duration value accordingly. In the final task counters, these durations appear as duration.perform.xxx

Specified by:
addDuration in interface TaskContext
Parameters:
name - the name of the counter
duration - the duration in nanoseconds to add.

addDuration

public void addDuration(java.lang.String name,
                        double duration)
Description copied from interface: TaskContext
On each call, the value is added to the existing duration value for the given name. Values are assumed to describe a duration in seconds and are not changed. In the final task counters, these durations appear as duration.perform.xxx

Specified by:
addDuration in interface TaskContext
Parameters:
name - the name of the counter
duration - the duration in seconds to add.

isCanceled

public boolean isCanceled()

Specified by:
isCanceled in interface TaskContext
Returns:
true if current task is canceled, false otherwise.

cancel

public void cancel()
cancel task execution.

Specified by:
cancel in interface TaskContext

getObjectStore

public ObjectStoreService getObjectStore()

Specified by:
getObjectStore in interface TaskContext
Returns:
the object store service used to access the object store.

getLog

public TaskLog getLog()
Specified by:
getLog in interface TaskContext
Returns:
the task log, used for logging that can be accessed via REST/JSON API.

SMILA 1.0 API documentation