====== The Concepts : Session Handling ====== The session handling logic is encapsulated in the SessionHandler module extension which is added to the ActionFlow::Base class eval at the plugin initialization. The session handler has the following responsibilities. * Expose the state variable, which is a hash that saves data which is relevant to the current flow state. * Generate state snapshots in the session hash. * Persist and restore each state data and make sure the state variable contains the data corresponding to the correct restored state using its unique [[Flow Execution Key|key]]. ===== Example usage of the state variable ===== To store values relevant to the current flow state, simply interact with the state attribute. def some_step_definition state[ :key ] = :lets_put_something_in end See the [[state]] page for more details. ===== Session data structure ===== Each flow's session data is structured in the user's session hash as follows. ----> User session hash | -----> flow data | | | -----> state data | | | -----> state data | | | -----> state data | | | -----> timestamp | -----> flow data | -----> state data | -----> state data | -----> state data | -----> timestamp Therefore, each time a new [[flow]] is launched (which means no [[flow execution key]] was supplied), a new flow session data placeholder is created. We call it a [[state]]. After that, once the user submits a [[flow execution key]], the correct [[state]] is fetched and written from the correct session state placeholder. Here's an example of the session data structure with correct values. The unique keys used here are not representative of a real world situation, since the numbers are random. ----> User session hash | -----> flow_data-00000001 | | | -----> 00000(...)001 | | | | | ----> last_step_name | | | -----> 00000(...)002 | | | | | ----> last_step_name | | | -----> 00000(...)003 | | | | | ----> last_step_name | | | -----> timestamp => 20070101 12:01:01.001 | -----> flow_data-00000002 | -----> 00000(...)001 | | | ----> last_step_name | -----> 00000(...)002 | | | ----> last_step_name | -----> 00000(...)003 | | | ----> last_step_name | -----> timestamp => 20070101 13:01:01.001 Be careful when using the session hash instead of the [[state]] hash. Concurrency problems between flows may occur. Be sure you know what you're doing. ~~DISCUSSION~~