commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From t.@apache.org
Subject svn commit: r1717921 - in /commons/proper/jcs/trunk/commons-jcs-core/src: main/java/org/apache/commons/jcs/auxiliary/ main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/ main/java/org/apache/commons/jcs/io/ main/java/org/apache/commons/jcs/utils...
Date Fri, 04 Dec 2015 10:11:55 GMT
Author: tv
Date: Fri Dec  4 10:11:55 2015
New Revision: 1717921

URL: http://svn.apache.org/viewvc?rev=1717921&view=rev
Log:
Address issues reported by Findbugs

Modified:
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCacheMonitor.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/AbstractJCSWorkerHelper.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorker.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorkerHelper.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
    commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/access/JCSWorkerUnitTest.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java
    commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCacheMonitor.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCacheMonitor.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCacheMonitor.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/AbstractAuxiliaryCacheMonitor.java
Fri Dec  4 10:11:55 2015
@@ -45,7 +45,7 @@ public abstract class AbstractAuxiliaryC
     /**
      * Must make sure AbstractAuxiliaryCacheMonitor is started before any error can be detected!
      */
-    private AtomicBoolean allright = new AtomicBoolean(true);
+    protected AtomicBoolean allright = new AtomicBoolean(true);
 
     /**
      * shutdown flag
@@ -82,14 +82,6 @@ public abstract class AbstractAuxiliaryC
     }
 
     /**
-     * Set error condition unconditionally
-     */
-    protected void setError(boolean state)
-    {
-        allright.set(!state);
-    }
-
-    /**
      * Notifies the cache monitor that an error occurred, and kicks off the error recovery
process.
      */
     public void notifyError()
@@ -135,7 +127,6 @@ public abstract class AbstractAuxiliaryC
      */
     protected abstract void doWork();
 
-
     /**
      * Main processing method for the AbstractAuxiliaryCacheMonitor object
      */

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/auxiliary/disk/jdbc/hsql/HSQLDiskCacheFactory.java
Fri Dec  4 10:11:55 2015
@@ -169,13 +169,11 @@ public class HSQLDiskCacheFactory
 
         try
         {
-            sStatement.executeQuery( createSql.toString() );
-            sStatement.close();
+            sStatement.execute( createSql.toString() );
         }
         catch ( SQLException e )
         {
-            // FIXME: This is not reliable
-            if ( e.toString().indexOf( "already exists" ) != -1 )
+            if ("23000".equals(e.getSQLState()))
             {
                 newT = false;
             }
@@ -184,23 +182,35 @@ public class HSQLDiskCacheFactory
                 throw e;
             }
         }
-
-        // TODO create an index on SYSTEM_EXPIRE_TIME_SECONDS
-        String setupData[] = { "create index iKEY on " + tableName + " (CACHE_KEY, REGION)"
};
+        finally
+        {
+            sStatement.close();
+        }
 
         if ( newT )
         {
-            for ( int i = 1; i < setupData.length; i++ )
+            // TODO create an index on SYSTEM_EXPIRE_TIME_SECONDS
+            String setupData[] = { "create index iKEY on " + tableName + " (CACHE_KEY, REGION)"
};
+            Statement iStatement = cConn.createStatement();
+
+            try
             {
-                try
-                {
-                    sStatement.executeQuery( setupData[i] );
-                }
-                catch ( SQLException e )
+                for ( int i = 0; i < setupData.length; i++ )
                 {
-                    log.error( "Exception caught when creating index." + e );
+                    try
+                    {
+                        iStatement.execute( setupData[i] );
+                    }
+                    catch ( SQLException e )
+                    {
+                        log.error( "Exception caught when creating index.", e );
+                    }
                 }
             }
+            finally
+            {
+                iStatement.close();
+            }
         }
     }
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/io/ObjectInputStreamClassLoaderAware.java
Fri Dec  4 10:11:55 2015
@@ -38,8 +38,8 @@ public class ObjectInputStreamClassLoade
     }
 
     @Override
-    protected Class resolveProxyClass(final String[] interfaces) throws IOException, ClassNotFoundException
{
-        final Class[] cinterfaces = new Class[interfaces.length];
+    protected Class<?> resolveProxyClass(final String[] interfaces) throws IOException,
ClassNotFoundException {
+        final Class<?>[] cinterfaces = new Class[interfaces.length];
         for (int i = 0; i < interfaces.length; i++) {
             cinterfaces[i] = Class.forName(interfaces[i], false, classLoader);
         }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/AbstractJCSWorkerHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/AbstractJCSWorkerHelper.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/AbstractJCSWorkerHelper.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/AbstractJCSWorkerHelper.java
Fri Dec  4 10:11:55 2015
@@ -25,8 +25,7 @@ package org.apache.commons.jcs.utils.acc
  * <p>
  * @author tsavo
  */
-public abstract class AbstractJCSWorkerHelper
-    implements JCSWorkerHelper
+public abstract class AbstractJCSWorkerHelper<V> implements JCSWorkerHelper<V>
 {
     /** finished flag. Can't we use wait notify? */
     private boolean finished = false;
@@ -43,7 +42,7 @@ public abstract class AbstractJCSWorkerH
      * @return finished
      */
     @Override
-    public boolean isFinished()
+    public synchronized boolean isFinished()
     {
         return finished;
     }
@@ -52,7 +51,7 @@ public abstract class AbstractJCSWorkerH
      * @param isFinished
      */
     @Override
-    public void setFinished( boolean isFinished )
+    public synchronized void setFinished( boolean isFinished )
     {
         finished = isFinished;
     }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorker.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorker.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorker.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorker.java
Fri Dec  4 10:11:55 2015
@@ -19,6 +19,10 @@ package org.apache.commons.jcs.utils.acc
  * under the License.
  */
 
+import java.io.Serializable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
 import org.apache.commons.jcs.JCS;
 import org.apache.commons.jcs.access.CacheAccess;
 import org.apache.commons.jcs.access.GroupCacheAccess;
@@ -26,10 +30,6 @@ import org.apache.commons.jcs.access.exc
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * Utility class to encapsulate doing a piece of work, and caching the results
  * in JCS. Simply construct this class with the region name for the Cache and
@@ -106,7 +106,7 @@ public class JCSWorker<K extends Seriali
     /**
      * Map to hold who's doing work presently.
      */
-    private static volatile Map<String, JCSWorkerHelper> map = new HashMap<String,
JCSWorkerHelper>();
+    private volatile ConcurrentMap<String, JCSWorkerHelper<V>> map = new ConcurrentHashMap<String,
JCSWorkerHelper<V>>();
 
     /**
      * Region for the JCS cache.
@@ -158,7 +158,7 @@ public class JCSWorker<K extends Seriali
      *             Throws an exception if anything goes wrong while doing the
      *             work.
      */
-    public V getResult( K aKey, JCSWorkerHelper aWorker )
+    public V getResult( K aKey, JCSWorkerHelper<V> aWorker )
         throws Exception
     {
         return run( aKey, null, aWorker );
@@ -168,7 +168,7 @@ public class JCSWorker<K extends Seriali
      * Gets the cached result for this region/key OR does the work and caches
      * the result, returning the result. If the result has not been cached yet,
      * this calls doWork() on the JCSWorkerHelper to do the work and cache the
-     * result. This is also an opertunity to do any post processing of the
+     * result. This is also an opportunity to do any post processing of the
      * result in your CachedWorker implementation.
      * @param aKey
      *            The key to get/put with on the Cache.
@@ -183,7 +183,7 @@ public class JCSWorker<K extends Seriali
      *             Throws an exception if anything goes wrong while doing the
      *             work.
      */
-    public V getResult( K aKey, String aGroup, JCSWorkerHelper aWorker )
+    public V getResult( K aKey, String aGroup, JCSWorkerHelper<V> aWorker )
         throws Exception
     {
         return run( aKey, aGroup, aWorker );
@@ -203,25 +203,14 @@ public class JCSWorker<K extends Seriali
      *             If something goes wrong while doing the work, throw an
      *             exception.
      */
-    private V run( K aKey, String aGroup, JCSWorkerHelper aHelper )
+    private V run( K aKey, String aGroup, JCSWorkerHelper<V> aHelper )
         throws Exception
     {
         V result = null;
         // long start = 0;
         // long dbTime = 0;
-        JCSWorkerHelper helper = null;
+        JCSWorkerHelper<V> helper = map.putIfAbsent(getRegion() + aKey, aHelper);
 
-        synchronized ( map )
-        {
-            // Check to see if we already have a thread doing this work.
-            helper = map.get( getRegion() + aKey );
-            if ( helper == null )
-            {
-                // If not, add ourselves as the Worker so
-                // calls in another thread will use this worker's result
-                map.put( getRegion() + aKey, aHelper );
-            }
-        }
         if ( helper != null )
         {
             synchronized ( helper )
@@ -230,9 +219,16 @@ public class JCSWorker<K extends Seriali
                 {
                     logger.debug( "Found a worker already doing this work (" + getRegion()
+ ":" + aKey + ")." );
                 }
-                if ( !helper.isFinished() )
+                while ( !helper.isFinished() )
                 {
-                    helper.wait();
+                    try
+                    {
+                        helper.wait();
+                    }
+                    catch (InterruptedException e)
+                    {
+                        // expected
+                    }
                 }
                 if ( logger.isDebugEnabled() )
                 {
@@ -261,9 +257,7 @@ public class JCSWorker<K extends Seriali
             // If the cache dosn't have it, do the work.
             if ( result == null )
             {
-                @SuppressWarnings("unchecked") // Need to cast from Object
-                V doWork = (V)aHelper.doWork();
-                result = doWork;
+                result = aHelper.doWork();
                 if ( logger.isDebugEnabled() )
                 {
                     logger.debug( "Work Done, caching: key:" + aKey + ", group:" + aGroup
+ ", result:" + result + "." );
@@ -287,19 +281,17 @@ public class JCSWorker<K extends Seriali
             {
                 logger.debug( getRegion() + ":" + aKey + " entered finally." );
             }
-            synchronized ( map )
+
+            // Remove ourselves as the worker.
+            if ( helper == null )
             {
-                // Remove ourselves as the worker.
-                if ( helper == null )
-                {
-                    map.remove( getRegion() + aKey );
-                }
-                synchronized ( aHelper )
-                {
-                    aHelper.setFinished( true );
-                    // Wake everyone waiting on us
-                    aHelper.notifyAll();
-                }
+                map.remove( getRegion() + aKey );
+            }
+            synchronized ( aHelper )
+            {
+                aHelper.setFinished( true );
+                // Wake everyone waiting on us
+                aHelper.notifyAll();
             }
         }
     }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorkerHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorkerHelper.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorkerHelper.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/access/JCSWorkerHelper.java
Fri Dec  4 10:11:55 2015
@@ -21,7 +21,7 @@ package org.apache.commons.jcs.utils.acc
 
 /**
  * Interface for doing a piece of work which is expected to be cached. This is
- * ment to be used in conjunction with JCSWorker.
+ * meant to be used in conjunction with JCSWorker.
  * <p>
  * Implement doWork() to return the work being done. isFinished() should return
  * false until setFinished(true) is called, after which time it should return
@@ -29,7 +29,7 @@ package org.apache.commons.jcs.utils.acc
  * <p>
  * @author tsavo
  */
-public interface JCSWorkerHelper
+public interface JCSWorkerHelper<V>
 {
     /**
      * Tells us whether or not the work has been completed. This will be called
@@ -56,6 +56,5 @@ public interface JCSWorkerHelper
      *             If anything goes wrong while doing the work, an Exception
      *             should be thrown.
      */
-    Object doWork()
-        throws Exception;
+    V doWork() throws Exception;
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryManager.java
Fri Dec  4 10:11:55 2015
@@ -19,14 +19,14 @@ package org.apache.commons.jcs.utils.dis
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.commons.jcs.engine.behavior.ICompositeCacheManager;
 import org.apache.commons.jcs.engine.behavior.IProvideScheduler;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * This manages UDPDiscovery Services. We should end up with one service per Lateral Cache
Manager
  * Instance. One service works for multiple regions. We don't want a connection for each
region.
@@ -101,6 +101,7 @@ public class UDPDiscoveryManager
                 service.setScheduledExecutorService(((IProvideScheduler)cacheMgr).getScheduledExecutorService());
             }
 
+            service.startup();
             services.put( key, service );
         }
 

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryService.java
Fri Dec  4 10:11:55 2015
@@ -19,13 +19,7 @@ package org.apache.commons.jcs.utils.dis
  * under the License.
  */
 
-import org.apache.commons.jcs.engine.behavior.IRequireScheduler;
-import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
-import org.apache.commons.jcs.utils.discovery.behavior.IDiscoveryListener;
-import org.apache.commons.jcs.utils.net.HostNameUtil;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
+import java.io.IOException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -34,6 +28,13 @@ import java.util.concurrent.CopyOnWriteA
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
+import org.apache.commons.jcs.engine.behavior.IRequireScheduler;
+import org.apache.commons.jcs.engine.behavior.IShutdownObserver;
+import org.apache.commons.jcs.utils.discovery.behavior.IDiscoveryListener;
+import org.apache.commons.jcs.utils.net.HostNameUtil;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
 /**
  * This service creates a listener that can create lateral caches and add them to the no
wait list.
  * <p>
@@ -85,9 +86,9 @@ public class UDPDiscoveryService
             // todo, you should be able to set this
             udpDiscoveryAttributes.setServiceAddress( HostNameUtil.getLocalHostAddress()
);
         }
-        catch ( UnknownHostException e1 )
+        catch ( UnknownHostException e )
         {
-            log.error( "Couldn't get localhost address", e1 );
+            log.error( "Couldn't get localhost address", e );
         }
 
         try
@@ -95,12 +96,8 @@ public class UDPDiscoveryService
             // todo need some kind of recovery here.
             receiver = new UDPDiscoveryReceiver( this, getUdpDiscoveryAttributes().getUdpDiscoveryAddr(),
                                                  getUdpDiscoveryAttributes().getUdpDiscoveryPort()
);
-            udpReceiverThread = new Thread( receiver );
-            udpReceiverThread.setDaemon( true );
-            // udpReceiverThread.setName( t.getName() + "--UDPReceiver" );
-            udpReceiverThread.start();
         }
-        catch ( Exception e )
+        catch ( IOException e )
         {
             log.error( "Problem creating UDPDiscoveryReceiver, address ["
                 + getUdpDiscoveryAttributes().getUdpDiscoveryAddr() + "] port ["
@@ -315,6 +312,17 @@ public class UDPDiscoveryService
     }
 
     /**
+     * Start necessary receiver thread
+     */
+    public void startup()
+    {
+        udpReceiverThread = new Thread( receiver );
+        udpReceiverThread.setDaemon( true );
+        // udpReceiverThread.setName( t.getName() + "--UDPReceiver" );
+        udpReceiverThread.start();
+    }
+
+    /**
      * Shuts down the receiver.
      */
     @Override
@@ -366,29 +374,6 @@ public class UDPDiscoveryService
     }
 
     /**
-     * Call shutdown to be safe.
-     * <p>
-     * @throws Throwable on error
-     */
-    @Override
-    protected void finalize()
-        throws Throwable
-    {
-        super.finalize();
-
-        // TODO reconsider this, since it uses the logger
-        shutdown();
-    }
-
-    /**
-     * @param discoveredServices The discoveredServices to set.
-     */
-    public synchronized void setDiscoveredServices( Set<DiscoveredService> discoveredServices
)
-    {
-        this.discoveredServices = discoveredServices;
-    }
-
-    /**
      * @return Returns the discoveredServices.
      */
     public synchronized Set<DiscoveredService> getDiscoveredServices()

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/main/java/org/apache/commons/jcs/utils/threadpool/ThreadPoolManager.java
Fri Dec  4 10:11:55 2015
@@ -33,8 +33,7 @@ import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
 /**
- * This manages threadpools for an application using Doug Lea's Util Concurrent package.
- * http://gee.cs.oswego.edu/dl/classes/EDU/oswego/cs/dl/util/concurrent/intro.html
+ * This manages threadpools for an application
  * <p>
  * It is a singleton since threads need to be managed vm wide.
  * <p>
@@ -111,20 +110,22 @@ public class ThreadPoolManager
      */
     private static volatile Properties props = null;
 
+    /** singleton instance */
+    private static ThreadPoolManager INSTANCE = null;
+
     /** Map of names to pools. */
-    private static ConcurrentHashMap<String, ThreadPoolExecutor> pools = new ConcurrentHashMap<String,
ThreadPoolExecutor>();
+    private ConcurrentHashMap<String, ThreadPoolExecutor> pools;
 
     /** Lock for pools initialization. */
-    private static ReentrantLock poolLock = new ReentrantLock();
-
-    /** singleton instance */
-    private static ThreadPoolManager INSTANCE = null;
+    private ReentrantLock poolLock;
 
     /**
      * No instances please. This is a singleton.
      */
     private ThreadPoolManager()
     {
+        this.pools = new ConcurrentHashMap<String, ThreadPoolExecutor>();
+        this.poolLock = new ReentrantLock();
         configure();
     }
 
@@ -136,7 +137,6 @@ public class ThreadPoolManager
      */
     private ThreadPoolExecutor createPool( PoolConfiguration config )
     {
-        ThreadPoolExecutor pool = null;
         BlockingQueue<Runnable> queue = null;
         if ( config.isUseBoundary() )
         {
@@ -156,9 +156,13 @@ public class ThreadPoolManager
             queue = new LinkedBlockingQueue<Runnable>();
         }
 
-        pool = new ThreadPoolExecutor(config.getStartUpSize(), config.getMaximumPoolSize(),
-                config.getKeepAliveTime(), TimeUnit.MILLISECONDS,
-                queue, new DaemonThreadFactory("JCS-ThreadPoolManager-"));
+        ThreadPoolExecutor pool = new ThreadPoolExecutor(
+            config.getStartUpSize(),
+            config.getMaximumPoolSize(),
+            config.getKeepAliveTime(),
+            TimeUnit.MILLISECONDS,
+            queue,
+            new DaemonThreadFactory("JCS-ThreadPoolManager-"));
 
         // when blocked policy
         switch (config.getWhenBlockedPolicy())
@@ -256,11 +260,7 @@ public class ThreadPoolManager
 
                     PoolConfiguration config = loadConfig( PROP_NAME_ROOT + "." + name );
                     pool = createPool( config );
-
-                    if ( pool != null )
-                    {
-                        pools.put( name, pool );
-                    }
+                    pools.put( name, pool );
 
                     if ( log.isDebugEnabled() )
                     {
@@ -284,9 +284,7 @@ public class ThreadPoolManager
      */
     public ArrayList<String> getPoolNames()
     {
-        ArrayList<String> poolNames = new ArrayList<String>();
-        poolNames.addAll(pools.keySet());
-        return poolNames;
+        return new ArrayList<String>(pools.keySet());
     }
 
     /**

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/access/JCSWorkerUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/access/JCSWorkerUnitTest.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/access/JCSWorkerUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/access/JCSWorkerUnitTest.java
Fri Dec  4 10:11:55 2015
@@ -45,15 +45,14 @@ public class JCSWorkerUnitTest
         JCSWorker<String, Long> cachingWorker = new JCSWorker<String, Long>(
"example region" );
 
         // This is the helper.
-        JCSWorkerHelper helper = new AbstractJCSWorkerHelper()
+        JCSWorkerHelper<Long> helper = new AbstractJCSWorkerHelper<Long>()
         {
             int timesCalled = 0;
 
             @Override
-            public Object doWork()
+            public Long doWork()
             {
-                Object results = Long.valueOf( ++timesCalled );
-                return results;
+                return Long.valueOf( ++timesCalled );
             }
         };
 
@@ -65,7 +64,6 @@ public class JCSWorkerUnitTest
         // should get it from the cache.
         Long result2 = cachingWorker.getResult( key, helper );
         assertEquals( "Called the wrong number of times", Long.valueOf( 1 ), result2 );
-
     }
 
 }

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryServiceUnitTest.java
Fri Dec  4 10:11:55 2015
@@ -19,10 +19,10 @@ package org.apache.commons.jcs.utils.dis
  * under the License.
  */
 
-import junit.framework.TestCase;
-
 import java.util.ArrayList;
 
+import junit.framework.TestCase;
+
 /** Unit tests for the service. */
 public class UDPDiscoveryServiceUnitTest
     extends TestCase
@@ -40,6 +40,7 @@ public class UDPDiscoveryServiceUnitTest
 
         // create the service
         UDPDiscoveryService service = new UDPDiscoveryService( attributes );
+        service.startup();
         service.addParticipatingCacheName( "testCache1" );
 
         MockDiscoveryListener discoveryListener = new MockDiscoveryListener();
@@ -74,6 +75,7 @@ public class UDPDiscoveryServiceUnitTest
 
         // create the service
         UDPDiscoveryService service = new UDPDiscoveryService( attributes );
+        service.startup();
         service.addParticipatingCacheName( "testCache1" );
 
         MockDiscoveryListener discoveryListener = new MockDiscoveryListener();
@@ -136,6 +138,7 @@ public class UDPDiscoveryServiceUnitTest
 
         // create the service
         UDPDiscoveryService service = new UDPDiscoveryService( attributes );
+        service.startup();
         service.addParticipatingCacheName( "testCache1" );
 
         MockDiscoveryListener discoveryListener = new MockDiscoveryListener();
@@ -197,6 +200,7 @@ public class UDPDiscoveryServiceUnitTest
 
         // create the service
         UDPDiscoveryService service = new UDPDiscoveryService( attributes );
+        service.startup();
         service.addParticipatingCacheName( "testCache1" );
 
         MockDiscoveryListener discoveryListener = new MockDiscoveryListener();

Modified: commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java?rev=1717921&r1=1717920&r2=1717921&view=diff
==============================================================================
--- commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
(original)
+++ commons/proper/jcs/trunk/commons-jcs-core/src/test/java/org/apache/commons/jcs/utils/discovery/UDPDiscoveryUnitTest.java
Fri Dec  4 10:11:55 2015
@@ -19,10 +19,11 @@ package org.apache.commons.jcs.utils.dis
  * under the License.
  */
 
+import java.util.ArrayList;
+
 import junit.framework.TestCase;
-import org.apache.commons.jcs.utils.timing.SleepUtil;
 
-import java.util.ArrayList;
+import org.apache.commons.jcs.utils.timing.SleepUtil;
 
 /**
  * Unit tests for discovery
@@ -44,6 +45,7 @@ public class UDPDiscoveryUnitTest
 
         // create the service
         UDPDiscoveryService service = new UDPDiscoveryService( attributes );
+        service.startup();
         service.addParticipatingCacheName( "testCache1" );
 
         MockDiscoveryListener discoveryListener = new MockDiscoveryListener();



Mime
View raw message