Program guide > Access data with client applications > Use Sessions to access data in the grid
SessionHandle for routing
When using a per-container partition placement policy, you can use a SessionHandle. A SessionHandle instance contains partition information for the current Session and can be reused for a new Session.
A SessionHandle includes information for the partition to which the current Session is bound. SessionHandle is extremely useful for the per-container partition placement policy and can be serialized with standard Java™ serialization.
If you have a SessionHandle instance, you can apply that handle to a Session with the setSessionHandle(SessionHandle target) method, passing the handle in as the target. You can retrieve the SessionHandle with the Session.getSessionHandle method.
Because it is only applicable in a per-container placement scenario, getting the SessionHandle throws an IllegalStateException if a given ObjectGrid has multiple per-container mapsets or has none. If you do not invoke the setSessionHandle method before calling the getSessionHandle method, the appropriate SessionHandle will be selected based on the ClientProperties configuration.
You can also use the helper class SessionHandleTransformer to convert the handle into different formats. The methods of this class can change a handle's representation from byte array to instance, string to instance, and vice versa for both cases, and can also write the handle's contents into the output stream.
For an example on how you can use a SessionHandle, see Zone-preferred routing.
Parent topic:Use Sessions to access data in the grid