org.infinispan.marshall
Interface Externalizer<T>
- All Known Implementing Classes:
- ArrayListExternalizer, AtomicHashMap.Externalizer, AtomicHashMapDelta.Externalizer, Bucket.Externalizer, ByteArrayKey.Externalizer, ClearOperation.Externalizer, DefaultConsistentHash.Externalizer, DldGlobalTransaction.Externalizer, ExceptionResponse.Externalizer, ExperimentalDefaultConsistentHash.Externalizer, ExtendedResponse.Externalizer, Fqn.Externalizer, GlobalTransaction.Externalizer, ImmortalCacheEntry.Externalizer, ImmortalCacheValue.Externalizer, Immutables.ImmutableMapWrapperExternalizer, JGroupsAddress.Externalizer, LinkedListExternalizer, MapExternalizer, MarshalledValue.Externalizer, MortalCacheEntry.Externalizer, MortalCacheValue.Externalizer, NodeKey.Externalizer, NodeTopologyInfo.Externalizer, PutOperation.Externalizer, RemoveOperation.Externalizer, ReplicableCommandExternalizer, RequestIgnoredResponse.Externalizer, SetExternalizer, SingletonListExternalizer, SuccessfulResponse.Externalizer, TopologyAwareConsistentHash.Externalizer, TransactionLog.LogEntry.Externalizer, TransientCacheEntry.Externalizer, TransientCacheValue.Externalizer, TransientMortalCacheEntry.Externalizer, TransientMortalCacheValue.Externalizer, UnionConsistentHash.Externalizer, UnsuccessfulResponse.Externalizer, UnsureResponse.Externalizer
public interface Externalizer<T>
One of the key aspects of Infinispan is that it often needs to marshall/unmarshall
objects in order to provide some of its functionality. For example, if it needs
to store objects in a write-through or write-behind cache store, the objects stored
need marshalling. If a cluster of Infinispan nodes is formed, objects shipped around
need marshalling. Even if you enable lazy deserialization, objects need to marshalled
so that they can be lazily unmarshalled with the correct classloader.
Using standard JDK serialization is slow and produces payloads that are too big and
can affect bandwidth usage. On top of that, JDK serialization does not work well with
objects that are supposed to be immutable. In order to avoid these issues, Infinispan
uses JBoss Marshalling for marshalling/unmarshalling objects. JBoss Marshalling is fast
, provides very space efficient payloads, and on top of that, allows users to construct
objects themselves during unmarshalling, hence allowing objects to carry on being immutable.
Starting with 5.0, users of Infinispan can now benefit from this marshalling
framework as well, and they can provide their own implementations of the Externalizer
interface in order to define, how a particular object type needs to be marshalled or
unmarshalled.
It's common practice to include Externalizer implementations within the classes that
they marshall/unmarshall as public static classes. To make Externalizer implementations
easier to code and more typesafe, make sure you define type as the type of object
that's being marshalled/unmarshalled. You can find plenty of examples of Externalizer
implementations in the Infinispan code base, but to highlight one, check the Externalizer
implementation for JGroupsAddress
in
JGroupsAddress.Externalizer
Once the Externalizer implementations have been built, make sure you annotate each
Externalizer implementation with the Marshalls
annotation so that the link between
the type of classes externalized and the Externalizer itself can be established. Please
see the annotation javadoc for more details on this.
- Since:
- 4.0
- Author:
- Galder ZamarreƱo
writeObject
void writeObject(ObjectOutput output,
T object)
throws IOException
- Write the object reference to the stream.
- Parameters:
output
- the object output to write toobject
- the object reference to write
- Throws:
IOException
- if an I/O error occurs
readObject
T readObject(ObjectInput input)
throws IOException,
ClassNotFoundException
- Read an instance from the stream. The instance will have been written by the
writeObject(ObjectOutput, Object)
method. Implementations are free
to create instances of the object read from the stream in any way that they
feel like. This could be via constructor, factory or reflection.
- Parameters:
input
- the object input to read from
- Returns:
- the object instance
- Throws:
IOException
- if an I/O error occurs
ClassNotFoundException
- if a class could not be found
Copyright © 2010 JBoss, a division of Red Hat. All Rights Reserved.