public synchronized T getDeserializedValue(final SerializationStrategy<T> strategy, ClassLoader classLoader) throws IOException, ClassNotFoundException { if (cached == null) { cached = strategy.deserialize(getValue(), classLoader); nullByteArray(); } return cached; }
/** * Return a copy of this entry, potentially reusing a cached copy. * * @param strategy deserialization strategy * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public T getDeserializedValue(final SerializationStrategy<T> strategy) throws IOException, ClassNotFoundException { return getDeserializedValue(strategy, null); }
public SerializedEntry(final T deserialized, final byte[] serialized, final int createTime, final int lastAccessedTime) { this.value = serialized; this.createTime = createTime; this.setLastAccessedTimeInternal(lastAccessedTime); this.cached = deserialized; }
/** * Return a copy of this entry, potentially reusing a cached copy, using the specified classloader if required. * * @param strategy deserialization strategy * @param classLoader loader to use during deserialization * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public synchronized T getDeserializedValue(final SerializationStrategy<T> strategy, final ClassLoader classLoader) throws IOException, ClassNotFoundException { if (this.cached == null) { this.cached = strategy.deserialize(getValue()); nullByteArrayIfNecessary(); } return this.cached; }
/** * Return a new copy of this entry, newly deserialized from the serialized state. * * @param strategy deserialization strategy * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public T getDeserializedValueCopy(final SerializationStrategy<T> strategy) throws IOException, ClassNotFoundException { return strategy.deserialize(getValue()); }
public void put(final Object key, final Object value) throws CacheException { if (!isEnabled()) { return; } byte[] data; try { data = serializationStrategy.serialize(value); } catch (Exception e) { throw new CacheException(e); } String sKey = generateStringKeyFor(key); SerializedEntry entry = new SerializedEntry(value, data, store.getTimeSource()); store.putNoReturn(sKey, entry); // Now that the entry is shared we can drop the byte[] entry.nullByteArray(); }
public void processStoredValue(final TimestampedValue value) { if (!copyOnRead) { ((SerializedEntry) value).nullByteArray(); } }
public Element createElement(final Object key, final TimestampedValue value) { if (null == value) { return null; } SerializedEntry<AbstractElementData> entry = (SerializedEntry<AbstractElementData>) value; AbstractElementData data; try { if (copyOnRead) { data = entry.getDeserializedValueCopy(serializationStrategy, threadContextAwareClassLoader); } else { data = entry.getDeserializedValue(serializationStrategy, threadContextAwareClassLoader); } } catch (Exception e) { throw new CacheException(e); } Element element = data.createElement(key); element.setElementEvictionData(new ClusteredElementEvictionData(store, value)); return element; }
public TimestampedValue createTimestampedValue(final Element element) { SerializationModeElementData value = new SerializationModeElementData(element); byte[] data; try { data = store.getSerializationStrategy().serialize(value); } catch (Exception e) { throw new CacheException(e); } TimestampedValue entry = new SerializedEntry<SerializationModeElementData>(value, data, element.getElementEvictionData().getCreationTime(), element.getElementEvictionData().getCreationTime()); return entry; }
/** * Return a new copy of this entry, newly deserialized from the serialized state. * * @param strategy deserialization strategy * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public T getDeserializedValueCopy(final SerializationStrategy<T> strategy) throws IOException, ClassNotFoundException { return getDeserializedValueCopy(strategy, null); }
public T getDeserializedValueCopy(final SerializationStrategy<T> strategy, ClassLoader classLoader) throws IOException, ClassNotFoundException { return strategy.deserialize(getValue(), classLoader); }
public void processStoredValue(final TimestampedValue value) { ((SerializedEntry) value).nullByteArray(); }
public TimestampedValue createTimestampedValue(final Element element) { SerializationModeElementData value = new SerializationModeElementData(element); byte[] data; try { data = serializationStrategy.serialize(value); } catch (Exception e) { throw new CacheException(e); } // we can store null in the entry if we're doing copy on read value = copyOnRead ? null : value; if (element.usesCacheDefaultLifespan()) { return new SerializedEntry<SerializationModeElementData>(value, data, TimeUtil.toSecs(element.getElementEvictionData().getCreationTime()), TimeUtil.toSecs(element.getElementEvictionData().getCreationTime())); } else { int tti = element.getTimeToIdle(); int ttl = element.getTimeToLive(); return new CustomLifespanSerializedEntry<SerializationModeElementData>(value, data, tti, ttl, TimeUtil.toSecs(element.getElementEvictionData().getCreationTime()), TimeUtil.toSecs(element.getElementEvictionData().getCreationTime())); } }
public synchronized T getDeserializedValue(final SerializationStrategy<T> strategy) throws IOException, ClassNotFoundException { if (cached == null) { cached = strategy.deserialize(getValue()); nullByteArray(); } return cached; }
/** * Return a new copy of this entry, newly deserialized from the serialized state, using a specific classloader. * * @param strategy deserialization strategy * @param classLoader loader to use during deserialization * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public T getDeserializedValueCopy(final SerializationStrategy<T> strategy, final ClassLoader classLoader) throws IOException, ClassNotFoundException { return strategy.deserialize(getValue(), classLoader); }
/** * Constructs a wrapper around the given entry, and it's serialized state using a specific creation and last accessed * time. * * @param deserialized cache entry * @param serialized serialized form * @param createTime creation timestamp * @param lastAccessedTime last accessed timestamp */ public SerializedEntry(final T deserialized, final byte[] serialized, final int createTime, final int lastAccessedTime) { this.value = serialized; this.createTime = createTime; setLastAccessedTimeInternal(lastAccessedTime); this.cached = deserialized; }
/** * Returns the unwrapped SerializedEntry if the reference is non-null. * * @param entry retrieved reference * @return unwrapped Object or null */ private static Object unwrap(final SerializedEntry entry, final SerializationStrategy serializationStrategy) { if (entry == null) { return null; } else { try { return entry.getDeserializedValue(serializationStrategy); } catch (Exception e) { throw new CacheException(e); } } }
/** * Return a copy of this entry, potentially reusing a cached copy. * * @param strategy deserialization strategy * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public synchronized T getDeserializedValue(final SerializationStrategy<T> strategy) throws IOException, ClassNotFoundException { if (this.cached == null) { this.cached = strategy.deserialize(getValue()); nullByteArray(); } return this.cached; }
/** * Return a new copy of this entry, newly deserialized from the serialized state, using a specific classloader. * * @param strategy deserialization strategy * @param classLoader loader to use during deserialization * @return a newly deserialized entry * @throws IOException if de-serialization fails * @throws ClassNotFoundException if a necessary class definition is missing */ public T getDeserializedValueCopy(final SerializationStrategy<T> strategy, final ClassLoader classLoader) throws IOException, ClassNotFoundException { return strategy.deserialize(getValue(), classLoader); }
/** * Constructs a wrapper around the given entry, and it's serialized state using a specific creation and last accessed * time. * * @param deserialized cache entry * @param serialized serialized form * @param createTime creation timestamp * @param lastAccessedTime last accessed timestamp */ public SerializedEntry(final T deserialized, final byte[] serialized, final int createTime, final int lastAccessedTime) { this.value = serialized; this.createTime = createTime; setLastAccessedTimeInternal(lastAccessedTime); this.cached = deserialized; }