org.terracotta.cache.serialization
Class SerializedEntry<T>

java.lang.Object
  extended by org.terracotta.cache.value.AbstractStatelessTimestampedValue<V>
      extended by org.terracotta.cache.value.AbstractTimestampedValue<byte[]>
          extended by org.terracotta.cache.serialization.SerializedEntry<T>
All Implemented Interfaces:
Externalizable, Serializable, ExpirableEntry, MarkTimestampedValue, TimestampedValue<byte[]>
Direct Known Subclasses:
CustomLifespanSerializedEntry

public class SerializedEntry<T>
extends AbstractTimestampedValue<byte[]>
implements Externalizable

Storage wrapper for serialized cache entries.

This wrapper handles the de-serialization of the serialized cache entries, and also the local caching (in a transient reference) of the de-serialized value.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.terracotta.cache.value.AbstractTimestampedValue
lastAccessedTime
 
Fields inherited from class org.terracotta.cache.value.AbstractStatelessTimestampedValue
UNUSED
 
Fields inherited from interface org.terracotta.cache.TimestampedValue
NEVER_EXPIRE
 
Constructor Summary
SerializedEntry()
           
SerializedEntry(SerializedEntryParameters<T> params)
           
SerializedEntry(T deserialized, byte[] serialized, int createTime)
          Constructs a wrapper around the given entry, and it's serialized state using a specific creation time.
SerializedEntry(T deserialized, byte[] serialized, int createTime, int lastAccessedTime)
          Constructs a wrapper around the given entry, and it's serialized state using a specific creation and last accessed time.
SerializedEntry(T deserialized, byte[] serialized, TimeSource timeSource)
          Constructs a wrapper around the given entry, and it's serialized state.
 
Method Summary
 void addedToLocalCache()
          Discard the local copy of this entry's serialized state.
 boolean equals(Object obj)
          Compare whether the value in this entry equals the value in another entry.
 int getCreateTime()
          Retrieves the time when this value was created.
 T getDeserializedValue(SerializationStrategy<T> strategy)
          Return a copy of this entry, potentially reusing a cached copy.
 T getDeserializedValue(SerializationStrategy<T> strategy, ClassLoader classLoader)
          Return a copy of this entry, potentially reusing a cached copy, using the specified classloader if required.
 T getDeserializedValueCopy(SerializationStrategy<T> strategy)
          Return a new copy of this entry, newly deserialized from the serialized state.
 T getDeserializedValueCopy(SerializationStrategy<T> strategy, ClassLoader classLoader)
          Return a new copy of this entry, newly deserialized from the serialized state, using a specific classloader.
 byte[] getValue()
          Get the actual value in the cache.
 void markTxnComplete()
           
 void markTxnInProgress()
           
 void nullByteArray()
           
 void readExternal(ObjectInput in)
           
 boolean shouldRecalculateSize()
           
 String toString()
           
 T unsafelyGetDeserializedValue(SerializationStrategy<T> strategy, ClassLoader classLoader)
           
 T unsafelyGetDeserializedValueCopy(SerializationStrategy<T> strategy, ClassLoader classLoader)
           
 void writeExternal(ObjectOutput out)
           
 
Methods inherited from class org.terracotta.cache.value.AbstractTimestampedValue
fastGetCapacityEvictionPolicyData, getCapacityEvictionPolicyData, getLastAccessedTime, setCapacityEvictionPolicyData, setLastAccessedTimeInternal
 
Methods inherited from class org.terracotta.cache.value.AbstractStatelessTimestampedValue
expiresAt, expiresAt, hashCode, isExpired, markUsed, markUsed
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SerializedEntry

public SerializedEntry()

SerializedEntry

public SerializedEntry(T deserialized,
                       byte[] serialized,
                       TimeSource timeSource)
Constructs a wrapper around the given entry, and it's serialized state.

Parameters:
deserialized - cache entry
serialized - serialized form
timeSource - source for timestamps

SerializedEntry

public SerializedEntry(T deserialized,
                       byte[] serialized,
                       int createTime)
Constructs a wrapper around the given entry, and it's serialized state using a specific creation time.

Parameters:
deserialized - cache entry
serialized - serialized form
createTime - creation timestamp

SerializedEntry

public SerializedEntry(T deserialized,
                       byte[] serialized,
                       int createTime,
                       int lastAccessedTime)
Constructs a wrapper around the given entry, and it's serialized state using a specific creation and last accessed time.

Parameters:
deserialized - cache entry
serialized - serialized form
createTime - creation timestamp
lastAccessedTime - last accessed timestamp

SerializedEntry

public SerializedEntry(SerializedEntryParameters<T> params)
Method Detail

getDeserializedValueCopy

public T getDeserializedValueCopy(SerializationStrategy<T> strategy)
                           throws IOException,
                                  ClassNotFoundException
Return a new copy of this entry, newly deserialized from the serialized state.

Parameters:
strategy - deserialization strategy
Returns:
a newly deserialized entry
Throws:
IOException - if de-serialization fails
ClassNotFoundException - if a necessary class definition is missing

getDeserializedValueCopy

public T getDeserializedValueCopy(SerializationStrategy<T> strategy,
                                  ClassLoader classLoader)
                           throws IOException,
                                  ClassNotFoundException
Return a new copy of this entry, newly deserialized from the serialized state, using a specific classloader.

Parameters:
strategy - deserialization strategy
classLoader - loader to use during deserialization
Returns:
a newly deserialized entry
Throws:
IOException - if de-serialization fails
ClassNotFoundException - if a necessary class definition is missing

unsafelyGetDeserializedValueCopy

public T unsafelyGetDeserializedValueCopy(SerializationStrategy<T> strategy,
                                          ClassLoader classLoader)
                                   throws IOException,
                                          ClassNotFoundException
Throws:
IOException
ClassNotFoundException

getDeserializedValue

public T getDeserializedValue(SerializationStrategy<T> strategy)
                       throws IOException,
                              ClassNotFoundException
Return a copy of this entry, potentially reusing a cached copy.

Parameters:
strategy - deserialization strategy
Returns:
a newly deserialized entry
Throws:
IOException - if de-serialization fails
ClassNotFoundException - if a necessary class definition is missing

getDeserializedValue

public T getDeserializedValue(SerializationStrategy<T> strategy,
                              ClassLoader classLoader)
                       throws IOException,
                              ClassNotFoundException
Return a copy of this entry, potentially reusing a cached copy, using the specified classloader if required.

Parameters:
strategy - deserialization strategy
classLoader - loader to use during deserialization
Returns:
a newly deserialized entry
Throws:
IOException - if de-serialization fails
ClassNotFoundException - if a necessary class definition is missing

unsafelyGetDeserializedValue

public T unsafelyGetDeserializedValue(SerializationStrategy<T> strategy,
                                      ClassLoader classLoader)
                               throws IOException,
                                      ClassNotFoundException
Throws:
IOException
ClassNotFoundException

addedToLocalCache

public void addedToLocalCache()
Discard the local copy of this entry's serialized state.


getCreateTime

public int getCreateTime()
Description copied from interface: TimestampedValue
Retrieves the time when this value was created.

Specified by:
getCreateTime in interface TimestampedValue<byte[]>
Specified by:
getCreateTime in class AbstractStatelessTimestampedValue<byte[]>
Returns:
this value's creation time in seconds since epoch

getValue

public byte[] getValue()
Description copied from interface: TimestampedValue
Get the actual value in the cache.

Specified by:
getValue in interface TimestampedValue<byte[]>
Specified by:
getValue in class AbstractStatelessTimestampedValue<byte[]>
Returns:
The value

toString

public String toString()
Overrides:
toString in class AbstractStatelessTimestampedValue<byte[]>

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Specified by:
writeExternal in interface Externalizable
Throws:
IOException

readExternal

public void readExternal(ObjectInput in)
                  throws IOException
Specified by:
readExternal in interface Externalizable
Throws:
IOException

equals

public boolean equals(Object obj)
Description copied from class: AbstractStatelessTimestampedValue
Compare whether the value in this entry equals the value in another entry. Timestamps are ignored for equality purposes. Two null values will compare equals.

Overrides:
equals in class AbstractStatelessTimestampedValue<byte[]>

markTxnInProgress

public void markTxnInProgress()

markTxnComplete

public void markTxnComplete()

nullByteArray

public void nullByteArray()

shouldRecalculateSize

public boolean shouldRecalculateSize()


Copyright © 2015 Terracotta, Inc.. All Rights Reserved.