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 2021/11/21 16:49:40 UTC
[commons-jcs] 02/03: Merge with master
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
commit 6e46ad96d1087d7adb625cd98f42cee1c1ac3e8a
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Sun Nov 21 17:48:54 2021 +0100
Merge with master
---
.github/workflows/maven.yml | 16 ++---
.../auxiliary/disk/block/BlockDiskKeyStore.java | 2 +-
.../auxiliary/disk/indexed/IndexedDiskCache.java | 5 --
.../disk/jdbc/mysql/MySQLDiskCacheFactory.java | 8 +--
.../remote/CommonRemoteCacheAttributes.java | 6 +-
.../remote/RemoteCacheFailoverRunner.java | 6 +-
.../remote/server/RemoteCacheStartupServlet.java | 9 +--
.../apache/commons/jcs3/engine/CacheListeners.java | 22 ++-----
.../apache/commons/jcs3/log/MessageFormatter.java | 2 +-
.../commons/jcs3/utils/config/OptionConverter.java | 17 ++---
.../commons/jcs3/utils/net/HostNameUtil.java | 75 ++++++++++------------
.../commons/jcs3/jcache/JCSCachingManager.java | 4 +-
12 files changed, 69 insertions(+), 103 deletions(-)
diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml
index 928ebd5..41becb5 100644
--- a/.github/workflows/maven.yml
+++ b/.github/workflows/maven.yml
@@ -25,15 +25,15 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
- java: [ 8, 11, 16 ]
+ java: [ 8, 11, 17 ]
experimental: [false]
- include:
- - java: 17-ea
- os: ubuntu-latest
- experimental: true
- - java: 17-ea
- os: windows-latest
- experimental: true
+# include:
+# - java: 18-ea
+# os: ubuntu-latest
+# experimental: true
+# - java: 18-ea
+# os: windows-latest
+# experimental: true
fail-fast: false
steps:
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java
index cc9928c..5379835 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/block/BlockDiskKeyStore.java
@@ -596,7 +596,7 @@ public class BlockDiskKeyStore<K>
}
boolean ok = true;
if (!log.isTraceEnabled()) {
- return ok;
+ return true;
}
for (final Entry<Integer, Set<K>> e : blockAllocationMap.entrySet())
{
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java
index 3d4d030..69dd6ea 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/disk/indexed/IndexedDiskCache.java
@@ -733,11 +733,6 @@ public class IndexedDiskCache<K, V> extends AbstractDiskCache<K, V>
storageLock.writeLock().unlock();
}
- if (reset)
- {
- reset();
- }
-
// this increments the remove count.
// there is no reason to call this if an item was not removed.
if (removed)
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 c778d2b..2bbcde3 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
@@ -101,12 +101,10 @@ public class MySQLDiskCacheFactory
// loop through the dates.
try
{
+ // canĀ“t be null, otherwise ScheduleParser.createDatesForSchedule will throw ParseException
final Date[] dates = ScheduleParser.createDatesForSchedule( attributes.getOptimizationSchedule() );
- if ( dates != null )
- {
- for (final Date date : dates) {
- this.scheduleOptimization( date, optimizer );
- }
+ for (final Date date : dates) {
+ this.scheduleOptimization( date, optimizer );
}
}
catch ( final ParseException e )
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/CommonRemoteCacheAttributes.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/CommonRemoteCacheAttributes.java
index f85bf71..c81a1ec 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/CommonRemoteCacheAttributes.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/auxiliary/remote/CommonRemoteCacheAttributes.java
@@ -82,11 +82,7 @@ public class CommonRemoteCacheAttributes
@Override
public void setRemoteTypeName( final String s )
{
- final RemoteType rt = RemoteType.valueOf(s);
- if (rt != null)
- {
- this.remoteType = rt;
- }
+ this.remoteType = RemoteType.valueOf(s);
}
/**
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 a88b6a5..38c5f86 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
@@ -118,8 +118,7 @@ public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonit
{
log.info( "Failover index is <= 0, meaning we are not connected to a failover server." );
}
- else if ( failoverIndex > 0 )
- {
+ else {
log.info( "Failover index is > 0, meaning we are connected to a failover server." );
}
// log if we are allright or not.
@@ -339,8 +338,7 @@ public class RemoteCacheFailoverRunner<K, V> extends AbstractAuxiliaryCacheMonit
return true;
}
}
- else if ( fidx < 0 )
- {
+ else {
// this should never happen
log.warn( "Failover index is less than 0, this shouldn't happen" );
}
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 21d44bf..b45fe4f 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
@@ -232,12 +232,9 @@ public class RemoteCacheStartupServlet
try
{
props = RemoteUtils.loadProps(propsFileName);
- if (props != null)
- {
- registryHost = props.getProperty("registry.host", registryHost);
- final String portS = props.getProperty("registry.port", String.valueOf(registryPort));
- setRegistryPort(portS);
- }
+ registryHost = props.getProperty("registry.host", registryHost);
+ final String portS = props.getProperty("registry.port", String.valueOf(registryPort));
+ setRegistryPort(portS);
}
catch (final IOException e)
{
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheListeners.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheListeners.java
index 2b7563d..789f279 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheListeners.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/engine/CacheListeners.java
@@ -58,22 +58,12 @@ public class CacheListeners<K, V>
{
final StringBuilder buffer = new StringBuilder();
buffer.append( "\n CacheListeners" );
- if ( cache != null )
- {
- buffer.append( "\n Region = " + cache.getCacheName() );
- }
- if ( eventQMap != null )
- {
- buffer.append( "\n Event Queue Map " );
- buffer.append( "\n size = " + eventQMap.size() );
- eventQMap.forEach((key, value)
- -> buffer.append( "\n Entry: key: ").append(key)
- .append(", value: ").append(value));
- }
- else
- {
- buffer.append( "\n No Listeners. " );
- }
+ buffer.append( "\n Region = " + cache.getCacheName() );
+ buffer.append( "\n Event Queue Map " );
+ buffer.append( "\n size = " + eventQMap.size() );
+ eventQMap.forEach((key, value)
+ -> buffer.append( "\n Entry: key: ").append(key)
+ .append(", value: ").append(value));
return buffer.toString();
}
}
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/MessageFormatter.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/MessageFormatter.java
index ef94d45..4be7ad1 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/MessageFormatter.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/log/MessageFormatter.java
@@ -68,7 +68,7 @@ public class MessageFormatter
.map(Supplier::get)
.toArray();
- final int length = parameters == null ? 0 : parameters.length;
+ final int length = parameters.length;
if (length > 0 && parameters[length - 1] instanceof Throwable)
{
this.throwable = (Throwable) parameters[length - 1];
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
index 1f3b44b..29179b0 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/config/OptionConverter.java
@@ -253,17 +253,14 @@ public class OptionConverter
multiplier = 1024 * 1024 * 1024;
s = s.substring( 0, index );
}
- if ( s != null )
+ try
{
- try
- {
- return Long.parseLong(s) * multiplier;
- }
- catch ( final NumberFormatException e )
- {
- log.error( "[{0}] is not in proper int form.", s);
- log.error( "[{0}] not in expected format", value, e );
- }
+ return Long.parseLong(s) * multiplier;
+ }
+ catch ( final NumberFormatException e )
+ {
+ log.error( "[{0}] is not in proper int form.", s);
+ log.error( "[{0}] not in expected format", value, e );
}
return defaultValue;
}
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java
index ee6882a..f06cab3 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs3/utils/net/HostNameUtil.java
@@ -124,37 +124,34 @@ public class HostNameUtil
InetAddress candidateAddress = null;
// Iterate all NICs (network interface cards)...
final Enumeration<NetworkInterface> ifaces = NetworkInterface.getNetworkInterfaces();
- if ( ifaces != null )
+ while ( ifaces.hasMoreElements() )
{
- while ( ifaces.hasMoreElements() )
- {
- final NetworkInterface iface = ifaces.nextElement();
+ final NetworkInterface iface = ifaces.nextElement();
- // Skip loopback interfaces
- if (iface.isLoopback() || !iface.isUp())
- {
- continue;
- }
+ // Skip loopback interfaces
+ if (iface.isLoopback() || !iface.isUp())
+ {
+ continue;
+ }
- // Iterate all IP addresses assigned to each card...
- for ( final Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); )
+ // Iterate all IP addresses assigned to each card...
+ for ( final Enumeration<InetAddress> inetAddrs = iface.getInetAddresses(); inetAddrs.hasMoreElements(); )
+ {
+ final InetAddress inetAddr = inetAddrs.nextElement();
+ if ( !inetAddr.isLoopbackAddress() )
{
- final InetAddress inetAddr = inetAddrs.nextElement();
- if ( !inetAddr.isLoopbackAddress() )
+ if (inetAddr.isSiteLocalAddress())
{
- if (inetAddr.isSiteLocalAddress())
- {
- // Found non-loopback site-local address.
- addresses.add(inetAddr);
- }
- if ( candidateAddress == null )
- {
- // Found non-loopback address, but not necessarily site-local.
- // Store it as a candidate to be returned if site-local address is not subsequently found...
- candidateAddress = inetAddr;
- // Note that we don't repeatedly assign non-loopback non-site-local addresses as candidates,
- // only the first. For subsequent iterations, candidate will be non-null.
- }
+ // Found non-loopback site-local address.
+ addresses.add(inetAddr);
+ }
+ if ( candidateAddress == null )
+ {
+ // Found non-loopback address, but not necessarily site-local.
+ // Store it as a candidate to be returned if site-local address is not subsequently found...
+ candidateAddress = inetAddr;
+ // Note that we don't repeatedly assign non-loopback non-site-local addresses as candidates,
+ // only the first. For subsequent iterations, candidate will be non-null.
}
}
}
@@ -199,22 +196,20 @@ public class HostNameUtil
public static NetworkInterface getMulticastNetworkInterface() throws SocketException
{
final Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
- if (networkInterfaces != null) {
- while (networkInterfaces.hasMoreElements())
+ while (networkInterfaces.hasMoreElements())
+ {
+ final NetworkInterface networkInterface = networkInterfaces.nextElement();
+ final Enumeration<InetAddress> addressesFromNetworkInterface = networkInterface.getInetAddresses();
+ while (addressesFromNetworkInterface.hasMoreElements())
{
- final NetworkInterface networkInterface = networkInterfaces.nextElement();
- final Enumeration<InetAddress> addressesFromNetworkInterface = networkInterface.getInetAddresses();
- while (addressesFromNetworkInterface.hasMoreElements())
+ final InetAddress inetAddress = addressesFromNetworkInterface.nextElement();
+ if (inetAddress.isSiteLocalAddress()
+ && !inetAddress.isAnyLocalAddress()
+ && !inetAddress.isLinkLocalAddress()
+ && !inetAddress.isLoopbackAddress()
+ && !inetAddress.isMulticastAddress())
{
- final InetAddress inetAddress = addressesFromNetworkInterface.nextElement();
- if (inetAddress.isSiteLocalAddress()
- && !inetAddress.isAnyLocalAddress()
- && !inetAddress.isLinkLocalAddress()
- && !inetAddress.isLoopbackAddress()
- && !inetAddress.isMulticastAddress())
- {
- return networkInterface;
- }
+ return networkInterface;
}
}
}
diff --git a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java
index 90ec8f0..886d3c0 100644
--- a/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java
+++ b/commons-jcs-jcache/src/main/java/org/apache/commons/jcs3/jcache/JCSCachingManager.java
@@ -189,8 +189,8 @@ public class JCSCachingManager implements CacheManager
assertNotClosed();
assertNotNull(cacheName, "cacheName");
assertNotNull(configuration, "configuration");
- final Class<?> keyType = configuration == null ? Object.class : configuration.getKeyType();
- final Class<?> valueType = configuration == null ? Object.class : configuration.getValueType();
+ final Class<?> keyType = configuration.getKeyType();
+ final Class<?> valueType = configuration.getValueType();
if (caches.containsKey(cacheName)) {
throw new javax.cache.CacheException("cache " + cacheName + " already exists");
}