From c270234f37f0d9bdb1755f22561cbcba156b6e8c Mon Sep 17 00:00:00 2001 From: "Brian S. O'Neill" Date: Wed, 18 Aug 2010 16:54:59 +0000 Subject: Introduce SoftValuedCache, which evicts more aggressively than SoftValuedHashMap. --- .../java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java | 7 ++++--- .../com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java | 6 ++++-- src/main/java/com/amazon/carbonado/repo/map/Key.java | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) (limited to 'src/main/java/com/amazon/carbonado/repo') diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java index e929e6b..e40ce04 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableGenerator.java @@ -43,7 +43,6 @@ import org.cojen.classfile.Opcode; import org.cojen.classfile.TypeDesc; import org.cojen.util.ClassInjector; import org.cojen.util.KeyFactory; -import org.cojen.util.SoftValuedHashMap; import org.joda.time.ReadableInstant; @@ -65,6 +64,8 @@ import com.amazon.carbonado.gen.StorableGenerator; import com.amazon.carbonado.gen.TriggerSupport; import static com.amazon.carbonado.gen.CommonMethodNames.*; +import com.amazon.carbonado.util.SoftValuedCache; + /** * Generates concrete implementations of {@link Storable} types for * {@link JDBCRepository}. @@ -87,10 +88,10 @@ class JDBCStorableGenerator { private static final int INITIAL_VERSION = 2; private static final int INCREMENT_VERSION = 3; - private static final Map> cCache; + private static final SoftValuedCache> cCache; static { - cCache = new SoftValuedHashMap(); + cCache = SoftValuedCache.newCache(11); } static Class getGeneratedClass(JDBCStorableInfo info, diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java index 042974f..acba43e 100644 --- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java +++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorableIntrospector.java @@ -46,7 +46,6 @@ import org.apache.commons.logging.LogFactory; import org.cojen.classfile.TypeDesc; import org.cojen.util.KeyFactory; -import org.cojen.util.SoftValuedHashMap; import org.cojen.util.ThrowUnchecked; import com.amazon.carbonado.capability.IndexInfo; @@ -66,6 +65,8 @@ import com.amazon.carbonado.info.StorableProperty; import com.amazon.carbonado.info.StorablePropertyAdapter; import com.amazon.carbonado.info.StorablePropertyConstraint; +import com.amazon.carbonado.util.SoftValuedCache; + /** * Provides additional metadata for a {@link Storable} type needed by * JDBCRepository. The storable type must match to a table in an external @@ -80,7 +81,8 @@ import com.amazon.carbonado.info.StorablePropertyConstraint; public class JDBCStorableIntrospector extends StorableIntrospector { // Maps compound keys to softly referenced JDBCStorableInfo objects. @SuppressWarnings("unchecked") - private static Map> cCache = new SoftValuedHashMap(); + private static SoftValuedCache> cCache = + SoftValuedCache.newCache(11); /** * Examines the given class and returns a JDBCStorableInfo describing it. A diff --git a/src/main/java/com/amazon/carbonado/repo/map/Key.java b/src/main/java/com/amazon/carbonado/repo/map/Key.java index 9348516..86a0023 100644 --- a/src/main/java/com/amazon/carbonado/repo/map/Key.java +++ b/src/main/java/com/amazon/carbonado/repo/map/Key.java @@ -34,7 +34,6 @@ import org.cojen.classfile.Modifiers; import org.cojen.classfile.TypeDesc; import org.cojen.util.ClassInjector; -import org.cojen.util.SoftValuedHashMap; import com.amazon.carbonado.Storable; @@ -45,6 +44,8 @@ import com.amazon.carbonado.info.StorableProperty; import com.amazon.carbonado.gen.CodeBuilderUtil; +import com.amazon.carbonado.util.SoftValuedCache; + /** * * @@ -82,10 +83,10 @@ class Key implements Comparable> { void setKeyValues(S storable, Object[] identityValues, Object rangeValue); } - private static final Map mAssigners; + private static final SoftValuedCache mAssigners; static { - mAssigners = new SoftValuedHashMap(); + mAssigners = SoftValuedCache.newCache(11); } public static synchronized Assigner getAssigner(Class clazz) { -- cgit v1.2.3