Dashboard > GridGain User Guide > Table Of Contents > Developers Guide > Distributed Grid Task Session
Distributed Grid Task Session
Added by morpheus, last edited by architect on Nov 22, 2008  (view change)
Labels: 
(None)


Description

Distributed task session is created for every task execution. It is defined by GridTaskSession Javadoc interface. Task session is distributed across the parent task and all grid jobs spawned by it, so attributes set on a task or on a job can be viewed on other jobs. Correspondingly attributes set on any of the jobs can also be viewed on a task.

Session has 2 main features: attribute and checkpoint (see Checkpoint SPI for more details) management. Both, attributes and checkpoints, can be used from task itself and from the jobs belonging to this task. Session attributes and checkpoints can be set from any task or job methods. Session attribute and checkpoint consistency is fault tolerant and is preserved whenever a job gets failed over to another node for execution. Whenever task execution ends, all checkpoints saved within session with GridCheckpointScope.SESSION_SCOPE Javadoc scope will be removed from checkpoint storage. Checkpoints saved with GridCheckpointScope.GLOBAL_SCOPE Javadoc will outlive the session and can be viewed by other tasks.

The sequence in which session attributes are set is consistent across the task and all job siblings within it. There will never be a case when one job sees attribute A before attribute B, and another job sees attribute B before A. Attribute order is identical across all session participants. Attribute order is also fault tolerant and is preserved whenever a job gets failed over to another node.

Connected Tasks

Note that apart from setting and getting session attributes, tasks or jobs can choose to wait for a certain attribute to be set using any of the waitForAttribute(...) methods. Tasks and jobs can also receive asynchronous notifications about a certain attribute being set through GridTaskSessionAttributeListener Javadoc listener. Such feature allows grid jobs and tasks remain connected in order to synchronize their execution with each other and opens a solution for a whole new range of problems.

Imagine for example that you need to compress a very large file (let's say terabytes in size). To do that in grid environment you would split such file into multiple sections and assign every section to a remote job for execution. Every job would have to scan its section to look for repetition patterns. Once this scan is done by all jobs in parallel, jobs would need to synchronize their results with their siblings so compression would happen consistently across the whole file. This can be achieved by setting repetition patterns discovered by every job into the session. Once all patterns are synchronized, all jobs can proceed with compressing their designated file sections in parallel, taking into account repetition patterns found by all the jobs in the split. Grid task would then reduce (aggregate) all compressed sections into one compressed file. Without session attribute synchronization step this problem would be much harder to solve.

Session Injection

Session can be injected into a task or a job using IoC (dependency injection). See Resources Injection page for additional details.

Example

To see example on how to use distributed task session refer to HelloWorld Session Example.

Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.2.10 Build:#528 Nov 29, 2006) - Bug/feature request - Contact Administrators