2323import java .io .Closeable ;
2424import java .util .concurrent .ArrayBlockingQueue ;
2525import java .util .concurrent .BlockingQueue ;
26- import java .util .concurrent .Callable ;
2726import java .util .concurrent .ExecutorService ;
2827import java .util .concurrent .Executors ;
2928import java .util .concurrent .ThreadFactory ;
@@ -57,13 +56,13 @@ public class ConnectionStateManager implements Closeable {
5756 }
5857
5958 private final Logger log = LoggerFactory .getLogger (getClass ());
60- private final BlockingQueue <ConnectionState > eventQueue = new ArrayBlockingQueue <ConnectionState >(QUEUE_SIZE );
59+ private final BlockingQueue <ConnectionState > eventQueue = new ArrayBlockingQueue <>(QUEUE_SIZE );
6160 private final CuratorFramework client ;
6261 private final int sessionTimeoutMs ;
6362 private final int sessionExpirationPercent ;
6463 private final AtomicBoolean initialConnectMessageSent = new AtomicBoolean (false );
6564 private final ExecutorService service ;
66- private final AtomicReference <State > state = new AtomicReference <State >(State .LATENT );
65+ private final AtomicReference <State > state = new AtomicReference <>(State .LATENT );
6766 private final UnaryListenerManager <ConnectionStateListener > listeners ;
6867
6968 // guarded by sync
@@ -80,9 +79,9 @@ private enum State {
8079 }
8180
8281 /**
83- * @param client the client
84- * @param threadFactory thread factory to use or null for a default
85- * @param sessionTimeoutMs the ZK session timeout in milliseconds
82+ * @param client the client
83+ * @param threadFactory thread factory to use or null for a default
84+ * @param sessionTimeoutMs the ZK session timeout in milliseconds
8685 * @param sessionExpirationPercent percentage of negotiated session timeout to use when simulating a session timeout. 0 means don't simulate at all
8786 */
8887 public ConnectionStateManager (
@@ -96,11 +95,11 @@ public ConnectionStateManager(
9695 }
9796
9897 /**
99- * @param client the client
100- * @param threadFactory thread factory to use or null for a default
101- * @param sessionTimeoutMs the ZK session timeout in milliseconds
98+ * @param client the client
99+ * @param threadFactory thread factory to use or null for a default
100+ * @param sessionTimeoutMs the ZK session timeout in milliseconds
102101 * @param sessionExpirationPercent percentage of negotiated session timeout to use when simulating a session timeout. 0 means don't simulate at all
103- * @param managerFactory manager factory to use
102+ * @param managerFactory manager factory to use
104103 */
105104 public ConnectionStateManager (
106105 CuratorFramework client ,
@@ -124,12 +123,9 @@ public ConnectionStateManager(
124123 public void start () {
125124 Preconditions .checkState (state .compareAndSet (State .LATENT , State .STARTED ), "Cannot be started more than once" );
126125
127- service .submit (new Callable <Object >() {
128- @ Override
129- public Object call () throws Exception {
130- processEvents ();
131- return null ;
132- }
126+ service .submit (() -> {
127+ processEvents ();
128+ return null ;
133129 });
134130 }
135131
@@ -173,7 +169,7 @@ public synchronized boolean setToSuspended() {
173169
174170 /**
175171 * Post a state change. If the manager is already in that state the change
176- * is ignored. Otherwise the change is queued for listeners.
172+ * is ignored. Otherwise, the change is queued for listeners.
177173 *
178174 * @param newConnectionState new state
179175 * @return true if the state actually changed, false if it was already at that state
@@ -228,7 +224,7 @@ public synchronized boolean isConnected() {
228224 }
229225
230226 private void postState (ConnectionState state ) {
231- log .info ("State change: " + state );
227+ log .info ("State change: {}" , state );
232228
233229 notifyAll ();
234230
@@ -265,7 +261,7 @@ private void processEvents() {
265261 && client .getZookeeperClient ().isConnected ()) {
266262 // CURATOR-525 - there is a race whereby LOST is sometimes set after the connection has been
267263 // repaired
268- // this "hack" fixes it by forcing the state to RECONNECTED
264+ // this "hack" fixes it by forcing the state to " RECONNECTED"
269265 log .warn ("ConnectionState is LOST but isConnected() is true. Forcing RECONNECTED." );
270266 addStateChange (ConnectionState .RECONNECTED );
271267 }
@@ -286,9 +282,10 @@ private void checkSessionExpiration() {
286282 startOfSuspendedEpoch =
287283 System .currentTimeMillis (); // reset startOfSuspendedEpoch to avoid spinning on this session
288284 // expiration injection CURATOR-405
289- log .warn (String .format (
290- "Session timeout has elapsed while SUSPENDED. Injecting a session expiration. Elapsed ms: %d. Adjusted session timeout ms: %d" ,
291- elapsedMs , useSessionTimeoutMs ));
285+ log .warn (
286+ "Session timeout has elapsed while SUSPENDED. Injecting a session expiration. Elapsed ms: {}. Adjusted session timeout ms: {}" ,
287+ elapsedMs ,
288+ useSessionTimeoutMs );
292289 try {
293290 if (lastExpiredInstanceIndex == client .getZookeeperClient ().getInstanceIndex ()) {
294291 // last expiration didn't work for this instance, so event thread is dead and a reset is needed.
0 commit comments