public class GridTaskSessionImpl extends Object implements GridTaskSessionInternal
| Constructor and Description |
|---|
GridTaskSessionImpl(UUID taskNodeId,
String taskName,
GridDeployment dep,
String taskClsName,
GridUuid sesId,
Collection<UUID> top,
long startTime,
long endTime,
Collection<GridComputeJobSibling> siblings,
Map<Object,Object> attrs,
GridKernalContext ctx,
boolean fullSup) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
acquire() |
void |
addAttributeListener(GridComputeTaskSessionAttributeListener lsnr,
boolean rewind)
Add listener for the session attributes.
|
void |
addJobSiblings(Collection<GridComputeJobSibling> siblings) |
protected void |
checkFullSupport() |
GridDeployment |
deployment() |
<K,V> V |
getAttribute(K key)
Gets an attribute set by
GridComputeTaskSession.setAttribute(Object, Object) or GridComputeTaskSession.setAttributes(Map)
method. |
Map<Object,Object> |
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.
|
String |
getFailoverSpi() |
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.
|
String |
getLoadBalancingSpi() |
long |
getSequenceNumber() |
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.
|
String |
getUserVersion() |
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. |
protected <T> T |
loadCheckpoint0(GridTaskSessionInternal ses,
String key) |
void |
onClosed()
Closes session.
|
Collection<GridComputeJobSibling> |
refreshJobSiblings()
Refreshes collection of job siblings.
|
boolean |
release() |
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. |
protected boolean |
removeCheckpoint0(GridTaskSessionInternal ses,
String key) |
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.
|
protected void |
saveCheckpoint0(GridTaskSessionInternal ses,
String key,
Object state,
GridComputeTaskSessionScope scope,
long timeout,
boolean overwrite) |
GridTaskSessionInternal |
session() |
void |
setAttribute(Object key,
Object val)
Sets session attributed.
|
void |
setAttributes(Map<?,?> attrs)
Sets task attributes.
|
void |
setCheckpointSpi(String cpSpi) |
void |
setClassLoader(ClassLoader clsLdr) |
void |
setFailoverSpi(String failSpi) |
void |
setInternal(Map<?,?> attrs) |
void |
setJobSiblings(Collection<GridComputeJobSibling> siblings) |
void |
setLoadBalancingSpi(String loadSpi) |
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.
|
boolean |
waitForAttribute(Object key,
Object val)
Waits for the specified attribute to be set or updated with given value.
|
boolean |
waitForAttribute(Object key,
Object 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 GridTaskSessionImpl(UUID taskNodeId, String taskName, @Nullable GridDeployment dep, String taskClsName, GridUuid sesId, @Nullable Collection<UUID> top, long startTime, long endTime, Collection<GridComputeJobSibling> siblings, @Nullable Map<Object,Object> attrs, GridKernalContext ctx, boolean fullSup)
taskNodeId - Task node ID.taskName - Task name.dep - Deployment.taskClsName - Task class name.sesId - Task session ID.top - Topology.startTime - Task execution start time.endTime - Task execution end time.siblings - Collection of siblings.attrs - Session attributes.ctx - Grid Kernal Context.fullSup - Session full support enabled flag.public boolean isFullSupport()
isFullSupport in interface GridTaskSessionInternalTrue if checkpoints and attributes are enabled.protected void checkFullSupport()
public boolean acquire()
True if session was acquired.public boolean release()
True if session cannot be acquired any more.public GridTaskSessionInternal session()
session in interface GridTaskSessionInternal@Nullable public GridUuid getJobId()
getJobId in interface GridTaskSessionInternalpublic void onClosed()
onClosed in interface GridTaskSessionInternalpublic boolean isClosed()
isClosed in interface GridTaskSessionInternalpublic UUID getTaskNodeId()
GridComputeTaskSessiongetTaskNodeId in interface GridComputeTaskSessionpublic long getStartTime()
getStartTime in interface GridComputeTaskSessionpublic <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 boolean waitForAttribute(Object key, Object val) throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionkey - 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 boolean waitForAttribute(Object key, Object val, long timeout) throws InterruptedException
waitForAttribute in interface GridComputeTaskSessionkey - 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.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 String getTaskName()
getTaskName in interface GridComputeTaskSessionpublic String getTaskClassName()
public GridUuid getId()
getId in interface GridComputeTaskSessionpublic long getEndTime()
getEndTime in interface GridComputeTaskSessionpublic String getUserVersion()
public 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 void setClassLoader(ClassLoader clsLdr)
clsLdr - Class loader.public boolean isTaskNode()
isTaskNode in interface GridTaskSessionInternalTrue if task node.public 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 void setJobSiblings(Collection<GridComputeJobSibling> siblings)
siblings - Siblings.public void addJobSiblings(Collection<GridComputeJobSibling> siblings)
siblings - Siblings.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, 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<Object,Object> getAttributes()
getAttributes in interface GridComputeTaskSessionpublic void setInternal(Map<?,?> attrs)
attrs - Attributes to set.public 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 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),
GridCheckpointSpiprotected void saveCheckpoint0(GridTaskSessionInternal ses, String key, Object state, GridComputeTaskSessionScope scope, long timeout, boolean overwrite) throws GridException
ses - Session.key - Key.state - State.scope - Scope.timeout - Timeout.overwrite - Overwrite.GridException - If failed.public <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),
GridCheckpointSpiprotected <T> T loadCheckpoint0(GridTaskSessionInternal ses, String key) throws GridException
ses - Session.key - Key.GridException - If failed.public 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),
GridCheckpointSpiprotected boolean removeCheckpoint0(GridTaskSessionInternal ses, String key) throws GridException
ses - Session.key - Key.True if removed.GridException - If failed.public Collection<UUID> getTopology()
getTopology in interface GridComputeTaskSessionpublic String getCheckpointSpi()
getCheckpointSpi in interface GridTaskSessionInternalpublic void setCheckpointSpi(String cpSpi)
cpSpi - Checkpoint SPI name.public String getFailoverSpi()
public void setFailoverSpi(String failSpi)
failSpi - Failover SPI name.public String getLoadBalancingSpi()
public void setLoadBalancingSpi(String loadSpi)
loadSpi - Load balancing SPI name.public long getSequenceNumber()
public GridDeployment deployment()
Copyright © 2014. All rights reserved.