public class HazelcastSessionSerializer extends java.lang.Object implements 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
com.hazelcast.config.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);
Constructor and Description |
---|
HazelcastSessionSerializer() |
Modifier and Type | Method and Description |
---|---|
void |
destroy() |
int |
getTypeId() |
MapSession |
read(com.hazelcast.nio.ObjectDataInput in) |
void |
write(com.hazelcast.nio.ObjectDataOutput out,
MapSession session) |
public void write(com.hazelcast.nio.ObjectDataOutput out, MapSession session) throws java.io.IOException
write
in interface com.hazelcast.nio.serialization.StreamSerializer<MapSession>
java.io.IOException
public MapSession read(com.hazelcast.nio.ObjectDataInput in) throws java.io.IOException
read
in interface com.hazelcast.nio.serialization.StreamSerializer<MapSession>
java.io.IOException
public int getTypeId()
getTypeId
in interface com.hazelcast.nio.serialization.Serializer
public void destroy()
destroy
in interface com.hazelcast.nio.serialization.Serializer