Skip to content

Commit

Permalink
Use final
Browse files Browse the repository at this point in the history
Use blocks
Remove useless or redundant parens
Use diamonds
Remove redundant keywords
Use else if
Add @OverRide
Use a for each loop instead of an iterator
Remove trailing whitespace
Use a switch instead of a cascading if else
  • Loading branch information
garydgregory committed Jul 9, 2024
1 parent 7398c74 commit fd9b5de
Show file tree
Hide file tree
Showing 45 changed files with 458 additions and 391 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ private void deleteExpiredFromAllRegisteredRegions()
if ( i.hasNext() )
{
log.info( "Pausing for [{0}] ms before shrinking the next region.",
this.getPauseBetweenRegionCallsMillis() );
getPauseBetweenRegionCallsMillis() );

try
{
Thread.sleep( this.getPauseBetweenRegionCallsMillis() );
Thread.sleep( getPauseBetweenRegionCallsMillis() );
}
catch ( final InterruptedException e )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class TableState
*/
public TableState( final String tableName )
{
this.setTableName( tableName );
setTableName( tableName );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public MySQLDiskCache( final MySQLDiskCacheAttributes attributes, final DataSour
@Override
protected int deleteExpired()
{
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return -1;
Expand All @@ -94,7 +94,7 @@ protected int deleteExpired()
@Override
protected ICacheElement<K, V> processGet( final K key )
{
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return null;
Expand All @@ -112,7 +112,7 @@ protected ICacheElement<K, V> processGet( final K key )
@Override
protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern )
{
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return null;
Expand All @@ -129,7 +129,7 @@ protected Map<K, ICacheElement<K, V>> processGetMatching( final String pattern )
@Override
protected void processUpdate( final ICacheElement<K, V> element )
{
if (this.getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
if (getTableState().getState() == TableState.OPTIMIZATION_RUNNING &&
this.mySQLDiskCacheAttributes.isBalkDuringOptimization())
{
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ protected void scheduleOptimizations( final MySQLDiskCacheAttributes attributes,
// can´t be null, otherwise ScheduleParser.createDatesForSchedule will throw ParseException
final Date[] dates = ScheduleParser.createDatesForSchedule( attributes.getOptimizationSchedule() );
for (final Date date : dates) {
this.scheduleOptimization( date, optimizer );
scheduleOptimization( date, optimizer );
}
}
catch ( final ParseException e )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,14 @@ public boolean optimizeTable()
try
{
tableState.setState( TableState.OPTIMIZATION_RUNNING );
log.info( "Optimizing table [{0}]", this.getTableName());
log.info( "Optimizing table [{0}]", getTableName());

try (Connection con = dataSource.getConnection())
{
// TEST
try (Statement sStatement = con.createStatement())
{
try (ResultSet rs = sStatement.executeQuery( "optimize table " + this.getTableName() ))
try (ResultSet rs = sStatement.executeQuery( "optimize table " + getTableName() ))
{
// first row is error, then status
// if there is only one row in the result set, everything
Expand Down Expand Up @@ -204,12 +204,12 @@ public boolean optimizeTable()
// log the table status
final String statusString = getTableStatus( sStatement );
log.info( "Table status after optimizing table [{0}]: {1}",
this.getTableName(), statusString );
getTableName(), statusString );
}
catch ( final SQLException e )
{
log.error( "Problem optimizing table [{0}]",
this.getTableName(), e );
getTableName(), e );
return false;
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ protected boolean repairTable( final Statement sStatement )

// if( message != null && message.indexOf( ) )
final StringBuilder repairString = new StringBuilder();
try (ResultSet repairResult = sStatement.executeQuery( "repair table " + this.getTableName()))
try (ResultSet repairResult = sStatement.executeQuery( "repair table " + getTableName()))
{
final int numColumns = repairResult.getMetaData().getColumnCount();
while ( repairResult.next() )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static Date[] createDatesForSchedule( final String schedule )
final String[] timeStrings = schedule.split("\\s*,\\s*");
final Date[] dates = new Date[timeStrings.length];
int cnt = 0;
for (String time : timeStrings)
for (final String time : timeStrings)
{
dates[cnt++] = getDateForSchedule(time);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,6 @@ public void setUdpTTL( final int udpTTL )
@Override
public String toString()
{
return this.getTcpServer() + ":" + this.getTcpListenerPort();
return getTcpServer() + ":" + getTcpListenerPort();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ protected AbstractRemoteCacheNoWaitFacade<K, V> getFacade()
protected String getIPAddressForService()
{
String ipAddress = "(null)";
if (this.getRemoteCacheAttributes().getRemoteLocation() != null)
if (getRemoteCacheAttributes().getRemoteLocation() != null)
{
ipAddress = this.getRemoteCacheAttributes().getRemoteLocation().toString();
ipAddress = getRemoteCacheAttributes().getRemoteLocation().toString();
}
return ipAddress;
}
Expand All @@ -124,7 +124,7 @@ public IStats getStatistics()
final ArrayList<IStatElement<?>> elems = new ArrayList<>();

elems.add(new StatElement<>( "Remote Host:Port", getIPAddressForService() ) );
elems.add(new StatElement<>( "Remote Type", this.getRemoteCacheAttributes().getRemoteTypeName() ) );
elems.add(new StatElement<>( "Remote Type", getRemoteCacheAttributes().getRemoteTypeName() ) );

// if ( this.getRemoteCacheAttributes().getRemoteType() == RemoteType.CLUSTER )
// {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public <K, V> AuxiliaryCache<K, V> createCache(
if (failoverList != null && !failoverList.isEmpty())
{
final String[] failoverServers = failoverList.split("\\s*,\\s*");
for (String server : failoverServers)
for (final String server : failoverServers)
{
final RemoteLocation location = RemoteLocation.parseServerAndPort(server);

Expand Down Expand Up @@ -121,7 +121,7 @@ public <K, V> AuxiliaryCache<K, V> createCache(
case CLUSTER:
// REGISTER LISTENERS FOR EACH SYSTEM CLUSTERED CACHEs
final String[] clusterServers = rca.getClusterServers().split("\\s*,\\s*");
for (String server: clusterServers)
for (final String server: clusterServers)
{
if (server.isEmpty())
{
Expand Down Expand Up @@ -220,7 +220,7 @@ public RemoteCacheManager getManager( final IRemoteCacheAttributes cattr,

return managers.computeIfAbsent(rca.getRemoteLocation(), key -> {

RemoteCacheManager manager = new RemoteCacheManager(rca, cacheMgr, monitor, cacheEventLogger, elementSerializer);
final RemoteCacheManager manager = new RemoteCacheManager(rca, cacheMgr, monitor, cacheEventLogger, elementSerializer);
monitor.addManager(manager);

return manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,18 +320,14 @@ public void removeRemoteCacheListener( final IRemoteCacheAttributes cattr )
if ( cache != null )
{
removeListenerFromCache(cache);
} else if ( cattr.isReceive() )
{
log.warn( "Trying to deregister Cache Listener that was never registered." );
}
else
{
if ( cattr.isReceive() )
{
log.warn( "Trying to deregister Cache Listener that was never registered." );
}
else
{
log.debug( "Since the remote cache is configured to not receive, "
+ "there is no listener to deregister." );
}
log.debug( "Since the remote cache is configured to not receive, "
+ "there is no listener to deregister." );
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public void addManager(final RemoteCacheManager manager)
this.managers.put(manager, manager);

// if not yet started, go ahead
if (this.getState() == Thread.State.NEW)
if (getState() == Thread.State.NEW)
{
this.start();
start();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public static Properties loadProps(final String propFile)

if (null == is) // not found in class path
{
Path propPath = Paths.get(propFile);
final Path propPath = Paths.get(propFile);
if (Files.exists(propPath))
{
// file found
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ private void incrementServiceCallCount()
{
// not thread safe, but it doesn't have to be accurate
serviceCalls++;
if ( log.isInfoEnabled() && (serviceCalls % logInterval == 0) )
if ( log.isInfoEnabled() && serviceCalls % logInterval == 0 )
{
log.info( "serviceCalls = {0}", serviceCalls );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ private void logUpdateInfo( final ICacheElement<K, V> item )
// not thread safe, but it doesn't have to be 100% accurate
puts++;

if ( log.isInfoEnabled() && (puts % logInterval == 0) )
if ( log.isInfoEnabled() && puts % logInterval == 0 )
{
log.info( "puts = {0}", puts );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,14 @@ public void setUseRegistryKeepAlive( final boolean useRegistryKeepAlive )
public String toString()
{
final StringBuilder buf = new StringBuilder(super.toString());
buf.append( "\n servicePort = [" + this.getServicePort() + "]" );
buf.append( "\n allowClusterGet = [" + this.isAllowClusterGet() + "]" );
buf.append( "\n configFileName = [" + this.getConfigFileName() + "]" );
buf.append( "\n rmiSocketFactoryTimeoutMillis = [" + this.getRmiSocketFactoryTimeoutMillis() + "]" );
buf.append( "\n useRegistryKeepAlive = [" + this.isUseRegistryKeepAlive() + "]" );
buf.append( "\n registryKeepAliveDelayMillis = [" + this.getRegistryKeepAliveDelayMillis() + "]" );
buf.append( "\n eventQueueType = [" + this.getEventQueueType() + "]" );
buf.append( "\n eventQueuePoolName = [" + this.getEventQueuePoolName() + "]" );
buf.append( "\n servicePort = [" + getServicePort() + "]" );
buf.append( "\n allowClusterGet = [" + isAllowClusterGet() + "]" );
buf.append( "\n configFileName = [" + getConfigFileName() + "]" );
buf.append( "\n rmiSocketFactoryTimeoutMillis = [" + getRmiSocketFactoryTimeoutMillis() + "]" );
buf.append( "\n useRegistryKeepAlive = [" + isUseRegistryKeepAlive() + "]" );
buf.append( "\n registryKeepAliveDelayMillis = [" + getRegistryKeepAliveDelayMillis() + "]" );
buf.append( "\n eventQueueType = [" + getEventQueueType() + "]" );
buf.append( "\n eventQueuePoolName = [" + getEventQueuePoolName() + "]" );
return buf.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,9 @@ protected static String getServiceName()
* @param cacheEventLogger the event logger for error messages
* @since 3.1
*/
protected static void keepAlive(String registryHost, int registryPort, ICacheEventLogger cacheEventLogger)
protected static void keepAlive(final String registryHost, final int registryPort, final ICacheEventLogger cacheEventLogger)
{
String namingURL = RemoteUtils.getNamingURL(registryHost, registryPort, serviceName);
final String namingURL = RemoteUtils.getNamingURL(registryHost, registryPort, serviceName);
log.debug( "looking up server {0}", namingURL );

try
Expand Down Expand Up @@ -422,7 +422,7 @@ static void shutdownImpl( final String host, final int port )
* @param props
* @throws IOException
*/
public static void startup( String host, final int port, final Properties props)
public static void startup( final String host, final int port, final Properties props)
throws IOException
{
if ( remoteCacheServer != null )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected ExecutorService createPool(final String threadPoolName)
{
// this will share the same pool with other event queues by default.
return ThreadPoolManager.getInstance().getExecutorService(
(threadPoolName == null) ? "cache_event_queue" : threadPoolName );
threadPoolName == null ? "cache_event_queue" : threadPoolName );
}

/**
Expand All @@ -91,7 +91,7 @@ protected ExecutorService createPool(final String threadPoolName)
* @param waitSeconds number of seconds to wait for the queue to drain
*/
@Override
public synchronized void destroy(int waitSeconds)
public synchronized void destroy(final int waitSeconds)
{
if ( isWorking() )
{
Expand All @@ -108,7 +108,7 @@ public synchronized void destroy(int waitSeconds)
this::getStatistics);
}
}
catch (InterruptedException e)
catch (final InterruptedException e)
{
// ignore
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@
import java.lang.reflect.Proxy;

/**
* ObjectInputStream implementation that allows to specify a class loader for deserializing
* ObjectInputStream implementation that allows to specify a class loader for deserializing
* objects
*
*
* The class also evaluates the system property <code>jcs.serialization.class.filter</code>
* to define a list of classes that are allowed to be de-serialized. The filter value
* is directly fed into {@link java.io.ObjectInputFilter.Config#createFilter(String)}
* See the syntax documentation there.
*/
public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
public class ObjectInputStreamClassLoaderAware extends ObjectInputStream
{
public static final String SYSTEM_PROPERTY_SERIALIZATION_FILTER = "jcs.serialization.class.filter";

Expand All @@ -44,7 +44,7 @@ public class ObjectInputStreamClassLoaderAware extends ObjectInputStream

private final ClassLoader classLoader;

public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
public ObjectInputStreamClassLoaderAware(final InputStream in, final ClassLoader classLoader) throws IOException
{
super(in);
setObjectInputFilter(ObjectInputFilter.Config.createFilter(filter));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,37 +82,33 @@ public static String convertSpecialChars( final String s )
if ( c == '\\' )
{
c = s.charAt( i++ );
if ( c == 'n' )
{
switch (c) {
case 'n':
c = '\n';
}
else if ( c == 'r' )
{
break;
case 'r':
c = '\r';
}
else if ( c == 't' )
{
break;
case 't':
c = '\t';
}
else if ( c == 'f' )
{
break;
case 'f':
c = '\f';
}
else if ( c == '\b' )
{
break;
case '\b':
c = '\b';
}
else if ( c == '\"' )
{
break;
case '\"':
c = '\"';
}
else if ( c == '\'' )
{
break;
case '\'':
c = '\'';
}
else if ( c == '\\' )
{
break;
case '\\':
c = '\\';
break;
default:
break;
}
}
sb.append( c );
Expand Down
Loading

0 comments on commit fd9b5de

Please sign in to comment.