Author: painter
Date: Fri May 21 15:04:52 2021
New Revision: 1890075
URL: http://svn.apache.org/viewvc?rev=1890075&view=rev
Log:
Code cleanup to reduce PMD errors
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/CachedObject.java
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/GlobalCacheService.java
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/RefreshableCachedObject.java
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/DefaultGlobalCacheService.java
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/JCSCacheService.java
turbine/fulcrum/trunk/cache/src/test/org/apache/fulcrum/cache/CacheTest.java
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/CachedObject.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/CachedObject.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/CachedObject.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/CachedObject.java
Fri May 21 15:04:52 2021
@@ -54,47 +54,47 @@ public class CachedObject<T> implements
private T contents = null;
/** Default age (30 minutes). */
- private long defaultage = 1800000;
+ private final long defaultAge = 1_800_000;
- /** When created. * */
+ /** When the object is created. */
protected long created = 0;
- /** When it expires. * */
+ /** When the object should expire. */
private long expires = 0;
/** Is this object stale/expired? */
- private AtomicBoolean stale = new AtomicBoolean();
+ private final AtomicBoolean stale = new AtomicBoolean();
/**
* Constructor; sets the object to expire in the default time (30 minutes).
*
- * @param o
+ * @param object
* The object you want to cache.
*/
- public CachedObject(T o)
+ public CachedObject(T object)
{
- this(o, DEFAULT);
+ this(object, DEFAULT);
}
/**
* Constructor.
*
- * @param o
+ * @param object
* The object to cache.
* @param expires
* How long before the object expires, in ms, e.g. 1000 = 1
* second.
*/
- public CachedObject(T o, long expires)
+ public CachedObject(T object, long expires)
{
if (expires == DEFAULT)
{
- this.expires = this.defaultage;
+ this.expires = this.defaultAge;
} else {
this.expires = expires;
}
- this.contents = o;
+ this.contents = object;
this.created = System.currentTimeMillis();
}
@@ -139,7 +139,7 @@ public class CachedObject<T> implements
{
if (expires == DEFAULT)
{
- this.expires = this.defaultage;
+ this.expires = this.defaultAge;
}
else
{
@@ -165,16 +165,7 @@ public class CachedObject<T> implements
{
this.stale.set( stale );
}
-
- /**
- * Get the stale status for the object.
- *
- * @return Whether the object is stale or not.
- */
- public boolean getStale()
- {
- return this.stale.get();
- }
+
/**
* Is the object stale?
@@ -183,12 +174,12 @@ public class CachedObject<T> implements
*/
public boolean isStale()
{
- if (this.expires == FOREVER)
+ boolean currentState = false;
+ if (this.expires != FOREVER)
{
- return false;
+ setStale((System.currentTimeMillis() - this.created) >
this.expires);
+ currentState = this.stale.get();
}
-
- setStale((System.currentTimeMillis() - this.created) > this.expires);
- return getStale();
+ return currentState;
}
}
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/GlobalCacheService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/GlobalCacheService.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/GlobalCacheService.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/GlobalCacheService.java
Fri May 21 15:04:52 2021
@@ -26,7 +26,7 @@ import java.util.List;
* GlobalCacheService interface.
*
* @author <a href="mailto:[email protected]">Dave Bryson</a>
- * @author <a href="mailto:[email protected]">Peter Courcoux</a>
+ * @author <a href="mailto:[email protected]">Peter
CourefreshableCachedObjectux</a>
* @version $Id$
*/
public interface GlobalCacheService
@@ -38,32 +38,32 @@ public interface GlobalCacheService
* Gets a cached object given its id (a String).
*
* @param <T> type of object to return
- * @param id
+ * @param objectId
* The String id for the object.
* @return A CachedObject.
* @throws ObjectExpiredException
* if the object has expired in the cache.
*/
- <T> CachedObject<T> getObject(String id) throws ObjectExpiredException;
+ <T> CachedObject<T> getObject(String objectId) throws
ObjectExpiredException;
/**
* Adds an object to the cache.
*
* @param <T> type of object to add
- * @param id
+ * @param objectId
* The String id for the object.
- * @param o
+ * @param object
* The object to add to the cache.
*/
- <T> void addObject(String id, CachedObject<T> o);
+ <T> void addObject(String objectId, CachedObject<T> object);
/**
* Removes an object from the cache.
*
- * @param id
+ * @param objectId
* The String id for the object.
*/
- void removeObject(String id);
+ void removeObject(String objectId);
/**
* Returns a copy of keys to objects in the cache as a list.
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/RefreshableCachedObject.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/RefreshableCachedObject.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/RefreshableCachedObject.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/RefreshableCachedObject.java
Fri May 21 15:04:52 2021
@@ -47,37 +47,37 @@ public class RefreshableCachedObject<T e
* How long to wait before removing an untouched object from the cache.
* Negative numbers mean never remove (the default).
*/
- private long timeToLive = -1;
+ private transient long timeToLive = -1;
/**
* The last time the Object was accessed from the cache.
*/
- private long lastAccess;
+ private transient long lastAccess;
/**
* Constructor; sets the object to expire in the default time (30 minutes).
*
- * @param o
+ * @param object
* The object you want to cache.
*/
- public RefreshableCachedObject(T o)
+ public RefreshableCachedObject(T object)
{
- super(o);
+ super(object);
this.lastAccess = System.currentTimeMillis();
}
/**
* Constructor.
*
- * @param o
+ * @param object
* The object to cache.
* @param expires
* How long before the object expires, in ms, e.g. 1000 = 1
* second.
*/
- public RefreshableCachedObject(T o, long expires)
+ public RefreshableCachedObject(T object, long expires)
{
- super(o, expires);
+ super(object, expires);
this.lastAccess = System.currentTimeMillis();
}
@@ -118,19 +118,12 @@ public class RefreshableCachedObject<T e
*/
public synchronized boolean isUntouched()
{
- if (this.timeToLive < 0)
- {
- return false;
- }
-
+ boolean untouched = false;
if (this.lastAccess + this.timeToLive < System.currentTimeMillis())
{
- return true;
- }
- else
- {
- return false;
+ untouched = true;
}
+ return untouched;
}
/**
@@ -138,11 +131,11 @@ public class RefreshableCachedObject<T e
*/
public void refresh()
{
- Refreshable r = getContents();
+ final Refreshable refreshable = getContents();
synchronized (this)
{
this.created = System.currentTimeMillis();
- r.refresh();
+ refreshable.refresh();
}
}
}
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/DefaultGlobalCacheService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/DefaultGlobalCacheService.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/DefaultGlobalCacheService.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/DefaultGlobalCacheService.java
Fri May 21 15:04:52 2021
@@ -52,7 +52,7 @@ import org.apache.fulcrum.cache.Refresha
* @author <a href="mailto:[email protected]">John Thorhauer</a>
* @author <a href="mailto:[email protected]">Henning P. Schmiedehausen</a>
* @author <a href="mailto:[email protected]">Eric Pugh</a>
- * @author <a href="mailto:[email protected]">Peter Courcoux</a>
+ * @author <a href="mailto:[email protected]">Peter
CourefreshableCachedObjectux</a>
* @version $Id$
*/
public class DefaultGlobalCacheService extends AbstractLogEnabled implements
@@ -80,24 +80,24 @@ public class DefaultGlobalCacheService e
*/
public static final long DEFAULT_CACHE_CHECK_FREQUENCY = 5000; // 5 seconds
- /** The cache. * */
- protected ConcurrentHashMap<String, CachedObject<?>> cache = null;
+ /** The cache. */
+ protected transient ConcurrentHashMap<String, CachedObject<?>> cache =
null;
/**
* cacheCheckFrequency (default - 5 seconds)
*/
- private long cacheCheckFrequency;
+ private transient long cacheCheckFrequency;
/**
* cacheInitialSize (default - 20)
*/
- private int cacheInitialSize;
+ private transient int cacheInitialSize;
/** thread for removing stale items from the cache */
- private Thread housekeeping;
+ private transient Thread houseKeepingThread;
/** flag to stop the housekeeping thread when the component is disposed. */
- private boolean continueThread;
+ private transient boolean continueThread;
/**
* Get the Cache Check Frequency in milliseconds
@@ -114,7 +114,7 @@ public class DefaultGlobalCacheService e
* RefreshableCachedObject will be refreshed if it is expired and not
* untouched.
*
- * @param id
+ * @param objectId
* The key of the stored object.
* @return The object from the cache.
* @throws ObjectExpiredException
@@ -122,27 +122,27 @@ public class DefaultGlobalCacheService e
* expired.
*/
@Override
- public <T> CachedObject<T> getObject(String id) throws
ObjectExpiredException
+ public <T> CachedObject<T> getObject(String objectId) throws
ObjectExpiredException
{
@SuppressWarnings("unchecked")
- CachedObject<T> obj = (CachedObject<T>) this.cache.get(id);
- if (obj == null)
+ final CachedObject<T> cachedObject = (CachedObject<T>)
this.cache.get(objectId);
+ if (cachedObject == null)
{
// Not in the cache.
throw new ObjectExpiredException();
}
- if (obj.isStale())
+ if (cachedObject.isStale())
{
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>)
obj;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableCachedObj =
(RefreshableCachedObject<?>) cachedObject;
+ if (refreshableCachedObj.isUntouched())
{
throw new ObjectExpiredException();
}
// Refresh Object
- rco.refresh();
- if (rco.isStale())
+ refreshableCachedObj.refresh();
+ if (refreshableCachedObj.isStale())
{
throw new ObjectExpiredException();
}
@@ -153,45 +153,45 @@ public class DefaultGlobalCacheService e
throw new ObjectExpiredException();
}
}
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
// notify it that it's being accessed.
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>) obj;
- rco.touch();
+ RefreshableCachedObject<?> refreshableCachedObj =
(RefreshableCachedObject<?>) cachedObject;
+ refreshableCachedObj.touch();
}
- return obj;
+ return cachedObject;
}
/**
* Adds an object to the cache.
*
- * @param id
+ * @param objectId
* The key to store the object by.
- * @param o
+ * @param object
* The object to cache.
*/
@Override
- public <T> void addObject(String id, CachedObject<T> o)
+ public <T> void addObject(String objectId, CachedObject<T> object)
{
// If the cache already contains the key, remove it and add
// the fresh one.
- if (this.cache.containsKey(id))
+ if (this.cache.containsKey(objectId))
{
- this.cache.remove(id);
+ this.cache.remove(objectId);
}
- this.cache.put(id, o);
+ this.cache.put(objectId, object);
}
/**
* Removes an object from the cache.
*
- * @param id
+ * @param objectId
* The String id for the object.
*/
@Override
- public void removeObject(String id)
+ public void removeObject(String objectId)
{
- this.cache.remove(id);
+ this.cache.remove(objectId);
}
/**
@@ -205,12 +205,12 @@ public class DefaultGlobalCacheService e
@Override
public List<String> getKeys()
{
- ArrayList<String> keys = new ArrayList<String>(this.cache.size());
+ ArrayList<String> keys = new ArrayList<>(this.cache.size());
for (String key : this.cache.keySet())
{
try
{
- /* CachedObject obj = */getObject(key);
+ getObject(key);
}
catch (ObjectExpiredException oee)
{
@@ -230,20 +230,24 @@ public class DefaultGlobalCacheService e
@Override
public List<CachedObject<?>> getCachedObjects()
{
- ArrayList<CachedObject<?>> objects = new
ArrayList<CachedObject<?>>(this.cache.size());
+ final ArrayList<CachedObject<?>> objects = new
ArrayList<>(this.cache.size());
for (String key : this.cache.keySet())
{
- CachedObject<?> obj = null;
+ CachedObject<?> cachedObject = null;
try
{
- obj = getObject(key);
+ // only add non-null objects
+ cachedObject = getObject(key);
+ if ( cachedObject != null )
+ {
+ objects.add(cachedObject);
+ }
}
catch (ObjectExpiredException oee)
{
// this is OK we just do not want this object
continue;
}
- objects.add(obj);
}
return objects;
}
@@ -280,26 +284,26 @@ public class DefaultGlobalCacheService e
*/
public void clearCache()
{
- List<String> refreshThese = new ArrayList<String>(20);
+ List<String> refreshThese = new ArrayList<>(20);
// Sync on this object so that other threads do not
// change the Hashtable while enumerating over it.
for (String key : this.cache.keySet())
{
- CachedObject<?> co = this.cache.get(key);
- if (co instanceof RefreshableCachedObject)
+ final CachedObject<?> cachedObject = this.cache.get(key);
+ if (cachedObject instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>)
co;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableObject =
(RefreshableCachedObject<?>) cachedObject;
+ if (refreshableObject.isUntouched())
{
this.cache.remove(key);
}
- else if (rco.isStale())
+ else if (refreshableObject.isStale())
{
// to prolong holding the lock on this object
refreshThese.add(key);
}
}
- else if (co.isStale())
+ else if (cachedObject.isStale())
{
this.cache.remove(key);
}
@@ -307,9 +311,9 @@ public class DefaultGlobalCacheService e
for (String key : refreshThese)
{
- CachedObject<?> co = this.cache.get(key);
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>) co;
- rco.refresh();
+ CachedObject<?> cachedObject = this.cache.get(key);
+ RefreshableCachedObject<?> refreshableCachedObject =
(RefreshableCachedObject<?>) cachedObject;
+ refreshableCachedObject.refresh();
}
}
@@ -341,8 +345,7 @@ public class DefaultGlobalCacheService e
// magic number (2 bytes) and version number (2 bytes) are
// both written to the stream before the object
//
- int objectsize = baos.toByteArray().length - 4;
- return objectsize;
+ return baos.toByteArray().length - 4;
}
/**
@@ -373,16 +376,16 @@ public class DefaultGlobalCacheService e
@Override
public void initialize() throws Exception
{
- this.cache = new ConcurrentHashMap<String,
CachedObject<?>>(this.cacheInitialSize);
+ this.cache = new ConcurrentHashMap<>(this.cacheInitialSize);
// Start housekeeping thread.
this.continueThread = true;
- this.housekeeping = new Thread(this);
+ this.houseKeepingThread = new Thread(this);
// Indicate that this is a system thread. JVM will quit only when
// there are no more active user threads. Settings threads spawned
// internally by Turbine as daemons allows commandline applications
// using Turbine to terminate in an orderly manner.
- this.housekeeping.setDaemon(true);
- this.housekeeping.start();
+ this.houseKeepingThread.setDaemon(true);
+ this.houseKeepingThread.start();
}
/**
@@ -394,7 +397,7 @@ public class DefaultGlobalCacheService e
synchronized (this)
{
this.continueThread = false;
- notify();
+ notifyAll();
}
}
}
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/EHCacheService.java
Fri May 21 15:04:52 2021
@@ -153,18 +153,18 @@ public class EHCacheService extends Abst
* @see
org.apache.fulcrum.cache.GlobalCacheService#addObject(java.lang.String,
org.apache.fulcrum.cache.CachedObject)
*/
@Override
- public <T> void addObject(String id, CachedObject<T> o)
+ public <T> void addObject(String objectId, CachedObject<T> object)
{
- Element cacheElement = new Element(id, o);
+ Element cacheElement = new Element(objectId, object);
- if (o instanceof RefreshableCachedObject)
+ if (object instanceof RefreshableCachedObject)
{
cacheElement.setEternal(true);
}
else
{
cacheElement.setEternal(false);
- cacheElement.setTimeToLive((int)(o.getExpires() + 500) / 1000);
+ cacheElement.setTimeToLive((int)(object.getExpires() + 500) /
1000);
}
this.cache.put(cacheElement);
@@ -203,7 +203,8 @@ public class EHCacheService extends Abst
/**
* @see org.apache.fulcrum.cache.GlobalCacheService#getCacheSize()
*/
- @Override
+ @SuppressWarnings("deprecation")
+ @Override
public int getCacheSize() throws IOException
{
return (int)this.cache.calculateInMemorySize();
@@ -233,9 +234,9 @@ public class EHCacheService extends Abst
* @see
org.apache.fulcrum.cache.GlobalCacheService#getObject(java.lang.String)
*/
@Override
- public <T> CachedObject<T> getObject(String id) throws
ObjectExpiredException
+ public <T> CachedObject<T> getObject(String objectId) throws
ObjectExpiredException
{
- Element cachedElement = this.cache.get(id);
+ Element cachedElement = this.cache.get(objectId);
if (cachedElement == null)
{
@@ -244,54 +245,54 @@ public class EHCacheService extends Abst
}
@SuppressWarnings("unchecked")
- CachedObject<T> obj = (CachedObject<T>)cachedElement.getObjectValue();
+ CachedObject<T> cachedObject =
(CachedObject<T>)cachedElement.getObjectValue();
- if (obj.isStale())
+ if (cachedObject.isStale())
{
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>)
obj;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableCachedObject =
(RefreshableCachedObject<?>) cachedObject;
+ if (refreshableCachedObject.isUntouched())
{
// Do not refresh an object that has exceeded TimeToLive
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
// Refresh Object
- rco.refresh();
- if (rco.isStale())
+ refreshableCachedObject.refresh();
+ if (refreshableCachedObject.isStale())
{
// Object is Expired, remove it from cache.
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
}
else
{
// Expired.
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
}
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
// notify it that it's being accessed.
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>) obj;
- rco.touch();
+ RefreshableCachedObject<?> refreshableCachedObject =
(RefreshableCachedObject<?>) cachedObject;
+ refreshableCachedObject.touch();
}
- return obj;
+ return cachedObject;
}
/**
* @see
org.apache.fulcrum.cache.GlobalCacheService#removeObject(java.lang.String)
*/
@Override
- public void removeObject(String id)
+ public void removeObject(String objectId)
{
- this.cache.remove(id);
+ this.cache.remove(objectId);
}
/**
@@ -327,18 +328,18 @@ public class EHCacheService extends Abst
continue;
}
- Object o = cachedElement.getObjectValue();
+ Object object = cachedElement.getObjectValue();
- if (o instanceof RefreshableCachedObject)
+ if (object instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco =
(RefreshableCachedObject<?>) o;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableObject =
(RefreshableCachedObject<?>) object;
+ if (refreshableObject.isUntouched())
{
this.cache.remove(key);
}
- else if (rco.isStale())
+ else if (refreshableObject.isStale())
{
- rco.refresh();
+ refreshableObject.refresh();
}
}
}
Modified:
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/JCSCacheService.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/JCSCacheService.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/JCSCacheService.java
(original)
+++
turbine/fulcrum/trunk/cache/src/java/org/apache/fulcrum/cache/impl/JCSCacheService.java
Fri May 21 15:04:52 2021
@@ -150,54 +150,54 @@ public class JCSCacheService extends Abs
* @see
org.apache.fulcrum.cache.GlobalCacheService#getObject(java.lang.String)
*/
@Override
- public <T> CachedObject<T> getObject(String id) throws
ObjectExpiredException
+ public <T> CachedObject<T> getObject(String objectId) throws
ObjectExpiredException
{
@SuppressWarnings("unchecked")
- CachedObject<T> obj =
(CachedObject<T>)this.cacheManager.getFromGroup(id, group);
+ CachedObject<T> cachedObject =
(CachedObject<T>)this.cacheManager.getFromGroup(objectId, group);
- if (obj == null)
+ if (cachedObject == null)
{
// Not in the cache.
throw new ObjectExpiredException();
}
- if (obj.isStale())
+ if (cachedObject.isStale())
{
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>)
obj;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableObject =
(RefreshableCachedObject<?>) cachedObject;
+ if (refreshableObject.isUntouched())
{
// Do not refresh an object that has exceeded TimeToLive
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
// Refresh Object
- rco.refresh();
- if (rco.isStale())
+ refreshableObject.refresh();
+ if (refreshableObject.isStale())
{
// Object is Expired, remove it from cache.
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
}
else
{
// Expired.
- removeObject(id);
+ removeObject(objectId);
throw new ObjectExpiredException();
}
}
- if (obj instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
// notify it that it's being accessed.
- RefreshableCachedObject<?> rco = (RefreshableCachedObject<?>) obj;
- rco.touch();
+ RefreshableCachedObject<?> refreshableCachedObject =
(RefreshableCachedObject<?>) cachedObject;
+ refreshableCachedObject.touch();
}
- return obj;
+ return cachedObject;
}
/**
@@ -205,22 +205,22 @@ public class JCSCacheService extends Abs
* org.apache.fulcrum.cache.CachedObject)
*/
@Override
- public <T> void addObject(String id, CachedObject<T> o)
+ public <T> void addObject(String objectId, CachedObject<T> cachedObject)
{
try
{
- if (!(o.getContents() instanceof Serializable))
+ if (!(cachedObject.getContents() instanceof Serializable))
{
getLogger()
.warn(
"Object with id ["
- + id
+ + objectId
+ "] is not serializable. Expect
problems with auxiliary caches.");
}
ElementAttributes attrib = (ElementAttributes)
this.cacheManager.getDefaultElementAttributes();
- if (o instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
attrib.setIsEternal(true);
}
@@ -228,19 +228,19 @@ public class JCSCacheService extends Abs
{
attrib.setIsEternal(false);
// expires in millis, maxlife in seconds
- double tmp0 = ((double) (o.getExpires() + 500)) / 1000;
+ double tmp0 = ((double) (cachedObject.getExpires() + 500)) /
1000;
getLogger().debug( "setting maxlife seconds (minimum 1sec)
from expiry + 0.5s: " + (int)tmp0 );
- attrib.setMaxLife( (tmp0 > 0 ? (int) Math.floor( tmp0 ) : 1 )
);
+ attrib.setMaxLife( tmp0 > 0 ? (int) Math.floor( tmp0 ) : 1 );
}
attrib.setLastAccessTimeNow();
attrib.setCreateTime();
- this.cacheManager.putInGroup(id, group, o, attrib);
+ this.cacheManager.putInGroup(objectId, group, cachedObject,
attrib);
}
catch (CacheException e)
{
- getLogger().error("Could not add object " + id + " to cache", e);
+ getLogger().error("Could not add object " + objectId + " to
cache", e);
}
}
@@ -248,9 +248,9 @@ public class JCSCacheService extends Abs
* @see
org.apache.fulcrum.cache.GlobalCacheService#removeObject(java.lang.String)
*/
@Override
- public void removeObject(String id)
+ public void removeObject(String objectId)
{
- this.cacheManager.removeFromGroup(id, group);
+ this.cacheManager.removeFromGroup(objectId, group);
}
/**
@@ -259,8 +259,7 @@ public class JCSCacheService extends Abs
@Override
public List<String> getKeys()
{
- ArrayList<String> keys = new ArrayList<String>();
-
+ ArrayList<String> keys = new ArrayList<>();
keys.addAll(this.cacheManager.getGroupKeys(group));
return keys;
}
@@ -271,14 +270,13 @@ public class JCSCacheService extends Abs
@Override
public List<CachedObject<?>> getCachedObjects()
{
- ArrayList<CachedObject<?>> values = new ArrayList<CachedObject<?>>();
-
+ ArrayList<CachedObject<?>> values = new ArrayList<>();
for (String key : this.cacheManager.getGroupKeys(group))
{
- CachedObject<?> o = this.cacheManager.getFromGroup(key, group);
- if (o != null)
+ CachedObject<?> cachedObject = this.cacheManager.getFromGroup(key,
group);
+ if (cachedObject != null)
{
- values.add(o);
+ values.add(cachedObject);
}
}
@@ -310,23 +308,23 @@ public class JCSCacheService extends Abs
for (String key : this.cacheManager.getGroupKeys(group))
{
- CachedObject<?> o = this.cacheManager.getFromGroup(key, group);
- if (o == null)
+ CachedObject<?> cachedObject =
this.cacheManager.getFromGroup(key, group);
+ if (cachedObject == null)
{
removeObject(key);
}
else
{
- if (o instanceof RefreshableCachedObject)
+ if (cachedObject instanceof RefreshableCachedObject)
{
- RefreshableCachedObject<?> rco =
(RefreshableCachedObject<?>) o;
- if (rco.isUntouched())
+ RefreshableCachedObject<?> refreshableObject =
(RefreshableCachedObject<?>) cachedObject;
+ if (refreshableObject.isUntouched())
{
this.cacheManager.removeFromGroup(key, group);
}
- else if (rco.isStale())
+ else if (refreshableObject.isStale())
{
- rco.refresh();
+ refreshableObject.refresh();
}
}
}
@@ -357,8 +355,7 @@ public class JCSCacheService extends Abs
// magic number (2 bytes) and version number (2 bytes) are
// both written to the stream before the object
//
- int objectsize = baos.toByteArray().length - 4 * keys.size();
- return objectsize;
+ return baos.toByteArray().length - 4 * keys.size();
}
/**
Modified:
turbine/fulcrum/trunk/cache/src/test/org/apache/fulcrum/cache/CacheTest.java
URL:
http://svn.apache.org/viewvc/turbine/fulcrum/trunk/cache/src/test/org/apache/fulcrum/cache/CacheTest.java?rev=1890075&r1=1890074&r2=1890075&view=diff
==============================================================================
---
turbine/fulcrum/trunk/cache/src/test/org/apache/fulcrum/cache/CacheTest.java
(original)
+++
turbine/fulcrum/trunk/cache/src/test/org/apache/fulcrum/cache/CacheTest.java
Fri May 21 15:04:52 2021
@@ -45,7 +45,7 @@ import org.junit.jupiter.api.Test;
*
* @author <a href="[email protected]">Paul Spencer</a>
* @author <a href="[email protected]">Eric Pugh</a>
- * @author <a href="mailto:[email protected]">Peter Courcoux</a>
+ * @author <a href="mailto:[email protected]">Peter
CourefreshableCachedObjectux</a>
* @version $Id$
*/
public class CacheTest extends BaseUnit5Test
@@ -106,7 +106,7 @@ public class CacheTest extends BaseUnit5
/**
* Simple test that verify an object can be created and deleted.
*
- * @throws Exception
+ * @throws Exception if unable to add object
*/
@Test
public void testSimpleAddGetCacheObject() throws Exception
@@ -156,7 +156,7 @@ public class CacheTest extends BaseUnit5
/**
* Simple test that adds, retrieves, and deletes 2 object.
*
- * @throws Exception
+ * @throws Exception if unable to add and retrieve objects
*/
@Test
public void test2ObjectAddGetCachedObject() throws Exception
@@ -215,7 +215,7 @@ public class CacheTest extends BaseUnit5
* Verify that an object will throw the ObjectExpiredException when it now
* longer exists in cache.
*
- * @throws Exception
+ * @throws Exception if object is not expired
*/
@Test
public void testObjectExpiration() throws Exception
@@ -271,7 +271,7 @@ public class CacheTest extends BaseUnit5
*
* This test can take server minutes.
*
- * @throws Exception
+ * @throws Exception if flushing the cache fails
*/
@Test
public void testCacheFlush() throws Exception
@@ -300,7 +300,7 @@ public class CacheTest extends BaseUnit5
/**
* Verify the Cache count is correct.
*
- * @throws Exception
+ * @throws Exception if the cache count does not match expected value
*/
@Test
public void testObjectCount() throws Exception
@@ -343,7 +343,7 @@ public class CacheTest extends BaseUnit5
*
* This test can take several minutes.
*
- * @throws Exception
+ * @throws Exception if object is not a refreshable object
*/
@Tag("LongRunning")
@Test
@@ -438,7 +438,7 @@ public class CacheTest extends BaseUnit5
*
* This test can take several minutes.
*
- * @throws Exception
+ * @throws Exception if object is not deleted
*/
@Tag("LongRunning")
@Test