org.infinispan.marshall
Interface Externalizer<T>

All Superinterfaces:
Serializable
All Known Subinterfaces:
AdvancedExternalizer<T>
All Known Implementing Classes:
AbstractExternalizer, AbstractWheelConsistentHash.Externalizer, ArrayListExternalizer, AtomicHashMap.Externalizer, AtomicHashMapDelta.Externalizer, Bucket.Externalizer, ByteArrayKey.Externalizer, CacheRpcCommandExternalizer, CacheView.Externalizer, ChunkCacheKey.Externalizer, ClearOperation.Externalizer, DefaultConsistentHash.Externalizer, DldGlobalTransaction.Externalizer, ExceptionResponse.Externalizer, ExperimentalDefaultConsistentHash.Externalizer, FileCacheKey.Externalizer, FileListCacheKey.Externalizer, FileMetadata.Externalizer, FileReadLockKey.Externalizer, Flag.Externalizer, Fqn.Externalizer, GlobalTransaction.AbstractGlobalTxExternalizer, GlobalTransaction.Externalizer, ImmortalCacheEntry.Externalizer, ImmortalCacheValue.Externalizer, Immutables.ImmutableMapWrapperExternalizer, InDoubtTxInfoImpl.Externalizer, JGroupsAddress.Externalizer, JGroupsTopologyAwareAddress.Externalizer, LinkedListExternalizer, LockInfo.Externalizer, MapExternalizer, MarshalledValue.Externalizer, MortalCacheEntry.Externalizer, MortalCacheValue.Externalizer, MurmurHash2.Externalizer, MurmurHash2Compat.Externalizer, MurmurHash3.Externalizer, NodeKey.Externalizer, NoStateExternalizer, PutOperation.Externalizer, RecoveryAwareDldGlobalTransaction.Externalizer, RecoveryAwareGlobalTransaction.Externalizer, RemoteTransactionLogDetails.Externalizer, RemoveOperation.Externalizer, ReplicableCommandExternalizer, SerializableXid.XidExternalizer, SetExternalizer, SingletonListExternalizer, SuccessfulResponse.Externalizer, TopologyAwareConsistentHash.Externalizer, TransientCacheEntry.Externalizer, TransientCacheValue.Externalizer, TransientMortalCacheEntry.Externalizer, TransientMortalCacheValue.Externalizer, UnionConsistentHash.Externalizer, UnsuccessfulResponse.Externalizer, UnsureResponse.Externalizer, VersionedImmortalCacheEntry.Externalizer, VersionedImmortalCacheValue.Externalizer, VersionedMortalCacheEntry.Externalizer, VersionedMortalCacheValue.Externalizer, VersionedTransientCacheEntry.Externalizer, VersionedTransientCacheValue.Externalizer, VersionedTransientMortalCacheEntry.Externalizer, VersionedTransientMortalCacheValue.Externalizer

public interface Externalizer<T>
extends Serializable

One of the key aspects of Infinispan is that it often needs to marshall or 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 storing as binary, 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. In the simplest possible form, users just need to provide an Externalizer implementation for the type that they want to marshall/unmarshall, and then annotate the marshalled type class with SerializeWith indicating the externalizer class to use and that's all about it. At runtime JBoss Marshaller will inspect the object and discover that's marshallable thanks to the annotation and so marshall it using the externalizer class passed. 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. Even though this way of defining externalizers is very user friendly, it has some disadvantages:

If you're affected by any of these disadvantages, an alternative mechanism to provide externalizers is available via AdvancedExternalizer. More details can be found in this interface's javadoc.

Since:
5.0
Author:
Galder ZamarreƱo

Method Summary
 T readObject(ObjectInput input)
          Read an instance from the stream.
 void writeObject(ObjectOutput output, T object)
          Write the object reference to the stream.
 

Method Detail

writeObject

void writeObject(ObjectOutput output,
                 T object)
                 throws IOException
Write the object reference to the stream.

Parameters:
output - the object output to write to
object - 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 © 2012 JBoss, a division of Red Hat. All Rights Reserved.