@@ -58,7 +58,7 @@ public class ResilientPooledObjectFactory<T, E extends Exception> implements Poo
5858 private Instant upStart ;
5959 /** Exception counts */
6060 @ SuppressWarnings ("rawtypes" )
61- private ConcurrentHashMap <Class , Integer > exceptionCounts = new ConcurrentHashMap <>();
61+ private final ConcurrentHashMap <Class , Integer > exceptionCounts = new ConcurrentHashMap <>();
6262 /** Whether or not the factory is "up" */
6363 private boolean up = true ;
6464 /**
@@ -84,8 +84,8 @@ public class ResilientPooledObjectFactory<T, E extends Exception> implements Poo
8484 * @param lookBack length of time over which metrics are kept
8585 * @param timeBetweenChecks time between checks by the monitor thread
8686 */
87- public ResilientPooledObjectFactory (PooledObjectFactory <T , E > factory ,
88- int logSize , Duration delay , Duration lookBack , Duration timeBetweenChecks ) {
87+ public ResilientPooledObjectFactory (final PooledObjectFactory <T , E > factory ,
88+ final int logSize , final Duration delay , final Duration lookBack , final Duration timeBetweenChecks ) {
8989 this .logSize = logSize ;
9090 this .factory = factory ;
9191 this .delay = delay ;
@@ -99,20 +99,25 @@ public ResilientPooledObjectFactory(PooledObjectFactory<T, E> factory,
9999 *
100100 * @param factory PooledObjectFactory to wrap
101101 */
102- public ResilientPooledObjectFactory (PooledObjectFactory <T , E > factory ) {
102+ public ResilientPooledObjectFactory (final PooledObjectFactory <T , E > factory ) {
103103 this (factory , DEFAULT_LOG_SIZE , DEFAULT_DELAY , DEFAULT_LOOK_BACK , DEFAULT_TIME_BETWEEN_CHECKS );
104104 }
105105
106- public void setPool (GenericObjectPool <T , E > pool ) {
106+ /**
107+ * Sets the underlying pool. For tests.
108+ *
109+ * @param pool the underlying pool.
110+ */
111+ void setPool (final GenericObjectPool <T , E > pool ) {
107112 this .pool = pool ;
108113 }
109114
110115 /**
111116 * Set the time between monitor checks.
112117 *
113- * @param timeBetweenChecks
118+ * @param timeBetweenChecks The time between monitor checks.
114119 */
115- public void setTimeBetweenChecks (Duration timeBetweenChecks ) {
120+ public void setTimeBetweenChecks (final Duration timeBetweenChecks ) {
116121 this .timeBetweenChecks = timeBetweenChecks ;
117122 }
118123
@@ -121,7 +126,7 @@ public void setTimeBetweenChecks(Duration timeBetweenChecks) {
121126 *
122127 * @param logSize the number of makeObject events to keep in the log
123128 */
124- public void setLogSize (int logSize ) {
129+ public void setLogSize (final int logSize ) {
125130 this .logSize = logSize ;
126131 }
127132
@@ -132,10 +137,10 @@ public void setLogSize(int logSize) {
132137 public PooledObject <T > makeObject () throws E {
133138 final MakeEvent makeEvent = new MakeEvent ();
134139 try {
135- PooledObject <T > obj = factory .makeObject ();
140+ final PooledObject <T > obj = factory .makeObject ();
136141 makeEvent .setSuccess (!PooledObject .isNull (obj ));
137142 return obj ;
138- } catch (Throwable t ) {
143+ } catch (final Throwable t ) {
139144 makeEvent .setSuccess (false );
140145 makeEvent .setException (t );
141146 exceptionCounts .put (t .getClass (), exceptionCounts .getOrDefault (t , 0 ) + 1 );
@@ -149,22 +154,22 @@ public PooledObject<T> makeObject() throws E {
149154 // Delegate all other methods to the wrapped factory.
150155
151156 @ Override
152- public void destroyObject (PooledObject <T > p ) throws E {
157+ public void destroyObject (final PooledObject <T > p ) throws E {
153158 factory .destroyObject (p );
154159 }
155160
156161 @ Override
157- public boolean validateObject (PooledObject <T > p ) {
162+ public boolean validateObject (final PooledObject <T > p ) {
158163 return factory .validateObject (p );
159164 }
160165
161166 @ Override
162- public void activateObject (PooledObject <T > p ) throws E {
167+ public void activateObject (final PooledObject <T > p ) throws E {
163168 factory .activateObject (p );
164169 }
165170
166171 @ Override
167- public void passivateObject (PooledObject <T > p ) throws E {
172+ public void passivateObject (final PooledObject <T > p ) throws E {
168173 factory .passivateObject (p );
169174 }
170175
@@ -195,7 +200,7 @@ protected void runChecks() {
195200 while (makeObjectLog .size () > logSize ) {
196201 makeObjectLog .poll ();
197202 }
198- for (MakeEvent makeEvent : makeObjectLog ) {
203+ for (final MakeEvent makeEvent : makeObjectLog ) {
199204 if (!makeEvent .isSuccess ()) {
200205 upOverLog = false ;
201206 downStart = Instant .now ();
@@ -242,7 +247,7 @@ public boolean isMonitorRunning() {
242247 *
243248 * @param timeBetweenChecks time between checks
244249 */
245- public void startMonitor (Duration timeBetweenChecks ) {
250+ public void startMonitor (final Duration timeBetweenChecks ) {
246251 this .timeBetweenChecks = timeBetweenChecks ;
247252 startMonitor ();
248253 }
@@ -277,7 +282,7 @@ public void stopMonitor() {
277282 class Adder extends Thread {
278283 private boolean killed = false ;
279284 private boolean running = false ;
280- private int MAX_FAILURES = 5 ;
285+ private final int MAX_FAILURES = 5 ;
281286 private int failures = 0 ;
282287
283288 @ Override
@@ -289,7 +294,7 @@ public void run() {
289294 if (pool .getNumWaiters () == 0 || pool .getNumActive () + pool .getNumIdle () == pool .getMaxTotal ()) {
290295 kill ();
291296 }
292- } catch (Throwable e ) {
297+ } catch (final Throwable e ) {
293298 failures ++;
294299 if (failures > MAX_FAILURES ) {
295300 kill ();
@@ -298,7 +303,7 @@ public void run() {
298303 // Wait for delay
299304 try {
300305 sleep (delay .toMillis ());
301- } catch (InterruptedException e ) {
306+ } catch (final InterruptedException e ) {
302307 killed = true ;
303308 }
304309 }
@@ -358,7 +363,7 @@ public boolean isSuccess() {
358363 *
359364 * @param success
360365 */
361- public void setSuccess (boolean success ) {
366+ public void setSuccess (final boolean success ) {
362367 this .success = success ;
363368 }
364369
@@ -374,7 +379,7 @@ public Throwable getException() {
374379 *
375380 * @param exception
376381 */
377- public void setException (Throwable exception ) {
382+ public void setException (final Throwable exception ) {
378383 this .exception = exception ;
379384 }
380385
@@ -396,9 +401,9 @@ public void run() {
396401 runChecks ();
397402 try {
398403 sleep (timeBetweenChecks .toMillis ());
399- } catch (InterruptedException e ) {
404+ } catch (final InterruptedException e ) {
400405 monitoring = false ;
401- } catch (Throwable e ) {
406+ } catch (final Throwable e ) {
402407 monitoring = false ;
403408 throw e ;
404409 }
@@ -453,7 +458,7 @@ public Duration getLookBack() {
453458 * @return a copy of the makeObject log
454459 */
455460 public List <MakeEvent > getMakeObjectLog () {
456- ArrayList <MakeEvent > makeObjectLog = new ArrayList <>();
461+ final ArrayList <MakeEvent > makeObjectLog = new ArrayList <>();
457462 return new ArrayList <>(makeObjectLog .stream ().toList ());
458463 }
459464
0 commit comments