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 2020/06/14 17:19:05 UTC
[commons-jcs] branch master updated: Fix PMD and Findbugs findings
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
The following commit(s) were added to refs/heads/master by this push:
new 58a9c01 Fix PMD and Findbugs findings
58a9c01 is described below
commit 58a9c019103554d8fd30d03104a3ba9991226b63
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Sun Jun 14 19:18:59 2020 +0200
Fix PMD and Findbugs findings
---
.../auxiliary/AbstractAuxiliaryCacheFactory.java | 2 -
.../jcs3/auxiliary/disk/AbstractDiskCache.java | 2 +-
.../jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java | 5 +-
.../auxiliary/disk/jdbc/JDBCDiskCacheFactory.java | 2 +-
.../disk/jdbc/dsfactory/JndiDataSourceFactory.java | 2 +-
.../auxiliary/disk/jdbc/mysql/MySQLDiskCache.java | 6 +-
.../disk/jdbc/mysql/MySQLDiskCacheFactory.java | 2 +-
.../disk/jdbc/mysql/MySQLTableOptimizer.java | 89 ++++++++++++----------
.../jcs3/auxiliary/remote/RemoteCacheFactory.java | 2 +-
.../remote/RemoteCacheFailoverRunner.java | 5 +-
.../behavior/ICommonRemoteCacheAttributes.java | 2 +-
.../auxiliary/remote/server/RemoteCacheServer.java | 10 +--
.../remote/server/RemoteCacheServerAttributes.java | 4 +-
.../remote/server/RemoteCacheServerFactory.java | 8 +-
.../remote/server/RemoteCacheStartupServlet.java | 14 +++-
.../apache/commons/jcs3/engine/CacheElement.java | 21 +++++
.../jcs3/engine/control/CompositeCache.java | 6 +-
.../jcs3/io/ObjectInputStreamClassLoaderAware.java | 2 +-
.../jcs3/utils/threadpool/DaemonThreadFactory.java | 4 +-
19 files changed, 110 insertions(+), 78 deletions(-)
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/AbstractAuxiliaryCacheFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/AbstractAuxiliaryCacheFactory.java
index 1399e4f..5702ffe 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/AbstractAuxiliaryCacheFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/AbstractAuxiliaryCacheFactory.java
@@ -19,8 +19,6 @@ package org.apache.commons.jcs3.auxiliary;
* under the License.
*/
-import org.apache.commons.jcs3.auxiliary.AuxiliaryCacheFactory;
-
/**
* Base class for auxiliary cache factories.
*/
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/AbstractDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/AbstractDiskCache.java
index d4c9308..138c2a7 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/AbstractDiskCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/AbstractDiskCache.java
@@ -522,7 +522,7 @@ public abstract class AbstractDiskCache<K, V>
@Override
public CacheStatus getStatus()
{
- return ( alive ? CacheStatus.ALIVE : CacheStatus.DISPOSED );
+ return alive ? CacheStatus.ALIVE : CacheStatus.DISPOSED;
}
/**
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java
index 720fdf2..8fbb830 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCache.java
@@ -38,7 +38,6 @@ import org.apache.commons.jcs3.auxiliary.AuxiliaryCacheAttributes;
import org.apache.commons.jcs3.auxiliary.disk.AbstractDiskCache;
import org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory.DataSourceFactory;
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
-import org.apache.commons.jcs3.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs3.engine.behavior.IElementSerializer;
import org.apache.commons.jcs3.engine.logging.behavior.ICacheEvent;
import org.apache.commons.jcs3.engine.logging.behavior.ICacheEventLogger;
@@ -116,10 +115,8 @@ public class JDBCDiskCache<K, V>
* @param cattr the configuration object for this cache
* @param dsFactory the DataSourceFactory for this cache
* @param tableState an object to track table operations
- * @param compositeCacheManager the global cache manager
*/
- public JDBCDiskCache( JDBCDiskCacheAttributes cattr, DataSourceFactory dsFactory, TableState tableState,
- ICompositeCacheManager compositeCacheManager )
+ public JDBCDiskCache(JDBCDiskCacheAttributes cattr, DataSourceFactory dsFactory, TableState tableState)
{
super( cattr );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCacheFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCacheFactory.java
index 0e99d24..99ab390 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCacheFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/JDBCDiskCacheFactory.java
@@ -95,7 +95,7 @@ public class JDBCDiskCacheFactory
TableState tableState = getTableState( cattr.getTableName() );
DataSourceFactory dsFactory = getDataSourceFactory(cattr, compositeCacheManager.getConfigurationProperties());
- JDBCDiskCache<K, V> cache = new JDBCDiskCache<>( cattr, dsFactory, tableState, compositeCacheManager );
+ JDBCDiskCache<K, V> cache = new JDBCDiskCache<>(cattr, dsFactory, tableState);
cache.setCacheEventLogger( cacheEventLogger );
cache.setElementSerializer( elementSerializer );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/dsfactory/JndiDataSourceFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/dsfactory/JndiDataSourceFactory.java
index 7d33e01..6a689c3 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/dsfactory/JndiDataSourceFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/dsfactory/JndiDataSourceFactory.java
@@ -91,7 +91,7 @@ public class JndiDataSourceFactory implements DataSourceFactory
{
synchronized (ctx)
{
- ds = ((DataSource) ctx.lookup(path));
+ ds = (DataSource) ctx.lookup(path);
}
lastLookup = time;
}
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
index 59764dc..2030881 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCache.java
@@ -26,7 +26,6 @@ import org.apache.commons.jcs3.auxiliary.disk.jdbc.JDBCDiskCache;
import org.apache.commons.jcs3.auxiliary.disk.jdbc.TableState;
import org.apache.commons.jcs3.auxiliary.disk.jdbc.dsfactory.DataSourceFactory;
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
-import org.apache.commons.jcs3.engine.behavior.ICompositeCacheManager;
import org.apache.commons.jcs3.log.Log;
import org.apache.commons.jcs3.log.LogManager;
@@ -54,13 +53,12 @@ public class MySQLDiskCache<K, V>
* @param attributes the configuration object for this cache
* @param dsFactory the DataSourceFactory for this cache
* @param tableState an object to track table operations
- * @param compositeCacheManager the global cache manager
* @throws SQLException if the pool access could not be set up
*/
public MySQLDiskCache( MySQLDiskCacheAttributes attributes, DataSourceFactory dsFactory,
- TableState tableState, ICompositeCacheManager compositeCacheManager ) throws SQLException
+ TableState tableState) throws SQLException
{
- super( attributes, dsFactory, tableState, compositeCacheManager );
+ super( attributes, dsFactory, tableState);
mySQLDiskCacheAttributes = attributes;
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
index da702ad..f3da717 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLDiskCacheFactory.java
@@ -68,7 +68,7 @@ public class MySQLDiskCacheFactory
TableState tableState = getTableState( cattr.getTableName() );
DataSourceFactory dsFactory = getDataSourceFactory(cattr, compositeCacheManager.getConfigurationProperties());
- MySQLDiskCache<K, V> cache = new MySQLDiskCache<>( cattr, dsFactory, tableState, compositeCacheManager );
+ MySQLDiskCache<K, V> cache = new MySQLDiskCache<>( cattr, dsFactory, tableState);
cache.setCacheEventLogger( cacheEventLogger );
cache.setElementSerializer( elementSerializer );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
index dc83d54..352f6ba 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/jdbc/mysql/MySQLTableOptimizer.java
@@ -134,34 +134,34 @@ public class MySQLTableOptimizer
try (Connection con = dataSource.getConnection())
{
// TEST
-
try (Statement sStatement = con.createStatement())
{
- ResultSet rs = sStatement.executeQuery( "optimize table " + this.getTableName() );
-
- // first row is error, then status
- // if there is only one row in the result set, everything
- // should be fine.
- // This may be mysql version specific.
- if ( rs.next() )
+ try (ResultSet rs = sStatement.executeQuery( "optimize table " + this.getTableName() ))
{
- String status = rs.getString( "Msg_type" );
- String message = rs.getString( "Msg_text" );
+ // first row is error, then status
+ // if there is only one row in the result set, everything
+ // should be fine.
+ // This may be mysql version specific.
+ if ( rs.next() )
+ {
+ String status = rs.getString( "Msg_type" );
+ String message = rs.getString( "Msg_text" );
- log.info( "Message Type: {0}", status );
- log.info( "Message: {0}", message );
+ log.info( "Message Type: {0}", status );
+ log.info( "Message: {0}", message );
- if ( "error".equals( status ) )
- {
- log.warn( "Optimization was in error. Will attempt "
- + "to repair the table. Message: {0}", message);
+ if ( "error".equals( status ) )
+ {
+ log.warn( "Optimization was in error. Will attempt "
+ + "to repair the table. Message: {0}", message);
- // try to repair the table.
- success = repairTable( sStatement );
- }
- else
- {
- success = true;
+ // try to repair the table.
+ success = repairTable( sStatement );
+ }
+ else
+ {
+ success = true;
+ }
}
}
@@ -203,16 +203,20 @@ public class MySQLTableOptimizer
protected String getTableStatus( Statement sStatement )
throws SQLException
{
- ResultSet statusResultSet = sStatement.executeQuery( "show table status" );
StringBuilder statusString = new StringBuilder();
- int numColumns = statusResultSet.getMetaData().getColumnCount();
- while ( statusResultSet.next() )
+ try (ResultSet statusResultSet = sStatement.executeQuery( "show table status" ))
{
- statusString.append( "\n" );
- for ( int i = 1; i <= numColumns; i++ )
+ int numColumns = statusResultSet.getMetaData().getColumnCount();
+ while ( statusResultSet.next() )
{
- statusString.append( statusResultSet.getMetaData().getColumnLabel( i ) + " ["
- + statusResultSet.getString( i ) + "] | " );
+ statusString.append( "\n" );
+ for ( int i = 1; i <= numColumns; i++ )
+ {
+ statusString.append(statusResultSet.getMetaData().getColumnLabel(i))
+ .append(" [")
+ .append(statusResultSet.getString(i))
+ .append("] | ");
+ }
}
}
return statusString.toString();
@@ -234,23 +238,28 @@ public class MySQLTableOptimizer
boolean success = false;
// if( message != null && message.indexOf( ) )
- ResultSet repairResult = sStatement.executeQuery( "repair table " + this.getTableName() );
StringBuilder repairString = new StringBuilder();
- int numColumns = repairResult.getMetaData().getColumnCount();
- while ( repairResult.next() )
+ try (ResultSet repairResult = sStatement.executeQuery( "repair table " + this.getTableName()))
{
- for ( int i = 1; i <= numColumns; i++ )
+ int numColumns = repairResult.getMetaData().getColumnCount();
+ while ( repairResult.next() )
{
- repairString.append( repairResult.getMetaData().getColumnLabel( i ) + " [" + repairResult.getString( i )
- + "] | " );
- }
+ for ( int i = 1; i <= numColumns; i++ )
+ {
+ repairString.append(repairResult.getMetaData().getColumnLabel(i))
+ .append(" [")
+ .append(repairResult.getString(i))
+ .append("] | ");
+ }
- String message = repairResult.getString( "Msg_text" );
- if ( "OK".equals( message ) )
- {
- success = true;
+ String message = repairResult.getString( "Msg_text" );
+ if ( "OK".equals( message ) )
+ {
+ success = true;
+ }
}
}
+
log.info("{0}", repairString);
if ( !success )
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
index cbf76d9..46b5c67 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFactory.java
@@ -117,7 +117,7 @@ public class RemoteCacheFactory
// add a listener if there are none, need to tell rca what
// number it is at
- if ( ( !primaryDefined && fCnt == 1 ) || noWaits.size() <= 0 )
+ if (!primaryDefined && fCnt == 1 || noWaits.size() <= 0)
{
RemoteCacheNoWait<K,V> ic = rcm.getCache( rca );
noWaits.add( ic );
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java
index 909bf6b..c1fe592 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/RemoteCacheFailoverRunner.java
@@ -173,11 +173,10 @@ public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonit
log.debug( "starting at failover i = {0}", i );
// try them one at a time until successful
- for ( ; i.hasNext() && !allright.get();)
+ while (i.hasNext() && !allright.get())
{
RemoteLocation server = i.next();
- log.debug( "Trying server [{1}] at failover index i = {1}",
- server, i );
+ log.debug( "Trying server [{0}] at failover index i = {1}", server, i );
RemoteCacheAttributes rca = (RemoteCacheAttributes) rca0.clone();
rca.setRemoteLocation(server);
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/behavior/ICommonRemoteCacheAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/behavior/ICommonRemoteCacheAttributes.java
index be29370..edb9ced 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/behavior/ICommonRemoteCacheAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/behavior/ICommonRemoteCacheAttributes.java
@@ -94,7 +94,7 @@ public interface ICommonRemoteCacheAttributes
* <p>
* @return The remote location value
*/
- public RemoteLocation getRemoteLocation();
+ RemoteLocation getRemoteLocation();
/**
* Gets the clusterServers attribute of the IRemoteCacheAttributes object
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
index fb7f5a4..2b5b92d 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServer.java
@@ -314,7 +314,7 @@ public class RemoteCacheServer<K, V>
// UPDATE LOCALS IF A REQUEST COMES FROM A CLUSTER
// IF LOCAL CLUSTER CONSISTENCY IS CONFIGURED
- if ( !fromCluster || ( fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency() ) )
+ if (!fromCluster || fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency())
{
ICacheEventQueue<K, V>[] qlist = getEventQList( cacheDesc, requesterId );
log.debug( "qlist.length = {0}", qlist.length );
@@ -843,7 +843,7 @@ public class RemoteCacheServer<K, V>
// UPDATE LOCALS IF A REQUEST COMES FROM A CLUSTER
// IF LOCAL CLUSTER CONSISTENCY IS CONFIGURED
- if ( !fromCluster || ( fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency() ) )
+ if (!fromCluster || fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency())
{
ICacheEventQueue<K, V>[] qlist = getEventQList( cacheDesc, requesterId );
@@ -928,13 +928,13 @@ public class RemoteCacheServer<K, V>
}
// update registered listeners
- if ( !fromCluster || ( fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency() ) )
+ if (!fromCluster || fromCluster && remoteCacheServerAttributes.isLocalClusterConsistency())
{
ICacheEventQueue<K, V>[] qlist = getEventQList( cacheDesc, requesterId );
- for ( int i = 0; i < qlist.length; i++ )
+ for (ICacheEventQueue<K, V> q : qlist)
{
- qlist[i].addRemoveAllEvent();
+ q.addRemoveAllEvent();
}
}
}
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
index b890d7c..6d9c8f0 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerAttributes.java
@@ -42,13 +42,13 @@ public class RemoteCacheServerAttributes
private String configFileName = "";
/** Should we start the registry */
- private final boolean DEFAULT_START_REGISTRY = true;
+ private final static boolean DEFAULT_START_REGISTRY = true;
/** Should we start the registry */
private boolean startRegistry = DEFAULT_START_REGISTRY;
/** Should we try to keep the registry alive */
- private final boolean DEFAULT_USE_REGISTRY_KEEP_ALIVE = true;
+ private final static boolean DEFAULT_USE_REGISTRY_KEEP_ALIVE = true;
/** Should we try to keep the registry alive */
private boolean useRegistryKeepAlive = DEFAULT_USE_REGISTRY_KEEP_ALIVE;
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
index 9a1c85f..02789a2 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheServerFactory.java
@@ -20,6 +20,7 @@ package org.apache.commons.jcs3.auxiliary.remote.server;
*/
import java.io.IOException;
+import java.net.InetAddress;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
@@ -436,15 +437,16 @@ public class RemoteCacheServerFactory
}
// startup.
- String host = prop.getProperty( "registry.host" );
+ String hostName = prop.getProperty( "registry.host" );
+ InetAddress host = InetAddress.getByName(hostName);
- if ( host == null || host.trim().equals( "" ) || host.trim().equals( "localhost" ) )
+ if (host.isLoopbackAddress())
{
log.debug( "main> creating registry on the localhost" );
RemoteUtils.createRegistry( port );
}
log.debug( "main> starting up RemoteCacheServer" );
- startup( host, port, prop);
+ startup( host.getHostName(), port, prop);
log.debug( "main> done" );
}
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheStartupServlet.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheStartupServlet.java
index d9966ae..8dbb1e5 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheStartupServlet.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/server/RemoteCacheStartupServlet.java
@@ -21,6 +21,7 @@ package org.apache.commons.jcs3.auxiliary.remote.server;
import java.io.IOException;
import java.io.OutputStream;
+import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.charset.StandardCharsets;
import java.util.Properties;
@@ -119,10 +120,17 @@ public class RemoteCacheStartupServlet
log.debug("registryHost = [{0}]", registryHost);
- if ("localhost".equals(registryHost) || "127.0.0.1".equals(registryHost))
+ try
+ {
+ if (InetAddress.getByName(registryHost).isLoopbackAddress())
+ {
+ log.warn("The local address [{0}] is a loopback address. Other machines must "
+ + "be able to use the address to reach this server.", registryHost);
+ }
+ }
+ catch (UnknownHostException e)
{
- log.warn("The local address [{0}] is INVALID. Other machines must "
- + "be able to use the address to reach this server.", registryHost);
+ throw new ServletException("Could not resolve registry host " + registryHost, e);
}
try
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElement.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElement.java
index 9d64993..ab37c6e 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElement.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheElement.java
@@ -1,5 +1,7 @@
package org.apache.commons.jcs3.engine;
+import java.util.Objects;
+
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -138,6 +140,25 @@ public class CacheElement<K, V>
}
/**
+ * @param obj other object
+ * @return true if this object key equals the key of obj
+ */
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (!(obj instanceof CacheElement))
+ {
+ return false;
+ }
+ CacheElement<?,?> other = (CacheElement<?,?>) obj;
+ return Objects.equals(key, other.key);
+ }
+
+ /**
* @return a hash of the key only
*/
@Override
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
index 75e51a1..e1de16c 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/control/CompositeCache.java
@@ -40,9 +40,9 @@ import org.apache.commons.jcs3.engine.CacheStatus;
import org.apache.commons.jcs3.engine.behavior.ICache;
import org.apache.commons.jcs3.engine.behavior.ICacheElement;
import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes;
+import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern;
import org.apache.commons.jcs3.engine.behavior.IElementAttributes;
import org.apache.commons.jcs3.engine.behavior.IRequireScheduler;
-import org.apache.commons.jcs3.engine.behavior.ICompositeCacheAttributes.DiskUsagePattern;
import org.apache.commons.jcs3.engine.control.event.ElementEvent;
import org.apache.commons.jcs3.engine.control.event.behavior.ElementEventType;
import org.apache.commons.jcs3.engine.control.event.behavior.IElementEvent;
@@ -1219,7 +1219,7 @@ public class CompositeCache<K, V>
// - The auxiliary is not alive
// - The auxiliary is remote and the invocation was remote
if (aux == null || aux.getStatus() != CacheStatus.ALIVE
- || (fromRemote && aux.getCacheType() == CacheType.REMOTE_CACHE))
+ || fromRemote && aux.getCacheType() == CacheType.REMOTE_CACHE)
{
log.info("In DISPOSE, [{0}] SKIPPING auxiliary [{1}] fromRemote [{2}]",
() -> this.cacheAttr.getCacheName(), () -> aux.getCacheName(),
@@ -1515,7 +1515,7 @@ public class CompositeCache<K, V>
// If you have a 0 size memory cache, then the last access will
// not get updated.
// you will need to set the idle time to -1.
- if ((idleTime != -1) && (timestamp - lastAccessTime) > idleTime * timeFactorForMilliseconds)
+ if (idleTime != -1 && timestamp - lastAccessTime > idleTime * timeFactorForMilliseconds)
{
log.debug("Exceeded maxIdle: {0}", () -> element.getKey());
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
index 757024b..d1d0802 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/io/ObjectInputStreamClassLoaderAware.java
@@ -67,7 +67,7 @@ public class ObjectInputStreamClassLoaderAware extends ObjectInputStream {
}
protected boolean isBlacklisted(final String name) {
- return (whitelist != null && !contains(whitelist, name)) || contains(blacklist, name);
+ return whitelist != null && !contains(whitelist, name) || contains(blacklist, name);
}
public final String check(final String name) {
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/threadpool/DaemonThreadFactory.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/threadpool/DaemonThreadFactory.java
index c559bee..dcb0fac 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/threadpool/DaemonThreadFactory.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/threadpool/DaemonThreadFactory.java
@@ -30,7 +30,7 @@ public class DaemonThreadFactory
implements ThreadFactory
{
private final String prefix;
- private final boolean threadIsDaemon = true;
+ private final static boolean THREAD_IS_DAEMON = true;
private int threadPriority = Thread.NORM_PRIORITY;
/**
@@ -67,7 +67,7 @@ public class DaemonThreadFactory
Thread t = new Thread( runner );
String oldName = t.getName();
t.setName( prefix + oldName );
- t.setDaemon(threadIsDaemon);
+ t.setDaemon(THREAD_IS_DAEMON);
t.setPriority(threadPriority);
return t;
}