Class HazelcastSessionSerializer

All Implemented Interfaces:
com.hazelcast.nio.serialization.Serializer, com.hazelcast.nio.serialization.StreamSerializer<MapSession>

public class HazelcastSessionSerializer extends Object implements com.hazelcast.nio.serialization.StreamSerializer<MapSession>
A Serializer implementation that handles the (de)serialization of MapSession stored on IMap.

The use of this serializer is optional and provides faster serialization of sessions. If not configured to be used, Hazelcast will serialize sessions via Serializable by default.

If multiple instances of a Spring application is run, then all of them need to use the same serialization method. If this serializer is registered on one instance and not another one, then it will end up with HazelcastSerializationException. The same applies when clients are configured to use this serializer but not the members, and vice versa. Also note that, if a new instance is created with this serialization but the existing Hazelcast cluster contains the values not serialized by this but instead the default one, this will result in incompatibility again.

An example of how to register the serializer on embedded instance can be seen below:

 Config config = new Config();

 // ... other configurations for Hazelcast ...

 SerializerConfig serializerConfig = new SerializerConfig();
 serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);

 HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
Below is the example of how to register the serializer on client instance. Note that, to use the serializer in client/server mode, the serializer - and hence MapSession, must exist on the server's classpath and must be registered via SerializerConfig with the configuration above for each server.
 ClientConfig clientConfig = new ClientConfig();

 // ... other configurations for Hazelcast Client ...

 SerializerConfig serializerConfig = new SerializerConfig();
 serializerConfig.setImplementation(new HazelcastSessionSerializer()).setTypeClass(MapSession.class);

 HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient(clientConfig);
  • Constructor Details

    • HazelcastSessionSerializer

      public HazelcastSessionSerializer()
  • Method Details

    • write

      public void write(com.hazelcast.nio.ObjectDataOutput out, MapSession session) throws IOException
      Specified by:
      write in interface com.hazelcast.nio.serialization.StreamSerializer<MapSession>
    • read

      public MapSession read(com.hazelcast.nio.ObjectDataInput in) throws IOException
      Specified by:
      read in interface com.hazelcast.nio.serialization.StreamSerializer<MapSession>
    • getTypeId

      public int getTypeId()
      Specified by:
      getTypeId in interface com.hazelcast.nio.serialization.Serializer
    • destroy

      public void destroy()
      Specified by:
      destroy in interface com.hazelcast.nio.serialization.Serializer