org.infinispan.marshall
Class MarshalledValue

java.lang.Object
  extended by org.infinispan.marshall.MarshalledValue

public class MarshalledValue
extends Object

Wrapper that wraps cached data, providing lazy deserialization using the calling thread's context class loader.

The MarshalledValueInterceptor handles transparent wrapping/unwrapping of cached data.

NOTE: the equals() method of this class will either compare binary representations (byte arrays) or delegate to the wrapped instance's equals() method, depending on whether both instances being compared are in serialized or deserialized form. If one of the instances being compared is in one form and the other in another form, then one instance is either serialized or deserialized, the preference will be to compare object representations, unless the instance is compact(boolean, boolean)ed and a preference is set accordingly.

Note also that this will affect the way keys stored in the cache will work, if storeAsBinary is used, since comparisons happen on the key which will be wrapped by a MarshalledValue. Implementers of equals() methods of their keys need to be aware of this.

Since:
4.0
Author:
Manik Surtani (manik@jboss.org), Mircea.Markus@jboss.com, Galder ZamarreƱo, Sanne Grinovero
See Also:
MarshalledValueInterceptor

Nested Class Summary
static class MarshalledValue.Externalizer
           
 
Field Summary
protected  Object instance
           
protected  byte[] raw
           
protected  int serialisedSize
           
 
Constructor Summary
MarshalledValue(Object instance, boolean equalityPreferenceForInstance, StreamingMarshaller marshaller)
           
 
Method Summary
 void compact(boolean preferSerializedRepresentation, boolean force)
          Compacts the references held by this class to a single reference.
 Object deserialize()
           
 boolean equals(Object o)
           
 Object get()
          Returns the 'cached' instance
 byte[] getRaw()
           
 int hashCode()
           
static boolean isTypeExcluded(Class type)
          Tests whether the type should be excluded from MarshalledValue wrapping.
 byte[] serialize()
           
 MarshalledValue setEqualityPreferenceForInstance(boolean equalityPreferenceForInstance)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

instance

protected volatile Object instance

raw

protected volatile byte[] raw

serialisedSize

protected volatile int serialisedSize
Constructor Detail

MarshalledValue

public MarshalledValue(Object instance,
                       boolean equalityPreferenceForInstance,
                       StreamingMarshaller marshaller)
Method Detail

serialize

public byte[] serialize()

deserialize

public Object deserialize()

compact

public void compact(boolean preferSerializedRepresentation,
                    boolean force)
Compacts the references held by this class to a single reference. If only one representation exists this method is a no-op unless the 'force' parameter is used, in which case the reference held is forcefully switched to the 'preferred representation'.

Either way, a call to compact() will ensure that only one representation is held.

Parameters:
preferSerializedRepresentation - if true and both representations exist, the serialized representation is favoured. If false, the deserialized representation is preferred.
force - ensures the preferred representation is maintained and the other released, even if this means serializing or deserializing.

getRaw

public byte[] getRaw()

get

public Object get()
Returns the 'cached' instance


equals

public boolean equals(Object o)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

setEqualityPreferenceForInstance

public MarshalledValue setEqualityPreferenceForInstance(boolean equalityPreferenceForInstance)

isTypeExcluded

public static boolean isTypeExcluded(Class type)
Tests whether the type should be excluded from MarshalledValue wrapping.

Parameters:
type - type to test. Should not be null.
Returns:
true if it should be excluded from MarshalledValue wrapping.

-->

Copyright © 2011 JBoss, a division of Red Hat. All Rights Reserved.