You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2012/05/30 20:14:51 UTC
svn commit: r1344374 [3/14] - in /commons/proper/jcs/trunk: ./
auxiliary-builds/javagroups/src/java/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/jdk14/src/java/org/apache/jcs/auxiliary/javagroups/
auxiliary-builds/jdk14/src/java/org/apache/jcs...
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCache.java Wed May 30 18:14:43 2012
@@ -12,8 +12,8 @@ import org.apache.jcs.engine.match.behav
import org.apache.jcs.utils.serialization.StandardSerializer;
/** This holds convenience methods used by most auxiliary caches. */
-public abstract class AbstractAuxiliaryCache
- implements AuxiliaryCache
+public abstract class AbstractAuxiliaryCache<K extends Serializable, V extends Serializable>
+ implements AuxiliaryCache<K, V>
{
/** Don't change. */
private static final long serialVersionUID = -1285708398502576617L;
@@ -24,11 +24,8 @@ public abstract class AbstractAuxiliaryC
/** The serializer. Uses a standard serializer by default. */
protected IElementSerializer elementSerializer = new StandardSerializer();
- /** If there is no event logger, we will return this event for all create calls. */
- private static final ICacheEvent EMPTY_ICACHE_EVENT = new CacheEvent();
-
/** Key matcher used by the getMatching API */
- protected IKeyMatcher keyMatcher = new KeyMatcherPatternImpl();
+ protected IKeyMatcher<K> keyMatcher = new KeyMatcherPatternImpl<K>();
/**
* Logs an event if an event logger is configured.
@@ -37,20 +34,22 @@ public abstract class AbstractAuxiliaryC
* @param eventName
* @return ICacheEvent
*/
- protected ICacheEvent createICacheEvent( ICacheElement item, String eventName )
+ protected ICacheEvent<K> createICacheEvent( ICacheElement<K, V> item, String eventName )
{
if ( cacheEventLogger == null )
{
- return EMPTY_ICACHE_EVENT;
+ return new CacheEvent<K>();
}
String diskLocation = getEventLoggingExtraInfo();
String regionName = null;
+ K key = null;
if ( item != null )
{
regionName = item.getCacheName();
+ key = item.getKey();
}
return cacheEventLogger.createICacheEvent( getAuxiliaryCacheAttributes().getName(), regionName, eventName,
- diskLocation, item );
+ diskLocation, key );
}
/**
@@ -61,11 +60,11 @@ public abstract class AbstractAuxiliaryC
* @param eventName
* @return ICacheEvent
*/
- protected ICacheEvent createICacheEvent( String regionName, Serializable key, String eventName )
+ protected <T extends Serializable> ICacheEvent<T> createICacheEvent( String regionName, T key, String eventName )
{
if ( cacheEventLogger == null )
{
- return EMPTY_ICACHE_EVENT;
+ return new CacheEvent<T>();
}
String diskLocation = getEventLoggingExtraInfo();
return cacheEventLogger.createICacheEvent( getAuxiliaryCacheAttributes().getName(), regionName, eventName,
@@ -78,7 +77,7 @@ public abstract class AbstractAuxiliaryC
* <p>
* @param cacheEvent
*/
- protected void logICacheEvent( ICacheEvent cacheEvent )
+ protected <T extends Serializable> void logICacheEvent( ICacheEvent<T> cacheEvent )
{
if ( cacheEventLogger != null )
{
@@ -174,7 +173,7 @@ public abstract class AbstractAuxiliaryC
* <p>
* @param keyMatcher
*/
- public void setKeyMatcher( IKeyMatcher keyMatcher )
+ public void setKeyMatcher( IKeyMatcher<K> keyMatcher )
{
if ( keyMatcher != null )
{
@@ -187,7 +186,7 @@ public abstract class AbstractAuxiliaryC
* <p>
* @return keyMatcher
*/
- public IKeyMatcher getKeyMatcher()
+ public IKeyMatcher<K> getKeyMatcher()
{
return this.keyMatcher;
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AbstractAuxiliaryCacheEventLogging.java Wed May 30 18:14:43 2012
@@ -15,8 +15,8 @@ import org.apache.jcs.engine.logging.beh
* <p>
* You can override the public method, but if you don't, the default will call getWithTiming.
*/
-public abstract class AbstractAuxiliaryCacheEventLogging
- extends AbstractAuxiliaryCache
+public abstract class AbstractAuxiliaryCacheEventLogging<K extends Serializable, V extends Serializable>
+ extends AbstractAuxiliaryCache<K, V>
{
/** Don't change. */
private static final long serialVersionUID = -3921738303365238919L;
@@ -27,7 +27,7 @@ public abstract class AbstractAuxiliaryC
* @param cacheElement
* @throws IOException
*/
- public void update( ICacheElement cacheElement )
+ public void update( ICacheElement<K, V> cacheElement )
throws IOException
{
updateWithEventLogging( cacheElement );
@@ -39,10 +39,10 @@ public abstract class AbstractAuxiliaryC
* @param cacheElement
* @throws IOException
*/
- protected final void updateWithEventLogging( ICacheElement cacheElement )
+ protected final void updateWithEventLogging( ICacheElement<K, V> cacheElement )
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( cacheElement, ICacheEventLogger.UPDATE_EVENT );
+ ICacheEvent<K> cacheEvent = createICacheEvent( cacheElement, ICacheEventLogger.UPDATE_EVENT );
try
{
processUpdate( cacheElement );
@@ -59,7 +59,7 @@ public abstract class AbstractAuxiliaryC
* @param cacheElement
* @throws IOException
*/
- protected abstract void processUpdate( ICacheElement cacheElement )
+ protected abstract void processUpdate( ICacheElement<K, V> cacheElement )
throws IOException;
/**
@@ -69,7 +69,7 @@ public abstract class AbstractAuxiliaryC
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
- public ICacheElement get( Serializable key )
+ public ICacheElement<K, V> get( K key )
throws IOException
{
return getWithEventLogging( key );
@@ -82,10 +82,10 @@ public abstract class AbstractAuxiliaryC
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
- protected final ICacheElement getWithEventLogging( Serializable key )
+ protected final ICacheElement<K, V> getWithEventLogging( K key )
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.GET_EVENT );
+ ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.GET_EVENT );
try
{
return processGet( key );
@@ -103,18 +103,18 @@ public abstract class AbstractAuxiliaryC
* @return ICacheElement, a wrapper around the key, value, and attributes
* @throws IOException
*/
- protected abstract ICacheElement processGet( Serializable key )
+ protected abstract ICacheElement<K, V> processGet( K key )
throws IOException;
/**
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
- public Map<Serializable, ICacheElement> getMultiple(Set<Serializable> keys)
+ public Map<K, ICacheElement<K, V>> getMultiple(Set<K> keys)
throws IOException
{
return getMultipleWithEventLogging( keys );
@@ -124,14 +124,14 @@ public abstract class AbstractAuxiliaryC
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
- protected final Map<Serializable, ICacheElement> getMultipleWithEventLogging(Set<Serializable> keys )
+ protected final Map<K, ICacheElement<K, V>> getMultipleWithEventLogging(Set<K> keys )
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), (Serializable) keys,
+ ICacheEvent<Serializable> cacheEvent = createICacheEvent( getCacheName(), (Serializable) keys,
ICacheEventLogger.GETMULTIPLE_EVENT );
try
{
@@ -147,11 +147,11 @@ public abstract class AbstractAuxiliaryC
* Implementation of getMultiple.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache for any of these keys
* @throws IOException
*/
- protected abstract Map<Serializable, ICacheElement> processGetMultiple(Set<Serializable> keys)
+ protected abstract Map<K, ICacheElement<K, V>> processGetMultiple(Set<K> keys)
throws IOException;
/**
@@ -164,11 +164,11 @@ public abstract class AbstractAuxiliaryC
* cache will convert * to % and . to _
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
- public Map<Serializable, ICacheElement> getMatching( String pattern )
+ public Map<K, ICacheElement<K, V>> getMatching( String pattern )
throws IOException
{
return getMatchingWithEventLogging( pattern );
@@ -178,14 +178,14 @@ public abstract class AbstractAuxiliaryC
* Gets mmatching items from the cache based on the given pattern.
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
- protected final Map<Serializable, ICacheElement> getMatchingWithEventLogging( String pattern )
+ protected final Map<K, ICacheElement<K, V>> getMatchingWithEventLogging( String pattern )
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), pattern, ICacheEventLogger.GETMATCHING_EVENT );
+ ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), pattern, ICacheEventLogger.GETMATCHING_EVENT );
try
{
return processGetMatching( pattern );
@@ -200,11 +200,11 @@ public abstract class AbstractAuxiliaryC
* Implementation of getMatching.
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
- protected abstract Map<Serializable, ICacheElement> processGetMatching( String pattern )
+ protected abstract Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
throws IOException;
/**
@@ -214,7 +214,7 @@ public abstract class AbstractAuxiliaryC
* @return boolean, whether or not the item was removed
* @throws IOException
*/
- public boolean remove( Serializable key )
+ public boolean remove( K key )
throws IOException
{
return removeWithEventLogging( key );
@@ -227,10 +227,10 @@ public abstract class AbstractAuxiliaryC
* @return boolean, whether or not the item was removed
* @throws IOException
*/
- protected final boolean removeWithEventLogging( Serializable key )
+ protected final boolean removeWithEventLogging( K key )
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.REMOVE_EVENT );
+ ICacheEvent<K> cacheEvent = createICacheEvent( getCacheName(), key, ICacheEventLogger.REMOVE_EVENT );
try
{
return processRemove( key );
@@ -248,7 +248,7 @@ public abstract class AbstractAuxiliaryC
* @return boolean, whether or not the item was removed
* @throws IOException
*/
- protected abstract boolean processRemove( Serializable key )
+ protected abstract boolean processRemove( K key )
throws IOException;
/**
@@ -270,7 +270,7 @@ public abstract class AbstractAuxiliaryC
protected final void removeAllWithEventLogging()
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), "all", ICacheEventLogger.REMOVEALL_EVENT );
+ ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "all", ICacheEventLogger.REMOVEALL_EVENT );
try
{
processRemoveAll();
@@ -309,7 +309,7 @@ public abstract class AbstractAuxiliaryC
protected final void disposeWithEventLogging()
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT );
+ ICacheEvent<String> cacheEvent = createICacheEvent( getCacheName(), "none", ICacheEventLogger.DISPOSE_EVENT );
try
{
processDispose();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCache.java Wed May 30 18:14:43 2012
@@ -34,8 +34,8 @@ import org.apache.jcs.engine.stats.behav
* the type (disk/lateral/remote) of the auxiliary here -- and the existing getCacheType will be
* removed from ICache.
*/
-public interface AuxiliaryCache
- extends ICache
+public interface AuxiliaryCache<K extends Serializable, V extends Serializable>
+ extends ICache<K, V>
{
/**
* Gets the set of keys of objects currently in the group
@@ -43,7 +43,7 @@ public interface AuxiliaryCache
* @return a set of group keys
* @throws IOException
*/
- Set<Serializable> getGroupKeys( String group )
+ Set<K> getGroupKeys( String group )
throws IOException;
/**
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheFactory.java Wed May 30 18:14:43 2012
@@ -6,15 +6,17 @@ package org.apache.jcs.auxiliary;
* copyright ownership. The ASF licenses this file to you 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.
*/
+import java.io.Serializable;
+
import org.apache.jcs.engine.behavior.ICompositeCacheManager;
import org.apache.jcs.engine.behavior.IElementSerializer;
import org.apache.jcs.engine.logging.behavior.ICacheEventLogger;
@@ -31,12 +33,13 @@ public interface AuxiliaryCacheFactory
* @param cacheMgr This allows auxiliaries to reference the manager without assuming that it is
* a singleton. This will allow JCS to be a nonsingleton. Also, it makes it easier to
* test.
- * @param cacheEventLogger
- * @param elementSerializer
+ * @param cacheEventLogger
+ * @param elementSerializer
* @return AuxiliaryCache
*/
- public AuxiliaryCache createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
- ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer );
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> createCache(
+ AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
+ ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer );
/**
* Sets the name attribute of the AuxiliaryCacheFactory object
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/AuxiliaryCacheManager.java Wed May 30 18:14:43 2012
@@ -19,6 +19,8 @@ package org.apache.jcs.auxiliary;
* under the License.
*/
+import java.io.Serializable;
+
import org.apache.jcs.engine.behavior.ICacheType;
/**
@@ -36,7 +38,7 @@ public interface AuxiliaryCacheManager
* @param cacheName
* @return AuxiliaryCache
*/
- public AuxiliaryCache getCache( String cacheName );
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> getCache( String cacheName );
/**
* This allows the cache manager to be plugged into the auxiliary caches,
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java Wed May 30 18:14:43 2012
@@ -24,6 +24,7 @@ import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -58,9 +59,9 @@ import org.apache.jcs.engine.stats.behav
* persistence mechanism, this class destroys the event queue. Should it also destroy purgatory?
* Should it dispose itself?
*/
-public abstract class AbstractDiskCache
- extends AbstractAuxiliaryCacheEventLogging
- implements AuxiliaryCache, Serializable
+public abstract class AbstractDiskCache<K extends Serializable, V extends Serializable>
+ extends AbstractAuxiliaryCacheEventLogging<K, V>
+ implements AuxiliaryCache<K, V>, Serializable
{
/** Don't change. */
private static final long serialVersionUID = 6541664080877628324L;
@@ -79,13 +80,13 @@ public abstract class AbstractDiskCache
* If the elements are pulled into the memory cache while the are still in purgatory, writing to
* disk can be canceled.
*/
- protected Map<Serializable, PurgatoryElement> purgatory = new HashMap<Serializable, PurgatoryElement>();
+ protected Map<K, PurgatoryElement<K, V>> purgatory = new HashMap<K, PurgatoryElement<K, V>>();
/**
* The CacheEventQueue where changes will be queued for asynchronous updating of the persistent
* storage.
*/
- protected ICacheEventQueue cacheEventQueue;
+ protected ICacheEventQueue<K, V> cacheEventQueue;
/**
* Indicates whether the cache is 'alive': initialized, but not yet disposed. Child classes must
@@ -120,7 +121,7 @@ public abstract class AbstractDiskCache
this.cacheName = attr.getCacheName();
// create queue
- CacheEventQueueFactory fact = new CacheEventQueueFactory();
+ CacheEventQueueFactory<K, V> fact = new CacheEventQueueFactory<K, V>();
this.cacheEventQueue = fact.createCacheEventQueue( new MyCacheListener(), CacheInfo.listenerId, cacheName,
diskCacheAttributes.getEventQueuePoolName(),
diskCacheAttributes.getEventQueueType() );
@@ -151,11 +152,11 @@ public abstract class AbstractDiskCache
{
if ( diskCacheAttributes.getMaxPurgatorySize() >= 0 )
{
- purgatory = new LRUMapJCS<Serializable, PurgatoryElement>( diskCacheAttributes.getMaxPurgatorySize() );
+ purgatory = new LRUMapJCS<K, PurgatoryElement<K, V>>( diskCacheAttributes.getMaxPurgatorySize() );
}
else
{
- purgatory = new HashMap<Serializable, PurgatoryElement>();
+ purgatory = new HashMap<K, PurgatoryElement<K, V>>();
}
}
}
@@ -163,11 +164,11 @@ public abstract class AbstractDiskCache
{
if ( diskCacheAttributes.getMaxPurgatorySize() >= 0 )
{
- purgatory = new LRUMapJCS<Serializable, PurgatoryElement>( diskCacheAttributes.getMaxPurgatorySize() );
+ purgatory = new LRUMapJCS<K, PurgatoryElement<K, V>>( diskCacheAttributes.getMaxPurgatorySize() );
}
else
{
- purgatory = new HashMap<Serializable, PurgatoryElement>();
+ purgatory = new HashMap<K, PurgatoryElement<K, V>>();
}
}
}
@@ -191,7 +192,7 @@ public abstract class AbstractDiskCache
* @see org.apache.jcs.engine.behavior.ICache#update
*/
@Override
- public final void update( ICacheElement cacheElement )
+ public final void update( ICacheElement<K, V> cacheElement )
throws IOException
{
if ( log.isDebugEnabled() )
@@ -202,7 +203,7 @@ public abstract class AbstractDiskCache
try
{
// Wrap the CacheElement in a PurgatoryElement
- PurgatoryElement pe = new PurgatoryElement( cacheElement );
+ PurgatoryElement<K, V> pe = new PurgatoryElement<K, V>( cacheElement );
// Indicates the the element is eligible to be spooled to disk,
// this will remain true unless the item is pulled back into
@@ -231,11 +232,11 @@ public abstract class AbstractDiskCache
* it on disk.
* <p>
* @param key
- * @return ICacheElement or null
+ * @return ICacheElement<K, V> or null
* @see AuxiliaryCache#get
*/
@Override
- public final ICacheElement get( Serializable key )
+ public final ICacheElement<K, V> get( K key )
{
// If not alive, always return null.
@@ -248,7 +249,7 @@ public abstract class AbstractDiskCache
return null;
}
- PurgatoryElement pe = null;
+ PurgatoryElement<K, V> pe = null;
synchronized ( purgatory )
{
pe = purgatory.get( key );
@@ -314,30 +315,30 @@ public abstract class AbstractDiskCache
* cache will convert * to % and . to _
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data matching the pattern.
* @throws IOException
*/
@Override
- public Map<Serializable, ICacheElement> getMatching( String pattern )
+ public Map<K, ICacheElement<K, V>> getMatching( String pattern )
throws IOException
{
// Get the keys from purgatory
- Object[] keyArray = null;
+ Set<K> keyArray = null;
// this avoids locking purgatory, but it uses more memory
synchronized ( purgatory )
{
- keyArray = purgatory.keySet().toArray();
+ keyArray = new HashSet<K>(purgatory.keySet());
}
- Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<K> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
// call getMultiple with the set
- Map<Serializable, ICacheElement> result = processGetMultiple( matchingKeys );
+ Map<K, ICacheElement<K, V>> result = processGetMultiple( matchingKeys );
// Get the keys from disk
- Map<Serializable, ICacheElement> diskMatches = doGetMatching( pattern );
+ Map<K, ICacheElement<K, V>> diskMatches = doGetMatching( pattern );
result.putAll( diskMatches );
@@ -348,19 +349,19 @@ public abstract class AbstractDiskCache
* Gets multiple items from the cache based on the given set of keys.
* <p>
* @param keys
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache for any of these keys
*/
@Override
- public Map<Serializable, ICacheElement> processGetMultiple(Set<Serializable> keys)
+ public Map<K, ICacheElement<K, V>> processGetMultiple(Set<K> keys)
{
- Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
+ Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, V>>();
if ( keys != null && !keys.isEmpty() )
{
- for (Serializable key : keys)
+ for (K key : keys)
{
- ICacheElement element = get( key );
+ ICacheElement<K, V> element = get( key );
if ( element != null )
{
@@ -378,7 +379,7 @@ public abstract class AbstractDiskCache
* (non-Javadoc)
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
*/
- public abstract Set<Serializable> getGroupKeys( String groupName );
+ public abstract Set<K> getGroupKeys( String groupName );
/**
* Removes are not queued. A call to remove is immediate.
@@ -389,10 +390,10 @@ public abstract class AbstractDiskCache
* @see org.apache.jcs.engine.behavior.ICache#remove
*/
@Override
- public final boolean remove( Serializable key )
+ public final boolean remove( K key )
throws IOException
{
- PurgatoryElement pe = null;
+ PurgatoryElement<K, V> pe = null;
synchronized ( purgatory )
{
@@ -605,7 +606,7 @@ public abstract class AbstractDiskCache
* parent class.
*/
protected class MyCacheListener
- implements ICacheListener
+ implements ICacheListener<K, V>
{
/** Id of the listener */
private long listenerId = 0;
@@ -640,16 +641,16 @@ public abstract class AbstractDiskCache
* added to the cache event queue, that may not be needed ( they are always
* PurgatoryElements ).
*/
- public void handlePut( ICacheElement element )
+ public void handlePut( ICacheElement<K, V> element )
throws IOException
{
if ( alive )
{
- // If the element is a PurgatoryElement we must check to see
+ // If the element is a PurgatoryElement<K, V> we must check to see
// if it is still spoolable, and remove it from purgatory.
if ( element instanceof PurgatoryElement )
{
- PurgatoryElement pe = (PurgatoryElement) element;
+ PurgatoryElement<K, V> pe = (PurgatoryElement<K, V>) element;
synchronized ( pe.getCacheElement() )
{
@@ -722,7 +723,7 @@ public abstract class AbstractDiskCache
* @throws IOException
* @see ICacheListener#handleRemove
*/
- public void handleRemove( String cacheName, Serializable key )
+ public void handleRemove( String cacheName, K key )
throws IOException
{
if ( alive )
@@ -782,7 +783,7 @@ public abstract class AbstractDiskCache
* @return An object matching key, or null.
* @throws IOException
*/
- protected final ICacheElement doGet( Serializable key )
+ protected final ICacheElement<K, V> doGet( K key )
throws IOException
{
return super.getWithEventLogging( key );
@@ -799,7 +800,7 @@ public abstract class AbstractDiskCache
* @return A map of matches..
* @throws IOException
*/
- protected final Map<Serializable, ICacheElement> doGetMatching( String pattern )
+ protected final Map<K, ICacheElement<K, V>> doGetMatching( String pattern )
throws IOException
{
return super.getMatchingWithEventLogging( pattern );
@@ -815,7 +816,7 @@ public abstract class AbstractDiskCache
* @param cacheElement
* @throws IOException
*/
- protected final void doUpdate( ICacheElement cacheElement )
+ protected final void doUpdate( ICacheElement<K, V> cacheElement )
throws IOException
{
super.updateWithEventLogging( cacheElement );
@@ -832,7 +833,7 @@ public abstract class AbstractDiskCache
* @return whether or no the item was present when removed
* @throws IOException
*/
- protected final boolean doRemove( Serializable key )
+ protected final boolean doRemove( K key )
throws IOException
{
return super.removeWithEventLogging( key );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/PurgatoryElement.java Wed May 30 18:14:43 2012
@@ -30,8 +30,8 @@ import org.apache.jcs.engine.behavior.IE
* Elements are stored in purgatory when they are spooled to the auxilliary cache, but have not yet
* been written to disk.
*/
-public class PurgatoryElement
- implements ICacheElement, Serializable
+public class PurgatoryElement<K extends Serializable, V extends Serializable>
+ implements ICacheElement<K, V>, Serializable
{
/** Don't change */
private static final long serialVersionUID = -8152034342684135628L;
@@ -40,14 +40,14 @@ public class PurgatoryElement
protected boolean spoolable = false;
/** Wrapped cache Element */
- protected ICacheElement cacheElement;
+ protected ICacheElement<K, V> cacheElement;
/**
- * Constructor for the PurgatoryElement object
+ * Constructor for the PurgatoryElement<K, V> object
* <p>
* @param cacheElement CacheElement to wrap.
*/
- public PurgatoryElement( ICacheElement cacheElement )
+ public PurgatoryElement( ICacheElement<K, V> cacheElement )
{
this.cacheElement = cacheElement;
}
@@ -77,7 +77,7 @@ public class PurgatoryElement
* <p>
* @return ICacheElement
*/
- public ICacheElement getCacheElement()
+ public ICacheElement<K, V> getCacheElement()
{
return cacheElement;
}
@@ -97,7 +97,7 @@ public class PurgatoryElement
* @return cacheElement.getKey();
* @see ICacheElement#getKey
*/
- public Serializable getKey()
+ public K getKey()
{
return cacheElement.getKey();
}
@@ -106,7 +106,7 @@ public class PurgatoryElement
* @return cacheElement.getVal();
* @see ICacheElement#getVal
*/
- public Serializable getVal()
+ public V getVal()
{
return cacheElement.getVal();
}
@@ -128,7 +128,7 @@ public class PurgatoryElement
{
cacheElement.setElementAttributes( attr );
}
-
+
/**
* @return debug string
*/
@@ -144,5 +144,5 @@ public class PurgatoryElement
buf.append( " ElementAttributes = " + getElementAttributes() );
buf.append( "]" );
return buf.toString();
- }
+ }
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCache.java Wed May 30 18:14:43 2012
@@ -51,8 +51,8 @@ import org.apache.jcs.engine.stats.behav
* <p>
* @author Aaron Smuts
*/
-public class BlockDiskCache
- extends AbstractDiskCache
+public class BlockDiskCache<K extends Serializable, V extends Serializable>
+ extends AbstractDiskCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 1L;
@@ -76,7 +76,7 @@ public class BlockDiskCache
private final File rootDirectory;
/** Store, loads, and persists the keys */
- private BlockDiskKeyStore keyStore;
+ private BlockDiskKeyStore<K> keyStore;
/**
* Use this lock to synchronize reads and writes to the underlying storage mechanism. We don't
@@ -135,7 +135,7 @@ public class BlockDiskCache
this.dataFile = new BlockDisk( new File( rootDirectory, fileName + ".data" ), getElementSerializer() );
}
- keyStore = new BlockDiskKeyStore( this.blockDiskCacheAttributes, this );
+ keyStore = new BlockDiskKeyStore<K>( this.blockDiskCacheAttributes, this );
boolean alright = verifyDisk();
@@ -176,11 +176,11 @@ public class BlockDiskCache
{
int maxToTest = 100;
int count = 0;
- Iterator<Map.Entry<Serializable, int[]>> it = this.keyStore.entrySet().iterator();
+ Iterator<Map.Entry<K, int[]>> it = this.keyStore.entrySet().iterator();
while ( it.hasNext() && count < maxToTest )
{
count++;
- Map.Entry<Serializable, int[]> entry = it.next();
+ Map.Entry<K, int[]> entry = it.next();
Object data = this.dataFile.read( entry.getValue() );
if ( data == null )
{
@@ -209,20 +209,20 @@ public class BlockDiskCache
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#getGroupKeys(java.lang.String)
*/
@Override
- public Set<Serializable> getGroupKeys( String groupName )
+ public Set<K> getGroupKeys( String groupName )
{
GroupId groupId = new GroupId( cacheName, groupName );
- HashSet<Serializable> keys = new HashSet<Serializable>();
+ HashSet<K> keys = new HashSet<K>();
storageLock.readLock().lock();
try
{
- for ( Serializable key : this.keyStore.keySet())
+ for ( K key : this.keyStore.keySet())
{
- if ( key instanceof GroupAttrName && ( (GroupAttrName) key ).groupId.equals( groupId ) )
+ if ( key instanceof GroupAttrName && ( (GroupAttrName<?>) key ).groupId.equals( groupId ) )
{
- keys.add( (Serializable)( (GroupAttrName) key ).attrName );
+ keys.add( ( (GroupAttrName<K>) key ).attrName );
}
}
}
@@ -238,30 +238,30 @@ public class BlockDiskCache
* Gets matching items from the cache.
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache matching keys
*/
@Override
- public Map<Serializable, ICacheElement> processGetMatching( String pattern )
+ public Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
{
- Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
+ Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, V>>();
- Object[] keyArray = null;
+ Set<K> keyArray = null;
storageLock.readLock().lock();
try
{
- keyArray = this.keyStore.keySet().toArray();
+ keyArray = new HashSet<K>(keyStore.keySet());
}
finally
{
storageLock.readLock().unlock();
}
- Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<K> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
- for (Serializable key : matchingKeys)
+ for (K key : matchingKeys)
{
- ICacheElement element = processGet( key );
+ ICacheElement<K, V> element = processGet( key );
if ( element != null )
{
elements.put( key, element );
@@ -284,7 +284,7 @@ public class BlockDiskCache
}
/**
- * Gets the ICacheElement for the key if it is in the cache. The program flow is as follows:
+ * Gets the ICacheElement<K, V> for the key if it is in the cache. The program flow is as follows:
* <ol>
* <li>Make sure the disk cache is alive.</li> <li>Get a read lock.</li> <li>See if the key is
* in the key store.</li> <li>If we found a key, ask the BlockDisk for the object at the
@@ -296,7 +296,7 @@ public class BlockDiskCache
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doGet(java.io.Serializable)
*/
@Override
- protected ICacheElement processGet( Serializable key )
+ protected ICacheElement<K, V> processGet( K key )
{
if ( !alive )
{
@@ -312,7 +312,7 @@ public class BlockDiskCache
log.debug( logCacheName + "Trying to get from disk: " + key );
}
- ICacheElement object = null;
+ ICacheElement<K, V> object = null;
storageLock.readLock().lock();
try
@@ -320,7 +320,7 @@ public class BlockDiskCache
int[] ded = this.keyStore.get( key );
if ( ded != null )
{
- object = (ICacheElement) this.dataFile.read( ded );
+ object = (ICacheElement<K, V>) this.dataFile.read( ded );
}
}
catch ( IOException ioe )
@@ -352,7 +352,7 @@ public class BlockDiskCache
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doUpdate(org.apache.jcs.engine.behavior.ICacheElement)
*/
@Override
- protected void processUpdate( ICacheElement element )
+ protected void processUpdate( ICacheElement<K, V> element )
{
if ( !alive )
{
@@ -411,7 +411,7 @@ public class BlockDiskCache
* @see org.apache.jcs.auxiliary.disk.AbstractDiskCache#doRemove(java.io.Serializable)
*/
@Override
- protected boolean processRemove( Serializable key )
+ protected boolean processRemove( K key )
{
if ( !alive )
{
@@ -432,12 +432,12 @@ public class BlockDiskCache
if ( key instanceof String && key.toString().endsWith( CacheConstants.NAME_COMPONENT_DELIMITER ) )
{
// remove all keys of the same name group.
- Iterator<Map.Entry<Serializable, int[]>> iter = this.keyStore.entrySet().iterator();
+ Iterator<Map.Entry<K, int[]>> iter = this.keyStore.entrySet().iterator();
while ( iter.hasNext() )
{
- Map.Entry<Serializable, int[]> entry = iter.next();
- Object k = entry.getKey();
+ Map.Entry<K, int[]> entry = iter.next();
+ K k = entry.getKey();
if ( k instanceof String && k.toString().startsWith( key.toString() ) )
{
@@ -449,16 +449,17 @@ public class BlockDiskCache
}
}
}
- else if ( key instanceof GroupId )
+ else if ( key instanceof GroupAttrName && ((GroupAttrName<?>)key).attrName == null )
{
// remove all keys of the same name hierarchy.
- Iterator<Map.Entry<Serializable, int[]>> iter = this.keyStore.entrySet().iterator();
+ Iterator<Map.Entry<K, int[]>> iter = this.keyStore.entrySet().iterator();
while ( iter.hasNext() )
{
- Map.Entry<Serializable, int[]> entry = iter.next();
- Object k = entry.getKey();
+ Map.Entry<K, int[]> entry = iter.next();
+ K k = entry.getKey();
- if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
+ if ( k instanceof GroupAttrName &&
+ ((GroupAttrName<?>)k).groupId.equals(((GroupAttrName<?>)key).groupId))
{
int[] ded = this.keyStore.get( key );
this.dataFile.freeBlocks( ded );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheFactory.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheFactory.java Wed May 30 18:14:43 2012
@@ -19,6 +19,8 @@ package org.apache.jcs.auxiliary.disk.bl
* under the License.
*/
+import java.io.Serializable;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.auxiliary.AuxiliaryCache;
@@ -56,7 +58,7 @@ public class BlockDiskCacheFactory
* @param elementSerializer
* @return AuxiliaryCache
*/
- public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
{
BlockDiskCacheAttributes idca = (BlockDiskCacheAttributes) iaca;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskCacheManager.java Wed May 30 18:14:43 2012
@@ -19,6 +19,7 @@ package org.apache.jcs.auxiliary.disk.bl
* under the License.
*/
+import java.io.Serializable;
import java.util.Hashtable;
import org.apache.commons.logging.Log;
@@ -44,7 +45,7 @@ public class BlockDiskCacheManager
private static BlockDiskCacheManager instance;
/** block disks for a region. */
- private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
+ private final Hashtable<String, AuxiliaryCache<?, ?>> caches = new Hashtable<String, AuxiliaryCache<?, ?>>();
/** Attributes. */
private final BlockDiskCacheAttributes defaultCacheAttributes;
@@ -93,7 +94,7 @@ public class BlockDiskCacheManager
* @param cacheName Name that will be used when creating attributes.
* @return A cache.
*/
- public AuxiliaryCache getCache( String cacheName )
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> getCache( String cacheName )
{
BlockDiskCacheAttributes cacheAttributes = (BlockDiskCacheAttributes) defaultCacheAttributes.copy();
@@ -109,9 +110,9 @@ public class BlockDiskCacheManager
* @param cacheAttributes Attributes the cache should have.
* @return A cache, either from the existing set or newly created.
*/
- public AuxiliaryCache getCache( BlockDiskCacheAttributes cacheAttributes )
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> getCache( BlockDiskCacheAttributes cacheAttributes )
{
- AuxiliaryCache cache = null;
+ AuxiliaryCache<K, V> cache = null;
String cacheName = cacheAttributes.getCacheName();
@@ -122,14 +123,13 @@ public class BlockDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = caches.get( cacheName );
+ cache = (AuxiliaryCache<K, V>) caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
-
if ( cache == null )
{
- cache = new BlockDiskCache( cacheAttributes );
+ cache = new BlockDiskCache<K, V>( cacheAttributes );
cache.setCacheEventLogger( getCacheEventLogger() );
cache.setElementSerializer( getElementSerializer() );
caches.put( cacheName, cache );
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptor.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptor.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskElementDescriptor.java Wed May 30 18:14:43 2012
@@ -32,14 +32,14 @@ import java.io.Serializable;
* <p>
* @author Aaron Smuts
*/
-public class BlockDiskElementDescriptor
+public class BlockDiskElementDescriptor<K extends Serializable>
implements Serializable, Externalizable
{
/** Don't change */
private static final long serialVersionUID = -1400659301208101411L;
/** The key */
- private Serializable key;
+ private K key;
/** The array of block numbers */
private int[] blocks;
@@ -47,7 +47,7 @@ public class BlockDiskElementDescriptor
/**
* @param key The key to set.
*/
- public void setKey( Serializable key )
+ public void setKey( K key )
{
this.key = key;
}
@@ -55,7 +55,7 @@ public class BlockDiskElementDescriptor
/**
* @return Returns the key.
*/
- public Serializable getKey()
+ public K getKey()
{
return key;
}
@@ -109,7 +109,7 @@ public class BlockDiskElementDescriptor
public void readExternal( ObjectInput input )
throws IOException, ClassNotFoundException
{
- this.key = (Serializable) input.readObject();
+ this.key = (K) input.readObject();
this.blocks = (int[]) input.readObject();
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/block/BlockDiskKeyStore.java Wed May 30 18:14:43 2012
@@ -47,7 +47,7 @@ import org.apache.jcs.utils.timing.Elaps
* <p>
* @author Aaron Smuts
*/
-public class BlockDiskKeyStore
+public class BlockDiskKeyStore<K extends Serializable>
{
/** The logger */
protected static final Log log = LogFactory.getLog( BlockDiskKeyStore.class );
@@ -56,7 +56,7 @@ public class BlockDiskKeyStore
private final BlockDiskCacheAttributes blockDiskCacheAttributes;
/** The key to block map */
- private Map<Serializable, int[]> keyHash;
+ private Map<K, int[]> keyHash;
/** The file where we persist the keys */
private final File keyFile;
@@ -71,7 +71,7 @@ public class BlockDiskKeyStore
private final int maxKeySize;
/** we need this so we can communicate free blocks to the data store when keys fall off the LRU */
- protected final BlockDiskCache blockDiskCache;
+ protected final BlockDiskCache<K, ?> blockDiskCache;
/**
* The background key persister, one for all regions.
@@ -84,7 +84,7 @@ public class BlockDiskKeyStore
* @param cacheAttributes
* @param blockDiskCache used for freeing
*/
- public BlockDiskKeyStore( BlockDiskCacheAttributes cacheAttributes, BlockDiskCache blockDiskCache )
+ public BlockDiskKeyStore( BlockDiskCacheAttributes cacheAttributes, BlockDiskCache<K, ?> blockDiskCache )
{
this.blockDiskCacheAttributes = cacheAttributes;
this.logCacheName = "Region [" + this.blockDiskCacheAttributes.getCacheName() + "] ";
@@ -165,9 +165,9 @@ public class BlockDiskKeyStore
try
{
// don't need to synchronize, since the underlying collection makes a copy
- for (Map.Entry<Serializable, int[]> entry : keyHash.entrySet())
+ for (Map.Entry<K, int[]> entry : keyHash.entrySet())
{
- BlockDiskElementDescriptor descriptor = new BlockDiskElementDescriptor();
+ BlockDiskElementDescriptor<K> descriptor = new BlockDiskElementDescriptor<K>();
descriptor.setKey( entry.getKey() );
descriptor.setBlocks( entry.getValue() );
// stream these out in the loop.
@@ -231,7 +231,7 @@ public class BlockDiskKeyStore
else
{
// If no max size, use a plain map for memory and processing efficiency.
- keyHash = new HashMap<Serializable, int[]>();
+ keyHash = new HashMap<K, int[]>();
// keyHash = Collections.synchronizedMap( new HashMap() );
if ( log.isInfoEnabled() )
{
@@ -256,7 +256,7 @@ public class BlockDiskKeyStore
// create a key map to use.
initKeyMap();
- HashMap<Serializable, int[]> keys = new HashMap<Serializable, int[]>();
+ HashMap<K, int[]> keys = new HashMap<K, int[]>();
synchronized (keyFile)
{
@@ -267,7 +267,7 @@ public class BlockDiskKeyStore
{
while ( true )
{
- BlockDiskElementDescriptor descriptor = (BlockDiskElementDescriptor) ois.readObject();
+ BlockDiskElementDescriptor<K> descriptor = (BlockDiskElementDescriptor<K>) ois.readObject();
if ( descriptor != null )
{
keys.put( descriptor.getKey(), descriptor.getBlocks() );
@@ -311,7 +311,7 @@ public class BlockDiskKeyStore
* <p>
* @return entry set.
*/
- public Set<Map.Entry<Serializable, int[]>> entrySet()
+ public Set<Map.Entry<K, int[]>> entrySet()
{
return this.keyHash.entrySet();
}
@@ -321,7 +321,7 @@ public class BlockDiskKeyStore
* <p>
* @return key set.
*/
- public Set<Serializable> keySet()
+ public Set<K> keySet()
{
return this.keyHash.keySet();
}
@@ -342,7 +342,7 @@ public class BlockDiskKeyStore
* @param key
* @return Object
*/
- public int[] get( Object key )
+ public int[] get( K key )
{
return this.keyHash.get( key );
}
@@ -353,7 +353,7 @@ public class BlockDiskKeyStore
* @param key
* @param value
*/
- public void put( Serializable key, int[] value )
+ public void put( K key, int[] value )
{
this.keyHash.put( key, value );
}
@@ -364,7 +364,7 @@ public class BlockDiskKeyStore
* @param key
* @return BlockDiskElementDescriptor if it was present, else null
*/
- public int[] remove( Serializable key )
+ public int[] remove( K key )
{
return this.keyHash.remove( key );
}
@@ -374,7 +374,7 @@ public class BlockDiskKeyStore
* blocks as free.
*/
public class LRUMap
- extends LRUMapJCS<Serializable, int[]>
+ extends LRUMapJCS<K, int[]>
{
/** Don't change */
private static final long serialVersionUID = 4955079991472142198L;
@@ -408,7 +408,7 @@ public class BlockDiskKeyStore
* @param value
*/
@Override
- protected void processRemovedLRU( Serializable key, int[] value )
+ protected void processRemovedLRU( K key, int[] value )
{
blockDiskCache.freeBlocks( value );
if ( log.isDebugEnabled() )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCache.java Wed May 30 18:14:43 2012
@@ -28,8 +28,8 @@ import org.apache.jcs.utils.timing.Sleep
* This is a fairly simple implementation. All the disk writing is handled right here. It's not
* clear that anything more complicated is needed.
*/
-public class FileDiskCache
- extends AbstractDiskCache
+public class FileDiskCache<K extends Serializable, V extends Serializable>
+ extends AbstractDiskCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = 1L;
@@ -108,7 +108,7 @@ public class FileDiskCache
* @param key
* @return the file for the key
*/
- protected File file( Serializable key )
+ protected <KK extends Serializable> File file( KK key )
{
StringBuffer fileNameBuffer = new StringBuffer();
@@ -139,7 +139,7 @@ public class FileDiskCache
* @return Set
*/
@Override
- public Set<Serializable> getGroupKeys(String groupName)
+ public Set<K> getGroupKeys(String groupName)
{
throw new UnsupportedOperationException();
}
@@ -183,7 +183,7 @@ public class FileDiskCache
protected synchronized void processDispose()
throws IOException
{
- ICacheEvent cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
+ ICacheEvent<K> cacheEvent = createICacheEvent( cacheName, (K)"none", ICacheEventLogger.DISPOSE_EVENT );
try
{
if ( !alive )
@@ -215,7 +215,7 @@ public class FileDiskCache
* @throws IOException
*/
@Override
- protected ICacheElement processGet( Serializable key )
+ protected ICacheElement<K, V> processGet( K key )
throws IOException
{
File file = file( key );
@@ -229,7 +229,7 @@ public class FileDiskCache
return null;
}
- ICacheElement element = null;
+ ICacheElement<K, V> element = null;
FileInputStream fis = null;
try
@@ -253,7 +253,7 @@ public class FileDiskCache
throw new IOException( "Could not completely read file " + file.getName() );
}
- element = (ICacheElement) getElementSerializer().deSerialize( bytes );
+ element = getElementSerializer().deSerialize( bytes );
// test that the retrieved object has equal key
if ( element != null && !key.equals( element.getKey() ) )
@@ -293,7 +293,7 @@ public class FileDiskCache
* @throws IOException
*/
@Override
- protected Map<Serializable, ICacheElement> processGetMatching( String pattern )
+ protected Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
throws IOException
{
// TODO get a list of file and return those with matching keys.
@@ -309,7 +309,20 @@ public class FileDiskCache
* @throws IOException
*/
@Override
- protected boolean processRemove( Serializable key )
+ protected boolean processRemove( K key )
+ throws IOException
+ {
+ return _processRemove(key);
+ }
+
+ /**
+ * Removes the file.
+ * <p>
+ * @param key
+ * @return true if the item was removed
+ * @throws IOException
+ */
+ private <T extends Serializable> boolean _processRemove( T key )
throws IOException
{
File file = file( key );
@@ -335,7 +348,7 @@ public class FileDiskCache
String[] fileNames = getDirectory().list();
for ( int i = 0; i < fileNames.length; i++ )
{
- processRemove( fileNames[i] );
+ _processRemove( fileNames[i] );
}
}
@@ -347,7 +360,7 @@ public class FileDiskCache
* @throws IOException
*/
@Override
- protected void processUpdate( ICacheElement element )
+ protected void processUpdate( ICacheElement<K, V> element )
throws IOException
{
removeIfLimitIsSetAndReached();
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheFactory.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheFactory.java Wed May 30 18:14:43 2012
@@ -1,8 +1,9 @@
package org.apache.jcs.auxiliary.disk.file;
+import java.io.Serializable;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.jcs.auxiliary.AuxiliaryCache;
import org.apache.jcs.auxiliary.AuxiliaryCacheAttributes;
import org.apache.jcs.auxiliary.AuxiliaryCacheFactory;
import org.apache.jcs.engine.behavior.ICompositeCacheManager;
@@ -33,8 +34,9 @@ public class FileDiskCacheFactory
* @param elementSerializer the serializer
* @return AuxiliaryCache
*/
- public AuxiliaryCache createCache( AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
- ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
+ public <K extends Serializable, V extends Serializable> FileDiskCache<K, V> createCache(
+ AuxiliaryCacheAttributes attr, ICompositeCacheManager cacheMgr,
+ ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
{
FileDiskCacheAttributes idfca = (FileDiskCacheAttributes) attr;
if ( log.isDebugEnabled() )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/file/FileDiskCacheManager.java Wed May 30 18:14:43 2012
@@ -1,5 +1,6 @@
package org.apache.jcs.auxiliary.disk.file;
+import java.io.Serializable;
import java.util.Hashtable;
import org.apache.commons.logging.Log;
@@ -22,7 +23,8 @@ public class FileDiskCacheManager
private final static Log log = LogFactory.getLog( FileDiskCacheManager.class );
/** Each region has an entry here. */
- private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
+ private final Hashtable<String, AuxiliaryCache<? extends Serializable, ? extends Serializable>> caches =
+ new Hashtable<String, AuxiliaryCache<? extends Serializable, ? extends Serializable>>();
/** User configurable attributes */
private final FileDiskCacheAttributes defaultCacheAttributes;
@@ -48,7 +50,7 @@ public class FileDiskCacheManager
* @param cacheName Name that will be used when creating attributes.
* @return A cache.
*/
- public AuxiliaryCache getCache( String cacheName )
+ public <K extends Serializable, V extends Serializable> FileDiskCache<K, V> getCache( String cacheName )
{
FileDiskCacheAttributes cacheAttributes = (FileDiskCacheAttributes) defaultCacheAttributes.copy();
@@ -64,9 +66,9 @@ public class FileDiskCacheManager
* @param cacheAttributes Attributes the cache should have.
* @return A cache, either from the existing set or newly created.
*/
- public AuxiliaryCache getCache( FileDiskCacheAttributes cacheAttributes )
+ public <K extends Serializable, V extends Serializable> FileDiskCache<K, V> getCache( FileDiskCacheAttributes cacheAttributes )
{
- AuxiliaryCache cache = null;
+ FileDiskCache<K, V> cache = null;
String cacheName = cacheAttributes.getCacheName();
@@ -77,14 +79,14 @@ public class FileDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = caches.get( cacheName );
+ cache = (FileDiskCache<K, V>) caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
if ( cache == null )
{
- cache = new FileDiskCache( cacheAttributes, getElementSerializer() );
+ cache = new FileDiskCache<K, V>( cacheAttributes, getElementSerializer() );
cache.setCacheEventLogger( getCacheEventLogger() );
caches.put( cacheName, cache );
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCache.java Wed May 30 18:14:43 2012
@@ -60,8 +60,8 @@ import org.apache.jcs.utils.timing.Elaps
* stored in memory is configurable. The disk cache tries to recycle spots on disk to limit file
* expansion.
*/
-public class IndexedDiskCache
- extends AbstractDiskCache
+public class IndexedDiskCache<K extends Serializable, V extends Serializable>
+ extends AbstractDiskCache<K, V>
{
/** Don't change */
private static final long serialVersionUID = -265035607729729629L;
@@ -82,7 +82,7 @@ public class IndexedDiskCache
private IndexedDisk keyFile;
/** Map containing the keys and disk offsets. */
- private Map<Serializable, IndexedDiskElementDescriptor> keyHash;
+ private Map<K, IndexedDiskElementDescriptor> keyHash;
/** The maximum number of keys that we will keep in memory. */
private final int maxKeySize;
@@ -325,8 +325,8 @@ public class IndexedDiskCache
// create a key map to use.
initializeKeyMap();
- HashMap<Serializable, IndexedDiskElementDescriptor> keys =
- (HashMap<Serializable, IndexedDiskElementDescriptor>) keyFile.readObject( new IndexedDiskElementDescriptor( 0, (int) keyFile.length()
+ HashMap<K, IndexedDiskElementDescriptor> keys =
+ (HashMap<K, IndexedDiskElementDescriptor>) keyFile.readObject( new IndexedDiskElementDescriptor( 0, (int) keyFile.length()
- IndexedDisk.HEADER_SIZE_BYTES ) );
if ( keys != null )
@@ -380,7 +380,7 @@ public class IndexedDiskCache
{
fileLength = dataFile.length();
- for (Map.Entry<Serializable, IndexedDiskElementDescriptor> e : keyHash.entrySet())
+ for (Map.Entry<K, IndexedDiskElementDescriptor> e : keyHash.entrySet())
{
IndexedDiskElementDescriptor ded = e.getValue();
@@ -464,8 +464,8 @@ public class IndexedDiskCache
keyFile.reset();
- HashMap<Serializable, IndexedDiskElementDescriptor> keys =
- new HashMap<Serializable, IndexedDiskElementDescriptor>();
+ HashMap<K, IndexedDiskElementDescriptor> keys =
+ new HashMap<K, IndexedDiskElementDescriptor>();
keys.putAll( keyHash );
if ( keys.size() > 0 )
@@ -488,10 +488,10 @@ public class IndexedDiskCache
* Update the disk cache. Called from the Queue. Makes sure the Item has not been retrieved from
* purgatory while in queue for disk. Remove items from purgatory when they go to disk.
* <p>
- * @param ce The ICacheElement to put to disk.
+ * @param ce The ICacheElement<K, V> to put to disk.
*/
@Override
- protected void processUpdate( ICacheElement ce )
+ protected void processUpdate( ICacheElement<K, V> ce )
{
if ( !alive )
{
@@ -603,11 +603,11 @@ public class IndexedDiskCache
* Gets the key, then goes to disk to get the object.
* <p>
* @param key
- * @return ICacheElement or null
+ * @return ICacheElement<K, V> or null
* @see AbstractDiskCache#doGet
*/
@Override
- protected ICacheElement processGet( Serializable key )
+ protected ICacheElement<K, V> processGet( K key )
{
if ( !alive )
{
@@ -620,7 +620,7 @@ public class IndexedDiskCache
log.debug( logCacheName + "Trying to get from disk: " + key );
}
- ICacheElement object = null;
+ ICacheElement<K, V> object = null;
try
{
storageLock.readLock().lock();
@@ -654,31 +654,31 @@ public class IndexedDiskCache
* Gets matching items from the cache.
* <p>
* @param pattern
- * @return a map of Serializable key to ICacheElement element, or an empty map if there is no
+ * @return a map of K key to ICacheElement<K, V> element, or an empty map if there is no
* data in cache matching keys
*/
@Override
- public Map<Serializable, ICacheElement> processGetMatching( String pattern )
+ public Map<K, ICacheElement<K, V>> processGetMatching( String pattern )
{
- Map<Serializable, ICacheElement> elements = new HashMap<Serializable, ICacheElement>();
+ Map<K, ICacheElement<K, V>> elements = new HashMap<K, ICacheElement<K, V>>();
try
{
- Object[] keyArray = null;
+ Set<K> keyArray = null;
storageLock.readLock().lock();
try
{
- keyArray = keyHash.keySet().toArray();
+ keyArray = new HashSet<K>(keyHash.keySet());
}
finally
{
storageLock.readLock().unlock();
}
- Set<Serializable> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
+ Set<K> matchingKeys = getKeyMatcher().getMatchingKeysFromArray( pattern, keyArray );
- for (Serializable key : matchingKeys)
+ for (K key : matchingKeys)
{
- ICacheElement element = processGet( key );
+ ICacheElement<K, V> element = processGet( key );
if ( element != null )
{
elements.put( key, element );
@@ -699,10 +699,10 @@ public class IndexedDiskCache
* @return ICacheElement
* @throws IOException
*/
- private ICacheElement readElement( Serializable key )
+ private ICacheElement<K, V> readElement( K key )
throws IOException
{
- ICacheElement object = null;
+ ICacheElement<K, V> object = null;
IndexedDiskElementDescriptor ded = keyHash.get( key );
@@ -714,7 +714,7 @@ public class IndexedDiskCache
}
try
{
- object = (ICacheElement) dataFile.readObject( ded );
+ object = (ICacheElement<K, V>) dataFile.readObject( ded );
// TODO consider checking key equality and throwing if there is a failure
}
catch ( IOException e )
@@ -738,26 +738,22 @@ public class IndexedDiskCache
* @see org.apache.jcs.auxiliary.AuxiliaryCache#getGroupKeys(java.lang.String)
*/
@Override
- public Set<Serializable> getGroupKeys( String groupName )
+ public Set<K> getGroupKeys( String groupName )
{
GroupId groupId = new GroupId( cacheName, groupName );
- HashSet<Serializable> keys = new HashSet<Serializable>();
+ HashSet<K> keys = new HashSet<K>();
try
{
storageLock.readLock().lock();
for (Serializable k : keyHash.keySet())
{
- if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( groupId ) )
+ if ( k instanceof GroupAttrName && ( (GroupAttrName<?>) k ).groupId.equals( groupId ) )
{
- keys.add( (Serializable) ( (GroupAttrName) k ).attrName );
+ keys.add( ( (GroupAttrName<K>) k ).attrName );
}
}
}
- catch ( Exception e )
- {
- log.error( logCacheName + "Failure getting from disk, group = " + groupName, e );
- }
finally
{
storageLock.readLock().unlock();
@@ -774,7 +770,7 @@ public class IndexedDiskCache
* @param key
*/
@Override
- protected boolean processRemove( Serializable key )
+ protected boolean processRemove( K key )
{
if ( !alive )
{
@@ -797,9 +793,9 @@ public class IndexedDiskCache
{
removed = performPartialKeyRemoval( (String) key );
}
- else if ( key instanceof GroupId )
+ else if ( key instanceof GroupAttrName && ((GroupAttrName<?>)key).attrName == null )
{
- removed = performGroupRemoval( (GroupId) key );
+ removed = performGroupRemoval( ((GroupAttrName<?>)key).groupId );
}
else
{
@@ -845,9 +841,9 @@ public class IndexedDiskCache
boolean removed = false;
// remove all keys of the same name hierarchy.
- List<Serializable> itemsToRemove = new LinkedList<Serializable>();
+ List<K> itemsToRemove = new LinkedList<K>();
- for (Serializable k : keyHash.keySet())
+ for (K k : keyHash.keySet())
{
if ( k instanceof String && k.toString().startsWith( key.toString() ) )
{
@@ -856,7 +852,7 @@ public class IndexedDiskCache
}
// remove matches.
- for (Serializable fullKey : itemsToRemove)
+ for (K fullKey : itemsToRemove)
{
// Don't add to recycle bin here
// https://issues.apache.org/jira/browse/JCS-67
@@ -882,19 +878,19 @@ public class IndexedDiskCache
boolean removed = false;
// remove all keys of the same name group.
- List<Serializable> itemsToRemove = new LinkedList<Serializable>();
+ List<K> itemsToRemove = new LinkedList<K>();
// remove all keys of the same name hierarchy.
- for (Serializable k : keyHash.keySet())
+ for (K k : keyHash.keySet())
{
- if ( k instanceof GroupAttrName && ( (GroupAttrName) k ).groupId.equals( key ) )
+ if ( k instanceof GroupAttrName && ( (GroupAttrName<?>) k ).groupId.equals( key ) )
{
itemsToRemove.add( k );
}
}
// remove matches.
- for (Serializable fullKey : itemsToRemove)
+ for (K fullKey : itemsToRemove)
{
// Don't add to recycle bin here
// https://issues.apache.org/jira/browse/JCS-67
@@ -914,7 +910,7 @@ public class IndexedDiskCache
* @param key
* @return true if an item was removed.
*/
- private boolean performSingleKeyRemoval( Serializable key )
+ private boolean performSingleKeyRemoval( K key )
{
boolean removed;
// remove single item.
@@ -935,7 +931,7 @@ public class IndexedDiskCache
@Override
public void processRemoveAll()
{
- ICacheEvent cacheEvent = createICacheEvent( cacheName, "all", ICacheEventLogger.REMOVEALL_EVENT );
+ ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, "all", ICacheEventLogger.REMOVEALL_EVENT );
try
{
reset();
@@ -1030,7 +1026,7 @@ public class IndexedDiskCache
else
{
// If no max size, use a plain map for memory and processing efficiency.
- keyHash = new HashMap<Serializable, IndexedDiskElementDescriptor>();
+ keyHash = new HashMap<K, IndexedDiskElementDescriptor>();
// keyHash = Collections.synchronizedMap( new HashMap() );
if ( log.isInfoEnabled() )
{
@@ -1048,7 +1044,7 @@ public class IndexedDiskCache
@Override
public void processDispose()
{
- ICacheEvent cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
+ ICacheEvent<String> cacheEvent = createICacheEvent( cacheName, "none", ICacheEventLogger.DISPOSE_EVENT );
try
{
Runnable disR = new Runnable()
@@ -1376,10 +1372,10 @@ public class IndexedDiskCache
private IndexedDiskElementDescriptor[] createPositionSortedDescriptorList()
{
IndexedDiskElementDescriptor[] defragList = new IndexedDiskElementDescriptor[keyHash.size()];
- Iterator<Map.Entry<Serializable, IndexedDiskElementDescriptor>> iterator = keyHash.entrySet().iterator();
+ Iterator<Map.Entry<K, IndexedDiskElementDescriptor>> iterator = keyHash.entrySet().iterator();
for ( int i = 0; iterator.hasNext(); i++ )
{
- Map.Entry<Serializable, IndexedDiskElementDescriptor> next = iterator.next();
+ Map.Entry<K, IndexedDiskElementDescriptor> next = iterator.next();
defragList[i] = next.getValue();
}
@@ -1482,7 +1478,7 @@ public class IndexedDiskCache
}
/**
- * For debugging. This dumps the values by defualt.
+ * For debugging. This dumps the values by default.
*/
public void dump()
{
@@ -1500,9 +1496,9 @@ public class IndexedDiskCache
{
log.debug( logCacheName + "[dump] Number of keys: " + keyHash.size() );
- for (Map.Entry<Serializable, IndexedDiskElementDescriptor> e : keyHash.entrySet())
+ for (Map.Entry<K, IndexedDiskElementDescriptor> e : keyHash.entrySet())
{
- Serializable key = e.getKey();
+ K key = e.getKey();
IndexedDiskElementDescriptor ded = e.getValue();
log.debug( logCacheName + "[dump] Disk element, key: " + key + ", pos: " + ded.pos + ", ded.len"
@@ -1700,7 +1696,7 @@ public class IndexedDiskCache
* to the recycle bin.
*/
public class LRUMap
- extends LRUMapJCS<Serializable, IndexedDiskElementDescriptor>
+ extends LRUMapJCS<K, IndexedDiskElementDescriptor>
// implements Serializable
{
/** Don't change */
@@ -1735,7 +1731,7 @@ public class IndexedDiskCache
* @param value
*/
@Override
- protected void processRemovedLRU(Serializable key, IndexedDiskElementDescriptor value )
+ protected void processRemovedLRU(K key, IndexedDiskElementDescriptor value )
{
addToRecycleBin( value );
if ( log.isDebugEnabled() )
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheFactory.java Wed May 30 18:14:43 2012
@@ -19,6 +19,8 @@ package org.apache.jcs.auxiliary.disk.in
* under the License.
*/
+import java.io.Serializable;
+
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.jcs.auxiliary.AuxiliaryCache;
@@ -52,11 +54,11 @@ public class IndexedDiskCacheFactory
* @param cacheMgr This allows auxiliaries to reference the manager without assuming that it is
* a singleton. This will allow JCS to be a non-singleton. Also, it makes it easier to
* test.
- * @param cacheEventLogger
- * @param elementSerializer
+ * @param cacheEventLogger
+ * @param elementSerializer
* @return AuxiliaryCache
*/
- public AuxiliaryCache createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
+ public <K extends Serializable, V extends Serializable> AuxiliaryCache<K, V> createCache( AuxiliaryCacheAttributes iaca, ICompositeCacheManager cacheMgr,
ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
{
IndexedDiskCacheAttributes idca = (IndexedDiskCacheAttributes) iaca;
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheManager.java Wed May 30 18:14:43 2012
@@ -19,6 +19,7 @@ package org.apache.jcs.auxiliary.disk.in
* under the License.
*/
+import java.io.Serializable;
import java.util.Hashtable;
import org.apache.commons.logging.Log;
@@ -44,7 +45,8 @@ public class IndexedDiskCacheManager
private static IndexedDiskCacheManager instance;
/** Each region has an entry here. */
- private final Hashtable<String, AuxiliaryCache> caches = new Hashtable<String, AuxiliaryCache>();
+ private final Hashtable<String, AuxiliaryCache<? extends Serializable, ? extends Serializable>> caches =
+ new Hashtable<String, AuxiliaryCache<? extends Serializable, ? extends Serializable>>();
/** User configurable attributes */
private final IndexedDiskCacheAttributes defaultCacheAttributes;
@@ -57,7 +59,7 @@ public class IndexedDiskCacheManager
* @param elementSerializer
*/
private IndexedDiskCacheManager( IndexedDiskCacheAttributes defaultCacheAttributes,
- ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
+ ICacheEventLogger cacheEventLogger, IElementSerializer elementSerializer )
{
this.defaultCacheAttributes = defaultCacheAttributes;
setElementSerializer( elementSerializer );
@@ -93,7 +95,7 @@ public class IndexedDiskCacheManager
* @param cacheName Name that will be used when creating attributes.
* @return A cache.
*/
- public AuxiliaryCache getCache( String cacheName )
+ public <K extends Serializable, V extends Serializable> IndexedDiskCache<K, V> getCache( String cacheName )
{
IndexedDiskCacheAttributes cacheAttributes = (IndexedDiskCacheAttributes) defaultCacheAttributes.copy();
@@ -109,9 +111,9 @@ public class IndexedDiskCacheManager
* @param cacheAttributes Attributes the cache should have.
* @return A cache, either from the existing set or newly created.
*/
- public AuxiliaryCache getCache( IndexedDiskCacheAttributes cacheAttributes )
+ public <K extends Serializable, V extends Serializable> IndexedDiskCache<K, V> getCache( IndexedDiskCacheAttributes cacheAttributes )
{
- AuxiliaryCache cache = null;
+ IndexedDiskCache<K, V> cache = null;
String cacheName = cacheAttributes.getCacheName();
@@ -122,14 +124,14 @@ public class IndexedDiskCacheManager
// Try to load the cache from the set that have already been
// created. This only looks at the name attribute.
- cache = caches.get( cacheName );
+ cache = (IndexedDiskCache<K, V>) caches.get( cacheName );
// If it was not found, create a new one using the supplied
// attributes
if ( cache == null )
{
- cache = new IndexedDiskCache( cacheAttributes, getElementSerializer() );
+ cache = new IndexedDiskCache<K, V>( cacheAttributes, getElementSerializer() );
cache.setCacheEventLogger( getCacheEventLogger() );
caches.put( cacheName, cache );
}
Modified: commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskDumper.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskDumper.java?rev=1344374&r1=1344373&r2=1344374&view=diff
==============================================================================
--- commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskDumper.java (original)
+++ commons/proper/jcs/trunk/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskDumper.java Wed May 30 18:14:43 2012
@@ -1,5 +1,7 @@
package org.apache.jcs.auxiliary.disk.indexed;
+import java.io.Serializable;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -47,7 +49,7 @@ public class IndexedDiskDumper
attr.setCacheName( args[0] );
attr.setDiskPath( args[0] );
- final IndexedDiskCache dc = new IndexedDiskCache( attr );
+ IndexedDiskCache<Serializable, Serializable> dc = new IndexedDiskCache<Serializable, Serializable>( attr );
dc.dump( true );
System.exit( 0 );
}