You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by hc...@apache.org on 2005/01/29 11:19:24 UTC
cvs commit: jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft SoftRefCache.java SoftRefCacheSafe.java SoftRefFileCache.java SoftRefFileCacheSafe.java SoftRefCacheCleaner.java
hchar 2005/01/29 02:19:24
Modified: sandbox/yajcache/src/org/apache/jcs/yajcache/soft
SoftRefCache.java SoftRefCacheSafe.java
SoftRefFileCache.java SoftRefFileCacheSafe.java
Removed: sandbox/yajcache/src/org/apache/jcs/yajcache/soft
SoftRefCacheCleaner.java
Log:
deprecate SoftRefCacheCleaner;
simplify constructors;
use JavaBean pattern for per cache config
Revision Changes Path
1.5 +30 -19 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefCache.java
Index: SoftRefCache.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefCache.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- SoftRefCache.java 28 Jan 2005 10:41:10 -0000 1.4
+++ SoftRefCache.java 29 Jan 2005 10:19:24 -0000 1.5
@@ -25,11 +25,12 @@
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
-import org.apache.jcs.yajcache.core.CacheEntry;
-import org.apache.jcs.yajcache.core.ICache;
+import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.yajcache.config.PerCacheConfig;
+import org.apache.jcs.yajcache.core.CacheEntry;
+import org.apache.jcs.yajcache.core.ICache;
import org.apache.jcs.yajcache.lang.annotation.*;
import org.apache.jcs.yajcache.lang.ref.KeyedRefCollector;
import org.apache.jcs.yajcache.lang.ref.KeyedSoftReference;
@@ -50,47 +51,41 @@
private final @NonNullable Class<V> valueType;
private final @NonNullable ConcurrentMap<String, KeyedSoftReference<String,V>> map;
private final @NonNullable KeyedRefCollector<String> collector;
- private final @NonNullable PerCacheConfig config;
+ private @NonNullable PerCacheConfig config;
- public String getName() {
+ public @NonNullable String getName() {
return this.name;
}
- public Class<V> getValueType() {
+ public @NonNullable Class<V> getValueType() {
return this.valueType;
}
public SoftRefCache(@NonNullable String name, @NonNullable Class<V> valueType,
- @NonNullable PerCacheConfig config,
int initialCapacity, float loadFactor, int concurrencyLevel)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity, loadFactor, concurrencyLevel);
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity, loadFactor, concurrencyLevel);
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public SoftRefCache(
@NonNullable String name,
@NonNullable Class<V> valueType,
- @NonNullable PerCacheConfig config,
int initialCapacity)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity);
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity);
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public SoftRefCache(
@NonNullable String name,
- @NonNullable Class<V> valueType,
- @NonNullable PerCacheConfig config)
+ @NonNullable Class<V> valueType)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>();
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>();
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public boolean isEmpty() {
@@ -116,7 +111,8 @@
if (val == null) {
// already garbage collected. So try to clean up the key.
- SoftRefCacheCleaner.inst.cleanupKey(this.map, key);
+ this.map.remove(key, ref);
+// SoftRefCacheCleaner.inst.cleanupKey(this.map, key);
}
// cache value exists.
// try to refresh the soft reference.
@@ -267,4 +263,19 @@
public int getCollectorCount() {
return this.collector.getCount();
}
+
+ @NonNullable PerCacheConfig getConfig() {
+ return config;
+ }
+
+ void setConfig(@NonNullable PerCacheConfig config) {
+ this.config = config;
+ }
+ @Override public String toString() {
+ return new ToStringBuilder(this)
+ .append("name", this.getName())
+ .append("valueType", this.getValueType().getName())
+ .append("collector", this.collector)
+ .toString();
+ }
}
1.4 +4 -6 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefCacheSafe.java
Index: SoftRefCacheSafe.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefCacheSafe.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SoftRefCacheSafe.java 27 Jan 2005 11:06:06 -0000 1.3
+++ SoftRefCacheSafe.java 29 Jan 2005 10:19:24 -0000 1.4
@@ -34,22 +34,20 @@
implements ICacheSafe<V>
{
public SoftRefCacheSafe(@NonNullable String name, @NonNullable Class<V> valueType,
- PerCacheConfig config,
int initialCapacity, float loadFactor, int concurrencyLevel)
{
- super(name, valueType, config, initialCapacity, loadFactor, concurrencyLevel);
+ super(name, valueType, initialCapacity, loadFactor, concurrencyLevel);
}
public SoftRefCacheSafe(@NonNullable String name, @NonNullable Class<V> valueType,
- PerCacheConfig config,
int initialCapacity)
{
- super(name, valueType, config, initialCapacity);
+ super(name, valueType, initialCapacity);
}
public SoftRefCacheSafe(@NonNullable String name,
- @NonNullable Class<V> valueType, PerCacheConfig config)
+ @NonNullable Class<V> valueType)
{
- super(name, valueType, config);
+ super(name, valueType);
}
public V getCopy(@NonNullable String key) {
V val = this.get(key);
1.4 +32 -21 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefFileCache.java
Index: SoftRefFileCache.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefFileCache.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- SoftRefFileCache.java 28 Jan 2005 11:17:49 -0000 1.3
+++ SoftRefFileCache.java 29 Jan 2005 10:19:24 -0000 1.4
@@ -28,15 +28,18 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.locks.Lock;
+
import org.apache.commons.lang.SerializationUtils;
-import org.apache.jcs.yajcache.core.CacheEntry;
-import org.apache.jcs.yajcache.core.ICache;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.commons.lang.builder.ToStringBuilder;
+
import org.apache.jcs.yajcache.lang.annotation.*;
import org.apache.jcs.yajcache.config.PerCacheConfig;
import org.apache.jcs.yajcache.core.ICacheChangeListener;
import org.apache.jcs.yajcache.core.CacheChangeSupport;
+import org.apache.jcs.yajcache.core.CacheEntry;
+import org.apache.jcs.yajcache.core.ICache;
import org.apache.jcs.yajcache.file.CacheFileContent;
import org.apache.jcs.yajcache.file.CacheFileContentType;
import org.apache.jcs.yajcache.file.CacheFileDAO;
@@ -61,7 +64,7 @@
private final @NonNullable String name;
private final @NonNullable Class<V> valueType;
private final @NonNullable ConcurrentMap<String,KeyedSoftReference<String,V>> map;
- private final @NonNullable PerCacheConfig config;
+ private PerCacheConfig config;
private final @NonNullable KeyedRefCollector<String> collector;
private final IKeyedReadWriteLock<String> krwl = new KeyedReadWriteLock<String>();
@@ -80,54 +83,47 @@
private AtomicInteger countPut = new AtomicInteger(0);
private AtomicInteger countRemove = new AtomicInteger(0);
- public String getName() {
+ public @NonNullable String getName() {
return this.name;
}
- public Class<V> getValueType() {
+ public @NonNullable Class<V> getValueType() {
return this.valueType;
}
public SoftRefFileCache(
@NonNullable String name, @NonNullable Class<V> valueType,
- @NonNullable PerCacheConfig config,
int initialCapacity,float loadFactor, int concurrencyLevel)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(
- initialCapacity, loadFactor, concurrencyLevel);
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity, loadFactor, concurrencyLevel);
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public SoftRefFileCache(
@NonNullable String name, @NonNullable Class<V> valueType,
- @NonNullable PerCacheConfig config,
int initialCapacity)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity);
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>(initialCapacity);
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public SoftRefFileCache(@NonNullable String name,
- @NonNullable Class<V> valueType,
- PerCacheConfig config)
+ @NonNullable Class<V> valueType)
{
- map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>();
- collector = new KeyedRefCollector<String>(refq, map);
+ this.map = new ConcurrentHashMap<String,KeyedSoftReference<String,V>>();
+ this.collector = new KeyedRefCollector<String>(refq, map);
this.name = name;
this.valueType = valueType;
- this.config = config;
}
public boolean isEmpty() {
- collector.run();
+ this.collector.run();
return map.isEmpty();
}
public int size() {
- collector.run();
+ this.collector.run();
return map.size();
}
@@ -390,4 +386,19 @@
{
this.cacheChangeSupport.removeCacheChangeListener(listener);
}
+
+ public PerCacheConfig getConfig() {
+ return config;
+ }
+
+ public void setConfig(PerCacheConfig config) {
+ this.config = config;
+ }
+ @Override public String toString() {
+ return new ToStringBuilder(this)
+ .append("name", this.getName())
+ .append("valueType", this.getValueType().getName())
+ .append("collector", this.collector)
+ .toString();
+ }
}
1.2 +4 -6 jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefFileCacheSafe.java
Index: SoftRefFileCacheSafe.java
===================================================================
RCS file: /home/cvs/jakarta-turbine-jcs/sandbox/yajcache/src/org/apache/jcs/yajcache/soft/SoftRefFileCacheSafe.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SoftRefFileCacheSafe.java 27 Jan 2005 11:02:12 -0000 1.1
+++ SoftRefFileCacheSafe.java 29 Jan 2005 10:19:24 -0000 1.2
@@ -34,22 +34,20 @@
implements ICacheSafe<V>
{
public SoftRefFileCacheSafe(@NonNullable String name, @NonNullable Class<V> valueType,
- PerCacheConfig config,
int initialCapacity, float loadFactor, int concurrencyLevel)
{
- super(name, valueType, config, initialCapacity, loadFactor, concurrencyLevel);
+ super(name, valueType, initialCapacity, loadFactor, concurrencyLevel);
}
public SoftRefFileCacheSafe(@NonNullable String name, @NonNullable Class<V> valueType,
- PerCacheConfig config,
int initialCapacity)
{
- super(name, valueType, config, initialCapacity);
+ super(name, valueType, initialCapacity);
}
public SoftRefFileCacheSafe(@NonNullable String name,
- @NonNullable Class<V> valueType, PerCacheConfig config)
+ @NonNullable Class<V> valueType)
{
- super(name, valueType, config);
+ super(name, valueType);
}
public V getCopy(@NonNullable String key) {
V val = this.get(key);
---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org