Index: branches/ehcache-2.7.x/ehcache-core/src/test/java/net/sf/ehcache/transaction/xa/XATransactionSizeOfTest.java =================================================================== diff -u -N -r7049 -r7131 --- branches/ehcache-2.7.x/ehcache-core/src/test/java/net/sf/ehcache/transaction/xa/XATransactionSizeOfTest.java (.../XATransactionSizeOfTest.java) (revision 7049) +++ branches/ehcache-2.7.x/ehcache-core/src/test/java/net/sf/ehcache/transaction/xa/XATransactionSizeOfTest.java (.../XATransactionSizeOfTest.java) (revision 7131) @@ -17,6 +17,9 @@ import java.util.ArrayList; import java.util.List; +import java.util.logging.ConsoleHandler; +import java.util.logging.Level; +import java.util.logging.Logger; import javax.transaction.Status; @@ -36,7 +39,7 @@ public void setUp() throws Exception { CacheConfiguration txCache1Cfg = new CacheConfiguration().name("txCache1") .transactionalMode(CacheConfiguration.TransactionalMode.XA_STRICT) - .sizeOfPolicy(new SizeOfPolicyConfiguration().maxDepth(15) + .sizeOfPolicy(new SizeOfPolicyConfiguration().maxDepth(13) .maxDepthExceededBehavior(SizeOfPolicyConfiguration.MaxDepthExceededBehavior.ABORT)); CopyStrategyConfiguration copyStrategyConfiguration = new CopyStrategyConfiguration(); copyStrategyConfiguration.setClass(SerializationCopyStrategy.class.getName()); @@ -86,12 +89,10 @@ * Here's what is walked when storing elements with integers both as key and value: * * 40b net.sf.ehcache.store.chm.SelectableConcurrentHashMap$HashEntry@1205901244 - * 72b net.sf.ehcache.Element@1942996580 - * 32b net.sf.ehcache.DefaultElementEvictionData@1928680974 + * 80b net.sf.ehcache.Element@1942996580 * 32b net.sf.ehcache.transaction.SoftLockID@1216216770 - * 72b net.sf.ehcache.Element@350784291 - * 32b net.sf.ehcache.DefaultElementEvictionData@788967822 - * 16b java.lang.Integer@1618147776 + * 80b net.sf.ehcache.Element@350784291 + * 24b java.lang.Integer@1618147776 * ignored java.lang.Integer@1897411861 * 24b net.sf.ehcache.transaction.xa.XidTransactionIDImpl@738355611 * 32b java.lang.String@739090040 @@ -100,7 +101,7 @@ * 56b [B@750131952 * 56b [B@1738709374 * - * That's 14 objects, so make sure SizeOfPolicyConfiguration's maxDepth is >= 15. + * That's 12 objects, so make sure SizeOfPolicyConfiguration's maxDepth is >= 13. */ @Test public void testSizeOf() throws Exception { Index: branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/Element.java =================================================================== diff -u -N -r7049 -r7131 --- branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/Element.java (.../Element.java) (revision 7049) +++ branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/Element.java (.../Element.java) (revision 7131) @@ -25,7 +25,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; @@ -43,7 +42,7 @@ * avoid CacheExceptions. The get... methods are reserved for Serializable keys and values. * * @author Greg Luck - * @version $Id: Element.java 6222 2012-09-04 14:08:37Z cdennis $ + * @version $Id: Element.java 7131 2013-02-15 18:26:48Z ljacomet $ */ public class Element implements Serializable, Cloneable { @@ -100,11 +99,16 @@ private volatile int timeToIdle = Integer.MIN_VALUE; /** - * Pluggable element eviction data instance + * The creation time. */ - private transient volatile ElementEvictionData elementEvictionData; + private transient long creationTime; /** + * The last access time. + */ + private transient long lastAccessTime; + + /** * If there is an Element in the Cache and it is replaced with a new Element for the same key, * then both the version number and lastUpdateTime should be updated to reflect that. The creation time * will be the creation time of the new Element, not the original one, so that TTL concepts still work. @@ -140,7 +144,7 @@ this.value = value; this.version = version; HIT_COUNT_UPDATER.set(this, 0); - this.elementEvictionData = new DefaultElementEvictionData(System.currentTimeMillis()); + this.creationTime = System.currentTimeMillis(); } /** @@ -173,7 +177,8 @@ this.version = version; this.lastUpdateTime = lastUpdateTime; HIT_COUNT_UPDATER.set(this, hitCount); - this.elementEvictionData = new DefaultElementEvictionData(creationTime, lastAccessTime); + this.creationTime = creationTime; + this.lastAccessTime = lastAccessTime; } /** @@ -192,7 +197,8 @@ this.timeToLive = timeToLive; this.timeToIdle = timeToIdle; this.lastUpdateTime = lastUpdateTime; - this.elementEvictionData = new DefaultElementEvictionData(creationTime, lastAccessTime); + this.creationTime = creationTime; + this.lastAccessTime = lastAccessTime; } /** @@ -217,7 +223,7 @@ if (timeToLiveSeconds != null) { setTimeToLive(timeToLiveSeconds.intValue()); } - this.elementEvictionData = new DefaultElementEvictionData(System.currentTimeMillis()); + this.creationTime = System.currentTimeMillis(); } /** @@ -406,7 +412,7 @@ */ @Deprecated public final void setCreateTime() { - this.elementEvictionData.setCreationTime(System.currentTimeMillis()); + creationTime = System.currentTimeMillis(); } /** @@ -415,7 +421,7 @@ * @return The creationTime value */ public final long getCreationTime() { - return elementEvictionData.getCreationTime(); + return creationTime; } /** @@ -424,7 +430,7 @@ */ public final long getLatestOfCreationAndUpdateTime() { if (0 == lastUpdateTime) { - return elementEvictionData.getCreationTime(); + return creationTime; } else { return lastUpdateTime; } @@ -445,7 +451,7 @@ * will have a last access time equal to its create time. */ public final long getLastAccessTime() { - return elementEvictionData.getLastAccessTime(); + return lastAccessTime; } /** @@ -469,36 +475,18 @@ } /** - * Retrieves this element's eviction data instance. - * - * @return this element's eviction data instance - */ - public ElementEvictionData getElementEvictionData() { - return elementEvictionData; - } - - /** - * Sets this element's eviction data instance. - * - * @param elementEvictionData this element's eviction data - */ - public void setElementEvictionData(ElementEvictionData elementEvictionData) { - this.elementEvictionData = elementEvictionData; - } - - /** * Resets the hit count to 0 and the last access time to now. Used when an Element is put into a cache. */ public final void resetAccessStatistics() { - elementEvictionData.resetLastAccessTime(this); + lastAccessTime = System.currentTimeMillis(); HIT_COUNT_UPDATER.set(this, 0); } /** * Sets the last access time to now and increase the hit count. */ public final void updateAccessStatistics() { - elementEvictionData.updateLastAccessTime(System.currentTimeMillis(), this); + lastAccessTime = System.currentTimeMillis(); HIT_COUNT_UPDATER.incrementAndGet(this); } @@ -549,10 +537,7 @@ super.clone(); try { - Element element = new Element(deepCopy(key), deepCopy(value), version); - element.elementEvictionData = elementEvictionData.clone(); - HIT_COUNT_UPDATER.set(element, hitCount); - return element; + return new Element(deepCopy(key), deepCopy(value), version, creationTime, lastAccessTime, 0L, hitCount); } catch (IOException e) { LOG.error("Error cloning Element with key " + key + " during serialization and deserialization of value"); @@ -645,8 +630,7 @@ */ public final boolean isSerializable() { return isKeySerializable() - && (value instanceof Serializable || value == null) - && elementEvictionData.canParticipateInSerialization(); + && (value instanceof Serializable || value == null); } /** @@ -729,12 +713,12 @@ } long expirationTime = 0; - long ttlExpiry = elementEvictionData.getCreationTime() + TimeUtil.toMillis(getTimeToLive()); + long ttlExpiry = creationTime + TimeUtil.toMillis(getTimeToLive()); - long mostRecentTime = Math.max(elementEvictionData.getCreationTime(), elementEvictionData.getLastAccessTime()); + long mostRecentTime = Math.max(creationTime, lastAccessTime); long ttiExpiry = mostRecentTime + TimeUtil.toMillis(getTimeToIdle()); - if (getTimeToLive() != 0 && (getTimeToIdle() == 0 || elementEvictionData.getLastAccessTime() == 0)) { + if (getTimeToLive() != 0 && (getTimeToIdle() == 0 || lastAccessTime == 0)) { expirationTime = ttlExpiry; } else if (getTimeToLive() == 0) { expirationTime = ttiExpiry; @@ -829,19 +813,17 @@ * Custom serialization write logic */ private void writeObject(ObjectOutputStream out) throws IOException { - if (!elementEvictionData.canParticipateInSerialization()) { - throw new NotSerializableException(); - } out.defaultWriteObject(); - out.writeInt(TimeUtil.toSecs(elementEvictionData.getCreationTime())); - out.writeInt(TimeUtil.toSecs(elementEvictionData.getLastAccessTime())); + out.writeInt(TimeUtil.toSecs(creationTime)); + out.writeInt(TimeUtil.toSecs(lastAccessTime)); } /** * Custom serialization read logic */ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { in.defaultReadObject(); - elementEvictionData = new DefaultElementEvictionData(TimeUtil.toMillis(in.readInt()), TimeUtil.toMillis(in.readInt())); + creationTime = TimeUtil.toMillis(in.readInt()); + lastAccessTime = TimeUtil.toMillis(in.readInt()); } } Index: branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/ElementEvictionData.java =================================================================== diff -u -N --- branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/ElementEvictionData.java (revision 7049) +++ branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/ElementEvictionData.java (revision 0) @@ -1,84 +0,0 @@ -/** - * Copyright Terracotta, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.ehcache; - -/** - * Provides pluggable storage and configuration of TTI eviction data. - * - * @author Geert Bevin - * @version $Id: ElementEvictionData.java 5594 2012-05-07 16:04:31Z cdennis $ - */ -public interface ElementEvictionData extends Cloneable { - - /** - * Sets the element creation time. Note that this is optional to implement and might result in a no-op. - * - * @param creationTime the new element's creation time - */ - public void setCreationTime(long creationTime); - - /** - * Get the element's creation time. - * - * @return the element's creation time in seconds - */ - public long getCreationTime(); - - /** - * Gets the last access time. - * Access means a get. So a newly created {@link Element} will have a last - * access time equal to its create time. - * - * @return the element's last access time in seconds - */ - public long getLastAccessTime(); - - /** - * Updates the last access time. - * - * @param time - * the new last access time - * @param element - * the element for which the last access time is set - */ - public void updateLastAccessTime(long time, Element element); - - /** - * Resets the last access time. - * - * @param element - * the element for which the last access time is set - */ - public void resetLastAccessTime(Element element); - - /** - * Creates a clone of the eviction data - * - * @return a clone of the eviction data - * @throws CloneNotSupportedException - */ - public ElementEvictionData clone() throws CloneNotSupportedException; - - /** - * Indicates whether the data of this element eviction instance can - * participate in serialization of the element as a whole. - * - * @return {@code true} when the data can participate in serialization; or - * {@code false} otherwise - */ - public boolean canParticipateInSerialization(); -} Index: branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/DefaultElementEvictionData.java =================================================================== diff -u -N --- branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/DefaultElementEvictionData.java (revision 7049) +++ branches/ehcache-2.7.x/ehcache-core/src/main/java/net/sf/ehcache/DefaultElementEvictionData.java (revision 0) @@ -1,108 +0,0 @@ -/** - * Copyright Terracotta, Inc. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.ehcache; - -/** - * Default implementation of the element eviction data storage that just keeps - * all the data in instance fields in the heap. - * - * @author Geert Bevin - * @version $Id: DefaultElementEvictionData.java 1219 2009-09-25 05:10:31Z - * gbevin $ - */ -public class DefaultElementEvictionData implements ElementEvictionData { - - /** - * The creation time. - */ - private long creationTime; - - /** - * The last access time. - */ - private long lastAccessTime; - - /** - * Default constructor initializing the field to their empty values - */ - public DefaultElementEvictionData(long creationTime) { - this.creationTime = creationTime; - } - - /** - * Constructor allowing custom values for the data fields. - * - * @param lastAccessTime - */ - public DefaultElementEvictionData(long creationTime, long lastAccessTime) { - this.creationTime = creationTime; - this.lastAccessTime = lastAccessTime; - } - - /** - * {@inheritDoc} - */ - public void setCreationTime(long creationTime) { - this.creationTime = creationTime; - } - - /** - * {@inheritDoc} - */ - public long getCreationTime() { - return creationTime; - } - - /** - * {@inheritDoc} - */ - public long getLastAccessTime() { - return lastAccessTime; - } - - /** - * {@inheritDoc} - */ - public void updateLastAccessTime(long time, Element element) { - lastAccessTime = time; - } - - /** - * {@inheritDoc} - */ - public void resetLastAccessTime(Element element) { - lastAccessTime = System.currentTimeMillis(); - } - - /** - * {@inheritDoc} - */ - @Override - public final ElementEvictionData clone() throws CloneNotSupportedException { - DefaultElementEvictionData result = (DefaultElementEvictionData)super.clone(); - result.creationTime = this.creationTime; - result.lastAccessTime = this.lastAccessTime; - return result; - } - - /** - * {@inheritDoc} - */ - public boolean canParticipateInSerialization() { - return true; - } -}