public class GridJobSessionImpl extends Object implements GridTaskSessionInternal
| Constructor and Description |
|---|
GridJobSessionImpl(GridKernalContext ctx,
GridTaskSessionImpl ses,
GridUuid jobId) |
| Modifier and Type | Method and Description |
|---|---|
void |
addAttributeListener(GridComputeTaskSessionAttributeListener lsnr,
boolean rewind)
Add listener for the session attributes.
|
<K,V> V |
getAttribute(K key)
Gets an attribute set by
GridComputeTaskSession.setAttribute(Object, Object) or GridComputeTaskSession.setAttributes(Map)
method. |
Map<?,?> |
getAttributes()
Gets all attributes.
|
String |
getCheckpointSpi() |
ClassLoader |
getClassLoader()
Gets class loader responsible for loading all classes within task.
|
long |
getEndTime()
Gets end of computation time for the task.
|
GridUuid |
getId()
Gets session ID of the task being executed.
|
GridUuid |
getJobId() |
GridComputeJobSibling |
getJobSibling(GridUuid jobId)
Gets job sibling for a given ID.
|
Collection<GridComputeJobSibling> |
getJobSiblings()
Gets a collection of all grid job siblings.
|
long |
getStartTime()
Gets start of computation time for the task.
|
String |
getTaskClassName()
Returns task class name.
|
String |
getTaskName()
Gets task name of the task this session belongs to.
|
UUID |
getTaskNodeId()
Gets ID of the node on which task execution originated.
|
Collection<UUID> |
getTopology()
Gets a collection of grid nodes IDs.
|
boolean |
isClosed() |
boolean |
isFullSupport() |
boolean |
isTaskNode() |
<T> T |
loadCheckpoint(String key)
Loads job's state previously saved via
GridComputeTaskSession.saveCheckpoint(String, Object, GridComputeTaskSessionScope, long)
method from an underlying storage for a given key. |
void |
onClosed()
Closes session.
|
Collection<GridComputeJobSibling> |
refreshJobSiblings()
Refreshes collection of job siblings.
|
boolean |
removeAttributeListener(GridComputeTaskSessionAttributeListener lsnr)
Removes given listener.
|
boolean |
removeCheckpoint(String key)
Removes previously saved job's state for a given
key from an underlying storage. |
void |
saveCheckpoint(String key,
Object state)
Saves intermediate state of a job or task to a storage.
|
void |
saveCheckpoint(String key,
Object state,
GridComputeTaskSessionScope scope,
long timeout)
Saves intermediate state of a job to a storage.
|
void |
saveCheckpoint(String key,
Object state,
GridComputeTaskSessionScope scope,
long timeout,
boolean overwrite)
Saves intermediate state of a job or task to a storage.
|
GridTaskSessionInternal |
session() |
void |
setAttribute(Object key,
Object val)
Sets session attributed.
|
void |
setAttributes(Map<?,?> attrs)
Sets task attributes.
|
String |
toString() |
<K,V> V |
waitForAttribute(K key)
Waits for the specified attribute to be set.
|
<K,V> V |
waitForAttribute(K key,
long timeout)
Waits for the specified attribute to be set.
|
<K,V> boolean |
waitForAttribute(K key,
V val)
Waits for the specified attribute to be set or updated with given value.
|
<K,V> boolean |
waitForAttribute(K key,
V val,
long timeout)
Waits for the specified attribute to be set or updated with given value.
|
Map<?,?> |
waitForAttributes(Collection<?> keys)
Waits for the specified attributes to be set.
|
Map<?,?> |
waitForAttributes(Collection<?> keys,
long timeout)
Waits for the specified attributes to be set.
|
boolean |
waitForAttributes(Map<?,?> attrs)
Waits for the specified attributes to be set or updated with given values.
|
boolean |
waitForAttributes(Map<?,?> attrs,
long timeout)
Waits for the specified attributes to be set or updated with given values.
|
public GridJobSessionImpl(GridKernalContext ctx, GridTaskSessionImpl ses, GridUuid jobId)
ctx - Kernal context.ses - Task session.jobId - Job ID.public GridTaskSessionInternal session()
session in interface GridTaskSessionInternalpublic GridUuid getJobId()
getJobId in interface GridTaskSessionInternalpublic void onClosed()
onClosed in interface GridTaskSessionInternalpublic boolean isClosed()
isClosed in interface GridTaskSessionInternalpublic boolean isTaskNode()
isTaskNode in interface GridTaskSessionInternalTrue if task node.public String getCheckpointSpi()
getCheckpointSpi in interface GridTaskSessionInternalpublic String getTaskName()
getTaskName in interface GridComputeTaskSessionpublic String getTaskClassName()
public UUID getTaskNodeId()
getTaskNodeId in interface GridComputeTaskSessionpublic long getStartTime()
getStartTime in interface GridComputeTaskSessionpublic long getEndTime()
getEndTime in interface GridComputeTaskSessionpublic GridUuid getId()
getId in interface GridComputeTaskSessionpublic ClassLoader getClassLoader()
Note that for classes that were loaded remotely from other nodes methods
Class.getResource(String) or ClassLoader.getResource(String)
will always return null. Use
Class.getResourceAsStream(String) or ClassLoader.getResourceAsStream(String)
instead.
getClassLoader in interface GridComputeTaskSessionpublic Collection<GridComputeJobSibling> refreshJobSiblings() throws GridException
GridComputeTaskContinuousMapper),
list of siblings on remote node may not be fresh. In that case, this method
will re-request list of siblings from originating node.refreshJobSiblings in interface GridComputeTaskSessionGridException - If refresh failed.public Collection<GridComputeJobSibling> getJobSiblings() throws GridException
If task uses continuous mapper (i.e. it injected into task class) then job siblings will be requested from task node for each apply.
getJobSiblings in interface GridComputeTaskSessionGridException - If job siblings can not be received from task node.public GridComputeJobSibling getJobSibling(GridUuid jobId) throws GridException
If task uses continuous mapper (i.e. it injected into task class) then job sibling will be requested from task node for each apply.
getJobSibling in interface GridComputeTaskSessionjobId - Job ID to get the sibling for.GridException - If job sibling can not be received from task node.public void setAttribute(Object key, @Nullable Object val) throws GridException
GridComputeTaskSessionAttributeListener
callback than an attribute has changed.
This method is no-op if the session has finished.
setAttribute in interface GridComputeTaskSessionkey - Attribute key.val - Attribute value. Can be null.GridException - If sending of attribute message failed.public <K,V> V getAttribute(K key)
GridComputeTaskSession.setAttribute(Object, Object) or GridComputeTaskSession.setAttributes(Map)
method. Note that this attribute could have been set by another job on
another node.
This method is no-op if the session has finished.
getAttribute in interface GridComputeTaskSessionK - Attribute key type.V - Attribute value type.key - Attribute key.public void setAttributes(Map<?,?> attrs) throws GridException
GridComputeTaskSession.setAttribute(Object, Object)
method, whenever you need to set multiple attributes.
This method is no-op if the session has finished.
setAttributes in interface GridComputeTaskSessionattrs - Attributes to set.GridException - If sending of attribute message failed.public Map<?,?> getAttributes()
getAttributes in interface GridComputeTaskSessionpublic void addAttributeListener(GridComputeTaskSessionAttributeListener lsnr, boolean rewind)
addAttributeListener in interface GridComputeTaskSessionlsnr - Listener to add.rewind - true value will result in calling given listener for all
already received attributes, while false value will result only
in new attribute notification. Settings rewind to true
allows for a simple mechanism that prevents the loss of notifications for
the attributes that were previously received or received while this method
was executing.public boolean removeAttributeListener(GridComputeTaskSessionAttributeListener lsnr)
removeAttributeListener in interface GridComputeTaskSessionlsnr - Listener to remove.true if listener was removed, false otherwise.public <K,V> V waitForAttribute(K key)
throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionK - Attribute key type.V - Attribute value type.key - Attribute key to wait for.InterruptedException - Thrown if wait was interrupted.public <K,V> boolean waitForAttribute(K key,
@Nullable
V val)
throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionK - Attribute key type.V - Attribute value type.key - Attribute key to wait for.val - Attribute value to wait for. Can be null.InterruptedException - Thrown if wait was interrupted.public <K,V> V waitForAttribute(K key,
long timeout)
throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionK - Attribute key type.V - Attribute value type.key - Attribute key to wait for.timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.InterruptedException - Thrown if wait was interrupted.public <K,V> boolean waitForAttribute(K key,
@Nullable
V val,
long timeout)
throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionK - Attribute key type.V - Attribute value type.key - Attribute key to wait for.val - Attribute value to wait for. Can be null.timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.InterruptedException - Thrown if wait was interrupted.public Map<?,?> waitForAttributes(Collection<?> keys) throws InterruptedException
waitForAttributes in interface GridComputeTaskSessionkeys - Attribute keys to wait for.InterruptedException - Thrown if wait was interrupted.public boolean waitForAttributes(Map<?,?> attrs) throws InterruptedException
waitForAttributes in interface GridComputeTaskSessionattrs - Key/value pairs to wait for.InterruptedException - Thrown if wait was interrupted.public Map<?,?> waitForAttributes(Collection<?> keys, long timeout) throws InterruptedException
waitForAttributes in interface GridComputeTaskSessionkeys - Attribute keys to wait for.timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.InterruptedException - Thrown if wait was interrupted.public boolean waitForAttributes(Map<?,?> attrs, long timeout) throws InterruptedException
waitForAttributes in interface GridComputeTaskSessionattrs - Key/value pairs to wait for.timeout - Timeout in milliseconds to wait for. 0 means indefinite wait.InterruptedException - Thrown if wait was interrupted.public void saveCheckpoint(String key, Object state) throws GridException
GridCheckpointSpi implementation used.
Long running jobs may decide to store intermediate state to protect themselves from failures.
This way whenever a job fails over to another node, it can load its previously saved state via
GridComputeTaskSession.loadCheckpoint(String) method and continue with execution.
This method defaults checkpoint scope to GridComputeTaskSessionScope.SESSION_SCOPE and
implementation will automatically remove the checkpoint at the end of the session. It is
analogous to calling saveCheckpoint(String, Serializable, GridCheckpointScope.SESSION_SCOPE, 0.
saveCheckpoint in interface GridComputeTaskSessionkey - Key to be used to load this checkpoint in future.state - Intermediate job state to save.GridException - If failed to save intermediate job state.GridComputeTaskSession.loadCheckpoint(String),
GridComputeTaskSession.removeCheckpoint(String),
GridCheckpointSpipublic void saveCheckpoint(String key, Object state, GridComputeTaskSessionScope scope, long timeout) throws GridException
GridCheckpointSpi implementation used.
Long running jobs may decide to store intermediate state to protect themselves from failures.
This way whenever a job fails over to another node, it can load its previously saved state via
GridComputeTaskSession.loadCheckpoint(String) method and continue with execution.
The life time of the checkpoint is determined by its timeout and scope.
If GridComputeTaskSessionScope.GLOBAL_SCOPE is used, the checkpoint will outlive
its session, and can only be removed by calling GridCheckpointSpi.removeCheckpoint(String)
from Grid or another task or job.
saveCheckpoint in interface GridComputeTaskSessionkey - Key to be used to load this checkpoint in future.state - Intermediate job state to save.scope - Checkpoint scope. If equal to GridComputeTaskSessionScope.SESSION_SCOPE, then
state will automatically be removed at the end of task execution. Otherwise, if scope is
GridComputeTaskSessionScope.GLOBAL_SCOPE then state will outlive its session and can be
removed by calling GridComputeTaskSession.removeCheckpoint(String) from another task or whenever
timeout expires.timeout - Maximum time this state should be kept by the underlying storage. Value 0 means that
timeout will never expire.GridException - If failed to save intermediate job state.GridComputeTaskSession.loadCheckpoint(String),
GridComputeTaskSession.removeCheckpoint(String),
GridCheckpointSpipublic void saveCheckpoint(String key, Object state, GridComputeTaskSessionScope scope, long timeout, boolean overwrite) throws GridException
GridCheckpointSpi implementation used.
Long running jobs may decide to store intermediate state to protect themselves from failures.
This way whenever a job fails over to another node, it can load its previously saved state via
GridComputeTaskSession.loadCheckpoint(String) method and continue with execution.
The life time of the checkpoint is determined by its timeout and scope.
If GridComputeTaskSessionScope.GLOBAL_SCOPE is used, the checkpoint will outlive
its session, and can only be removed by calling GridCheckpointSpi.removeCheckpoint(String)
from Grid or another task or job.
saveCheckpoint in interface GridComputeTaskSessionkey - Key to be used to load this checkpoint in future.state - Intermediate job state to save.scope - Checkpoint scope. If equal to GridComputeTaskSessionScope.SESSION_SCOPE, then
state will automatically be removed at the end of task execution. Otherwise, if scope is
GridComputeTaskSessionScope.GLOBAL_SCOPE then state will outlive its session and can be
removed by calling GridComputeTaskSession.removeCheckpoint(String) from another task or whenever
timeout expires.timeout - Maximum time this state should be kept by the underlying storage. Value 0 means that
timeout will never expire.overwrite - Whether or not overwrite checkpoint if it already exists.GridException - If failed to save intermediate job state.GridComputeTaskSession.loadCheckpoint(String),
GridComputeTaskSession.removeCheckpoint(String),
GridCheckpointSpipublic <T> T loadCheckpoint(String key) throws GridException
GridComputeTaskSession.saveCheckpoint(String, Object, GridComputeTaskSessionScope, long)
method from an underlying storage for a given key. If state was not previously
saved, then null will be returned. The storage implementation is defined by
GridCheckpointSpi implementation used.
Long running jobs may decide to store intermediate state to protect themselves from failures. This way whenever a job starts, it can load its previously saved state and continue with execution.
loadCheckpoint in interface GridComputeTaskSessionT - Type of the checkpoint state.key - Key for intermediate job state to load.null if no state was found for a given key.GridException - If failed to load job state.GridComputeTaskSession.removeCheckpoint(String),
GridCheckpointSpipublic boolean removeCheckpoint(String key) throws GridException
key from an underlying storage.
The storage implementation is defined by GridCheckpointSpi implementation used.
Long running jobs may decide to store intermediate state to protect themselves from failures. This way whenever a job starts, it can load its previously saved state and continue with execution.
removeCheckpoint in interface GridComputeTaskSessionkey - Key for intermediate job state to load.true if job state was removed, false if state was not found.GridException - If failed to remove job state.GridComputeTaskSession.loadCheckpoint(String),
GridCheckpointSpipublic Collection<UUID> getTopology()
getTopology in interface GridComputeTaskSessionpublic boolean isFullSupport()
isFullSupport in interface GridTaskSessionInternalTrue if checkpoints and attributes are enabled.Copyright © 2014. All rights reserved.