Class HazelcastSessionSerializer
- All Implemented Interfaces:
com.hazelcast.nio.serialization.Serializer
,com.hazelcast.nio.serialization.StreamSerializer<MapSession>
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); config.getSerializationConfig().addSerializerConfig(serializerConfig); 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); clientConfig.getSerializationConfig().addSerializerConfig(serializerConfig); HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient(clientConfig);
- Since:
- 2.4.0
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
int
read
(com.hazelcast.nio.ObjectDataInput in) void
write
(com.hazelcast.nio.ObjectDataOutput out, MapSession session)
-
Constructor Details
-
HazelcastSessionSerializer
public HazelcastSessionSerializer()
-
-
Method Details
-
write
- Specified by:
write
in interfacecom.hazelcast.nio.serialization.StreamSerializer<MapSession>
- Throws:
IOException
-
read
- Specified by:
read
in interfacecom.hazelcast.nio.serialization.StreamSerializer<MapSession>
- Throws:
IOException
-
getTypeId
public int getTypeId()- Specified by:
getTypeId
in interfacecom.hazelcast.nio.serialization.Serializer
-
destroy
public void destroy()- Specified by:
destroy
in interfacecom.hazelcast.nio.serialization.Serializer
-