Class GridJobSessionImpl
- java.lang.Object
-
- org.apache.ignite.internal.GridJobSessionImpl
-
- All Implemented Interfaces:
ComputeTaskSession,GridTaskSessionInternal
public class GridJobSessionImpl extends Object implements GridTaskSessionInternal
Job session implementation.
-
-
Constructor Summary
Constructors Constructor Description GridJobSessionImpl(GridKernalContext ctx, GridTaskSessionImpl ses, IgniteUuid jobId)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind)Add listener for the session attributes.GridDeploymentdeployment()Grid job deployment.<K,V>
VgetAttribute(K key)Gets an attribute set byComputeTaskSession.setAttribute(Object, Object)orComputeTaskSession.setAttributes(Map)method.Map<?,?>getAttributes()Gets all attributes.StringgetCheckpointSpi()ClassLoadergetClassLoader()Gets class loader responsible for loading all classes within task.longgetEndTime()Gets end of computation time for the task.IgniteUuidgetId()Gets session ID of the task being executed.IgniteUuidgetJobId()ComputeJobSiblinggetJobSibling(IgniteUuid jobId)Gets job sibling for a given ID.Collection<ComputeJobSibling>getJobSiblings()Gets a collection of all grid job siblings.longgetStartTime()Gets start of computation time for the task.StringgetTaskClassName()Returns task class name.StringgetTaskName()Gets task name of the task this session belongs to.UUIDgetTaskNodeId()Gets ID of the node on which task execution originated.Collection<UUID>getTopology()Gets a collection of grid nodes IDs.booleanisClosed()booleanisFullSupport()booleanisTaskNode()<T> TloadCheckpoint(String key)Loads job's state previously saved viaComputeTaskSession.saveCheckpoint(String, Object, ComputeTaskSessionScope, long)method from an underlying storage for a givenkey.IgniteFuture<?>mapFuture()Gets future that will be completed when task "map" step has completed (which means thatComputeTask.map(List, Object)method has finished).voidonClosed()Closes session.Collection<ComputeJobSibling>refreshJobSiblings()Refreshes collection of job siblings.booleanremoveAttributeListener(ComputeTaskSessionAttributeListener lsnr)Removes given listener.booleanremoveCheckpoint(String key)Removes previously saved job's state for a givenkeyfrom an underlying storage.voidsaveCheckpoint(String key, Object state)Saves intermediate state of a job or task to a storage.voidsaveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout)Saves intermediate state of a job to a storage.voidsaveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite)Saves intermediate state of a job or task to a storage.GridTaskSessionInternalsession()voidsetAttribute(Object key, @Nullable Object val)Sets session attributed.voidsetAttributes(Map<?,?> attrs)Sets task attributes.StringtoString()<K,V>
VwaitForAttribute(K key, long timeout)Waits for the specified attribute to be set.<K,V>
booleanwaitForAttribute(K key, V 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.booleanwaitForAttributes(Map<?,?> attrs, long timeout)Waits for the specified attributes to be set or updated with given values.
-
-
-
Constructor Detail
-
GridJobSessionImpl
public GridJobSessionImpl(GridKernalContext ctx, GridTaskSessionImpl ses, IgniteUuid jobId)
- Parameters:
ctx- Kernal context.ses- Task session.jobId- Job ID.
-
-
Method Detail
-
deployment
public GridDeployment deployment()
Grid job deployment.- Returns:
- Grid deployment.
-
session
public GridTaskSessionInternal session()
- Specified by:
sessionin interfaceGridTaskSessionInternal- Returns:
- Task session.
-
getJobId
public IgniteUuid getJobId()
- Specified by:
getJobIdin interfaceGridTaskSessionInternal- Returns:
- Job ID (possibly null).
-
onClosed
public void onClosed()
Closes session.- Specified by:
onClosedin interfaceGridTaskSessionInternal
-
isClosed
public boolean isClosed()
- Specified by:
isClosedin interfaceGridTaskSessionInternal- Returns:
- Checks if session is closed.
-
isTaskNode
public boolean isTaskNode()
- Specified by:
isTaskNodein interfaceGridTaskSessionInternal- Returns:
Trueif task node.
-
getCheckpointSpi
public String getCheckpointSpi()
- Specified by:
getCheckpointSpiin interfaceGridTaskSessionInternal- Returns:
- Checkpoint SPI name.
-
getTaskName
public String getTaskName()
Gets task name of the task this session belongs to.- Specified by:
getTaskNamein interfaceComputeTaskSession- Returns:
- Task name of the task this session belongs to.
-
getTaskClassName
public String getTaskClassName()
Returns task class name.- Returns:
- Task class name.
-
getTaskNodeId
public UUID getTaskNodeId()
Gets ID of the node on which task execution originated.- Specified by:
getTaskNodeIdin interfaceComputeTaskSession- Returns:
- ID of the node on which task execution originated.
-
getStartTime
public long getStartTime()
Gets start of computation time for the task.- Specified by:
getStartTimein interfaceComputeTaskSession- Returns:
- Start of computation time for the task.
-
getEndTime
public long getEndTime()
Gets end of computation time for the task. No job within the task will be allowed to execute passed this time.- Specified by:
getEndTimein interfaceComputeTaskSession- Returns:
- End of computation time for the task.
-
getId
public IgniteUuid getId()
Gets session ID of the task being executed.- Specified by:
getIdin interfaceComputeTaskSession- Returns:
- Session ID of the task being executed.
-
getClassLoader
public ClassLoader getClassLoader()
Gets class loader responsible for loading all classes within task.Note that for classes that were loaded remotely from other nodes methods
Class.getResource(String)orClassLoader.getResource(String)will always returnnull. UseClass.getResourceAsStream(String)orClassLoader.getResourceAsStream(String)instead.- Specified by:
getClassLoaderin interfaceComputeTaskSession- Returns:
- Class loader responsible for loading all classes within task.
-
refreshJobSiblings
public Collection<ComputeJobSibling> refreshJobSiblings()
Refreshes collection of job siblings. This method has no effect when invoked on originating node, as the list of siblings is always most recent. However, when using continuous mapping (seeComputeTaskContinuousMapper), list of siblings on remote node may not be fresh. In that case, this method will re-request list of siblings from originating node.- Specified by:
refreshJobSiblingsin interfaceComputeTaskSession- Returns:
- Refreshed collection of job siblings.
-
getJobSiblings
public Collection<ComputeJobSibling> getJobSiblings()
Gets a collection of all grid job siblings. Job siblings are grid jobs that are executing within the same task.If task uses continuous mapper (i.e. it injected into task class) then job siblings will be requested from task node for each apply.
- Specified by:
getJobSiblingsin interfaceComputeTaskSession- Returns:
- Collection of grid job siblings executing within this task.
-
getJobSibling
public ComputeJobSibling getJobSibling(IgniteUuid jobId)
Gets job sibling for a given ID.If task uses continuous mapper (i.e. it injected into task class) then job sibling will be requested from task node for each apply.
- Specified by:
getJobSiblingin interfaceComputeTaskSession- Parameters:
jobId- Job ID to get the sibling for.- Returns:
- Grid job sibling for a given ID.
-
setAttribute
public void setAttribute(Object key, @Nullable @Nullable Object val)
Sets session attributed. Note that task session is distributed and this attribute will be propagated to all other jobs within this task and task itself - i.e., to all accessors of this session. Other jobs then will be notified byComputeTaskSessionAttributeListenercallback than an attribute has changed.This method is no-op if the session has finished.
- Specified by:
setAttributein interfaceComputeTaskSession- Parameters:
key- Attribute key.val- Attribute value. Can benull.
-
getAttribute
public <K,V> V getAttribute(K key)
Gets an attribute set byComputeTaskSession.setAttribute(Object, Object)orComputeTaskSession.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.
- Specified by:
getAttributein interfaceComputeTaskSession- Type Parameters:
K- Attribute key type.V- Attribute value type.- Parameters:
key- Attribute key.- Returns:
- Gets task attribute for given name.
-
setAttributes
public void setAttributes(Map<?,?> attrs)
Sets task attributes. This method exists so one distributed replication operation will take place for the whole group of attributes passed in. Use it for performance reasons, rather thanComputeTaskSession.setAttribute(Object, Object)method, whenever you need to set multiple attributes.This method is no-op if the session has finished.
- Specified by:
setAttributesin interfaceComputeTaskSession- Parameters:
attrs- Attributes to set.
-
getAttributes
public Map<?,?> getAttributes()
Gets all attributes.- Specified by:
getAttributesin interfaceComputeTaskSession- Returns:
- All session attributes.
-
addAttributeListener
public void addAttributeListener(ComputeTaskSessionAttributeListener lsnr, boolean rewind)
Add listener for the session attributes.- Specified by:
addAttributeListenerin interfaceComputeTaskSession- Parameters:
lsnr- Listener to add.rewind-truevalue will result in calling given listener for all already received attributes, whilefalsevalue will result only in new attribute notification. Settingsrewindtotrueallows for a simple mechanism that prevents the loss of notifications for the attributes that were previously received or received while this method was executing.
-
removeAttributeListener
public boolean removeAttributeListener(ComputeTaskSessionAttributeListener lsnr)
Removes given listener.- Specified by:
removeAttributeListenerin interfaceComputeTaskSession- Parameters:
lsnr- Listener to remove.- Returns:
trueif listener was removed,falseotherwise.
-
waitForAttribute
public <K,V> V waitForAttribute(K key, long timeout) throws InterruptedExceptionWaits for the specified attribute to be set. If this attribute is already in session this method will return immediately.- Specified by:
waitForAttributein interfaceComputeTaskSession- Type Parameters:
K- Attribute key type.V- Attribute value type.- Parameters:
key- Attribute key to wait for.timeout- Timeout in milliseconds to wait for.0means indefinite wait.- Returns:
- Value of newly set attribute.
- Throws:
InterruptedException- Thrown if wait was interrupted.
-
waitForAttribute
public <K,V> boolean waitForAttribute(K key, @Nullable V val, long timeout) throws InterruptedExceptionWaits for the specified attribute to be set or updated with given value. Note that this method will block even if attribute is set for as long as its value is not equal to the specified.- Specified by:
waitForAttributein interfaceComputeTaskSession- Type Parameters:
K- Attribute key type.V- Attribute value type.- Parameters:
key- Attribute key to wait for.val- Attribute value to wait for. Can benull.timeout- Timeout in milliseconds to wait for.0means indefinite wait.- Returns:
- Whether or not specified key/value pair has been set.
- Throws:
InterruptedException- Thrown if wait was interrupted.
-
waitForAttributes
public Map<?,?> waitForAttributes(Collection<?> keys, long timeout) throws InterruptedException
Waits for the specified attributes to be set. If these attributes are already in session this method will return immediately.- Specified by:
waitForAttributesin interfaceComputeTaskSession- Parameters:
keys- Attribute keys to wait for.timeout- Timeout in milliseconds to wait for.0means indefinite wait.- Returns:
- Attribute values mapped by their keys.
- Throws:
InterruptedException- Thrown if wait was interrupted.
-
waitForAttributes
public boolean waitForAttributes(Map<?,?> attrs, long timeout) throws InterruptedException
Waits for the specified attributes to be set or updated with given values. Note that this method will block even if attributes are set for as long as their values are not equal to the specified.- Specified by:
waitForAttributesin interfaceComputeTaskSession- Parameters:
attrs- Key/value pairs to wait for.timeout- Timeout in milliseconds to wait for.0means indefinite wait.- Returns:
- Whether or not key/value pair has been set.
- Throws:
InterruptedException- Thrown if wait was interrupted.
-
saveCheckpoint
public void saveCheckpoint(String key, Object state)
Saves intermediate state of a job or task to a storage. The storage implementation is defined byCheckpointSpiimplementation 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_SCOPEand implementation will automatically remove the checkpoint at the end of the session. It is analogous to callingsaveCheckpoint(String, Serializable, GridCheckpointScope.SESSION_SCOPE, 0.- Specified by:
saveCheckpointin interfaceComputeTaskSession- Parameters:
key- Key to be used to load this checkpoint in future.state- Intermediate job state to save.- See Also:
ComputeTaskSession.loadCheckpoint(String),ComputeTaskSession.removeCheckpoint(String),CheckpointSpi
-
saveCheckpoint
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout)
Saves intermediate state of a job to a storage. The storage implementation is defined byCheckpointSpiimplementation 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_SCOPEis used, the checkpoint will outlive its session, and can only be removed by callingCheckpointSpi.removeCheckpoint(String)fromIgniteor another task or job.- Specified by:
saveCheckpointin interfaceComputeTaskSession- Parameters:
key- Key to be used to load this checkpoint in future.state- Intermediate job state to save.scope- Checkpoint scope. If equal toComputeTaskSessionScope.SESSION_SCOPE, then state will automatically be removed at the end of task execution. Otherwise, if scope isComputeTaskSessionScope.GLOBAL_SCOPEthen state will outlive its session and can be removed by callingComputeTaskSession.removeCheckpoint(String)from another task or whenever timeout expires.timeout- Maximum time this state should be kept by the underlying storage. Value0means that timeout will never expire.- See Also:
ComputeTaskSession.loadCheckpoint(String),ComputeTaskSession.removeCheckpoint(String),CheckpointSpi
-
saveCheckpoint
public void saveCheckpoint(String key, Object state, ComputeTaskSessionScope scope, long timeout, boolean overwrite)
Saves intermediate state of a job or task to a storage. The storage implementation is defined byCheckpointSpiimplementation 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_SCOPEis used, the checkpoint will outlive its session, and can only be removed by callingCheckpointSpi.removeCheckpoint(String)fromIgniteor another task or job.- Specified by:
saveCheckpointin interfaceComputeTaskSession- Parameters:
key- Key to be used to load this checkpoint in future.state- Intermediate job state to save.scope- Checkpoint scope. If equal toComputeTaskSessionScope.SESSION_SCOPE, then state will automatically be removed at the end of task execution. Otherwise, if scope isComputeTaskSessionScope.GLOBAL_SCOPEthen state will outlive its session and can be removed by callingComputeTaskSession.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.- See Also:
ComputeTaskSession.loadCheckpoint(String),ComputeTaskSession.removeCheckpoint(String),CheckpointSpi
-
loadCheckpoint
public <T> T loadCheckpoint(String key)
Loads job's state previously saved viaComputeTaskSession.saveCheckpoint(String, Object, ComputeTaskSessionScope, long)method from an underlying storage for a givenkey. If state was not previously saved, thennullwill be returned. The storage implementation is defined byCheckpointSpiimplementation 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.
- Specified by:
loadCheckpointin interfaceComputeTaskSession- Type Parameters:
T- Type of the checkpoint state.- Parameters:
key- Key for intermediate job state to load.- Returns:
- Previously saved state or
nullif no state was found for a givenkey. - See Also:
ComputeTaskSession.removeCheckpoint(String),CheckpointSpi
-
removeCheckpoint
public boolean removeCheckpoint(String key)
Removes previously saved job's state for a givenkeyfrom an underlying storage. The storage implementation is defined byCheckpointSpiimplementation 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.
- Specified by:
removeCheckpointin interfaceComputeTaskSession- Parameters:
key- Key for intermediate job state to load.- Returns:
trueif job state was removed,falseif state was not found.- See Also:
ComputeTaskSession.loadCheckpoint(String),CheckpointSpi
-
getTopology
public Collection<UUID> getTopology()
Gets a collection of grid nodes IDs.- Specified by:
getTopologyin interfaceComputeTaskSession- Returns:
- Collection of grid nodes IDs for the task's split.
-
isFullSupport
public boolean isFullSupport()
- Specified by:
isFullSupportin interfaceGridTaskSessionInternal- Returns:
Trueif checkpoints and attributes are enabled.
-
mapFuture
public IgniteFuture<?> mapFuture()
Gets future that will be completed when task "map" step has completed (which means thatComputeTask.map(List, Object)method has finished).- Specified by:
mapFuturein interfaceComputeTaskSession- Returns:
- Future that will be completed when task "map" step has completed.
-
-