public class GridTaskSessionImpl extends Object implements GridTaskSessionInternal
Constructor and Description |
---|
GridTaskSessionImpl(UUID taskNodeId,
String taskName,
@Nullable GridDeployment dep,
String taskClsName,
IgniteUuid sesId,
@Nullable Collection<UUID> top,
@Nullable IgnitePredicate<ClusterNode> topPred,
long startTime,
long endTime,
Collection<ComputeJobSibling> siblings,
@Nullable Map<Object,Object> attrs,
GridKernalContext ctx,
boolean fullSup,
boolean internal,
@Nullable String execName,
@Nullable Object login)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
acquire() |
void |
addAttributeListener(ComputeTaskSessionAttributeListener lsnr,
boolean rewind)
Add listener for the session attributes.
|
void |
addJobSiblings(Collection<ComputeJobSibling> siblings) |
Map<Object,Object> |
attributesSafeCopy() |
protected void |
checkFullSupport()
Checks that the task supports session attributes and checkpoints
(there is
ComputeTaskSessionFullSupport ). |
GridDeployment |
deployment() |
@Nullable String |
executorName() |
<K,V> V |
getAttribute(K key)
Gets an attribute set by
ComputeTaskSession.setAttribute(Object, Object) or ComputeTaskSession.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() |
IgniteUuid |
getId()
Gets session ID of the task being executed.
|
@Nullable IgniteUuid |
getJobId() |
ComputeJobSibling |
getJobSibling(IgniteUuid jobId)
Gets job sibling for a given ID.
|
Collection<ComputeJobSibling> |
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.
|
@Nullable IgnitePredicate<ClusterNode> |
getTopologyPredicate() |
String |
getUserVersion() |
boolean |
isClosed() |
boolean |
isFullSupport() |
boolean |
isInternal() |
boolean |
isTaskNode() |
void |
jobNodes(Collection<UUID> jobNodes)
Sets nodes on which the jobs of the task will be executed.
|
List<UUID> |
jobNodesSafeCopy() |
<T> T |
loadCheckpoint(String key)
Loads job's state previously saved via
ComputeTaskSession.saveCheckpoint(String, Object, ComputeTaskSessionScope, long)
method from an underlying storage for a given key . |
protected <T> T |
loadCheckpoint0(GridTaskSessionInternal ses,
String key) |
Object |
login() |
IgniteFuture<?> |
mapFuture()
Gets future that will be completed when task "map" step has completed
(which means that
ComputeTask.map(List, Object) method has finished). |
void |
onClosed()
Closes session.
|
void |
onDone()
Finish task callback.
|
void |
onMapped()
Task map callback.
|
Collection<ComputeJobSibling> |
refreshJobSiblings()
Refreshes collection of job siblings.
|
boolean |
release() |
boolean |
removeAttributeListener(ComputeTaskSessionAttributeListener 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,
ComputeTaskSessionScope scope,
long timeout)
Saves intermediate state of a job to a storage.
|
void |
saveCheckpoint(String key,
Object state,
ComputeTaskSessionScope 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,
ComputeTaskSessionScope 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<ComputeJobSibling> siblings) |
void |
setLoadBalancingSpi(String loadSpi) |
String |
toString() |
<K,V> V |
waitForAttribute(K key,
long timeout)
Waits for the specified attribute to be set.
|
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,
long timeout)
Waits for the specified attributes to be set.
|
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 @Nullable GridDeployment dep, String taskClsName, IgniteUuid sesId, @Nullable @Nullable Collection<UUID> top, @Nullable @Nullable IgnitePredicate<ClusterNode> topPred, long startTime, long endTime, Collection<ComputeJobSibling> siblings, @Nullable @Nullable Map<Object,Object> attrs, GridKernalContext ctx, boolean fullSup, boolean internal, @Nullable @Nullable String execName, @Nullable @Nullable Object login)
taskNodeId
- Task node ID.taskName
- Task name.dep
- Deployment.taskClsName
- Task class name.sesId
- Task session ID.top
- Topology.topPred
- Topology predicate.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.internal
- Internal task flag.execName
- Custom executor name.login
- User who created the session, null
if security is not enabled.public boolean isFullSupport()
isFullSupport
in interface GridTaskSessionInternal
True
if checkpoints and attributes are enabled.protected void checkFullSupport()
ComputeTaskSessionFullSupport
).IllegalStateException
- If not supported.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 @Nullable IgniteUuid getJobId()
getJobId
in interface GridTaskSessionInternal
public void onClosed()
onClosed
in interface GridTaskSessionInternal
public boolean isClosed()
isClosed
in interface GridTaskSessionInternal
public UUID getTaskNodeId()
ComputeTaskSession
getTaskNodeId
in interface ComputeTaskSession
public long getStartTime()
getStartTime
in interface ComputeTaskSession
public <K,V> V waitForAttribute(K key, long timeout) throws InterruptedException
waitForAttribute
in interface ComputeTaskSession
K
- 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 ComputeTaskSession
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, long timeout) throws InterruptedException
waitForAttributes
in interface ComputeTaskSession
keys
- 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 ComputeTaskSession
attrs
- 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 ComputeTaskSession
public String getTaskClassName()
public IgniteUuid getId()
getId
in interface ComputeTaskSession
public long getEndTime()
getEndTime
in interface ComputeTaskSession
public 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 ComputeTaskSession
public void setClassLoader(ClassLoader clsLdr)
clsLdr
- Class loader.public boolean isTaskNode()
isTaskNode
in interface GridTaskSessionInternal
True
if task node.public Collection<ComputeJobSibling> refreshJobSiblings()
ComputeTaskContinuousMapper
),
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 ComputeTaskSession
public Collection<ComputeJobSibling> getJobSiblings()
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 ComputeTaskSession
public void setJobSiblings(Collection<ComputeJobSibling> siblings)
siblings
- Siblings.public void addJobSiblings(Collection<ComputeJobSibling> siblings)
siblings
- Siblings.public ComputeJobSibling getJobSibling(IgniteUuid jobId)
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 ComputeTaskSession
jobId
- Job ID to get the sibling for.public void setAttribute(Object key, Object val)
ComputeTaskSessionAttributeListener
callback than an attribute has changed.
This method is no-op if the session has finished.
setAttribute
in interface ComputeTaskSession
key
- Attribute key.val
- Attribute value. Can be null
.public <K,V> V getAttribute(K key)
ComputeTaskSession.setAttribute(Object, Object)
or ComputeTaskSession.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 ComputeTaskSession
K
- Attribute key type.V
- Attribute value type.key
- Attribute key.public void setAttributes(Map<?,?> attrs)
ComputeTaskSession.setAttribute(Object, Object)
method, whenever you need to set multiple attributes.
This method is no-op if the session has finished.
setAttributes
in interface ComputeTaskSession
attrs
- Attributes to set.public Map<Object,Object> getAttributes()
getAttributes
in interface ComputeTaskSession
public void setInternal(Map<?,?> attrs)
attrs
- Attributes to set.public void addAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind)
addAttributeListener
in interface ComputeTaskSession
lsnr
- 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(ComputeTaskSessionAttributeListener lsnr)
removeAttributeListener
in interface ComputeTaskSession
lsnr
- Listener to remove.true
if listener was removed, false
otherwise.public void saveCheckpoint(String key, Object state)
CheckpointSpi
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
ComputeTaskSession.loadCheckpoint(String)
method and continue with execution.
This method defaults checkpoint scope to ComputeTaskSessionScope.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 ComputeTaskSession
key
- Key to be used to load this checkpoint in future.state
- Intermediate job state to save.ComputeTaskSession.loadCheckpoint(String)
,
ComputeTaskSession.removeCheckpoint(String)
,
CheckpointSpi
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout)
CheckpointSpi
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
ComputeTaskSession.loadCheckpoint(String)
method and continue with execution.
The life time of the checkpoint is determined by its timeout and scope.
If ComputeTaskSessionScope.GLOBAL_SCOPE
is used, the checkpoint will outlive
its session, and can only be removed by calling CheckpointSpi.removeCheckpoint(String)
from Ignite
or another task or job.
saveCheckpoint
in interface ComputeTaskSession
key
- Key to be used to load this checkpoint in future.state
- Intermediate job state to save.scope
- Checkpoint scope. If equal to ComputeTaskSessionScope.SESSION_SCOPE
, then
state will automatically be removed at the end of task execution. Otherwise, if scope is
ComputeTaskSessionScope.GLOBAL_SCOPE
then state will outlive its session and can be
removed by calling ComputeTaskSession.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.ComputeTaskSession.loadCheckpoint(String)
,
ComputeTaskSession.removeCheckpoint(String)
,
CheckpointSpi
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite)
CheckpointSpi
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
ComputeTaskSession.loadCheckpoint(String)
method and continue with execution.
The life time of the checkpoint is determined by its timeout and scope.
If ComputeTaskSessionScope.GLOBAL_SCOPE
is used, the checkpoint will outlive
its session, and can only be removed by calling CheckpointSpi.removeCheckpoint(String)
from Ignite
or another task or job.
saveCheckpoint
in interface ComputeTaskSession
key
- Key to be used to load this checkpoint in future.state
- Intermediate job state to save.scope
- Checkpoint scope. If equal to ComputeTaskSessionScope.SESSION_SCOPE
, then
state will automatically be removed at the end of task execution. Otherwise, if scope is
ComputeTaskSessionScope.GLOBAL_SCOPE
then state will outlive its session and can be
removed by calling ComputeTaskSession.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.ComputeTaskSession.loadCheckpoint(String)
,
ComputeTaskSession.removeCheckpoint(String)
,
CheckpointSpi
protected void saveCheckpoint0(GridTaskSessionInternal ses, String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite) throws IgniteException
ses
- Session.key
- Key.state
- State.scope
- Scope.timeout
- Timeout.overwrite
- Overwrite.IgniteException
- If failed.public <T> T loadCheckpoint(String key)
ComputeTaskSession.saveCheckpoint(String, Object, ComputeTaskSessionScope, 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
CheckpointSpi
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 ComputeTaskSession
T
- Type of the checkpoint state.key
- Key for intermediate job state to load.null
if no state was found for a given key
.ComputeTaskSession.removeCheckpoint(String)
,
CheckpointSpi
protected <T> T loadCheckpoint0(GridTaskSessionInternal ses, String key)
ses
- Session.key
- Key.IgniteException
- If failed.public boolean removeCheckpoint(String key)
key
from an underlying storage.
The storage implementation is defined by CheckpointSpi
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 ComputeTaskSession
key
- Key for intermediate job state to load.true
if job state was removed, false
if state was not found.ComputeTaskSession.loadCheckpoint(String)
,
CheckpointSpi
protected boolean removeCheckpoint0(GridTaskSessionInternal ses, String key) throws IgniteException
ses
- Session.key
- Key.True
if removed.IgniteException
- If failed.@Nullable public @Nullable IgnitePredicate<ClusterNode> getTopologyPredicate()
public Collection<UUID> getTopology()
getTopology
in interface ComputeTaskSession
public String getCheckpointSpi()
getCheckpointSpi
in interface GridTaskSessionInternal
public 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()
public void onMapped()
public void onDone()
public IgniteFuture<?> mapFuture()
ComputeTask.map(List, Object)
method has finished).mapFuture
in interface ComputeTaskSession
public boolean isInternal()
True
if task is internal.@Nullable public @Nullable String executorName()
public void jobNodes(Collection<UUID> jobNodes)
jobNodes
- Nodes on which the jobs of the task will be executed.public List<UUID> jobNodesSafeCopy()
public Map<Object,Object> attributesSafeCopy()
public Object login()
null
if security is not enabled.
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.13.0 Release Date : April 20 2022