From 1de96ae7693374aca65a5dcce110cc1ae20fd6d1 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 14 Oct 2017 13:47:34 +0200 Subject: [PATCH] Abstract methods for clarity --- .../network/connection/EndPointClient.java | 28 ++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/dorkbox/network/connection/EndPointClient.java b/src/dorkbox/network/connection/EndPointClient.java index 60e6fdbb..a048a87d 100644 --- a/src/dorkbox/network/connection/EndPointClient.java +++ b/src/dorkbox/network/connection/EndPointClient.java @@ -61,14 +61,34 @@ class EndPointClient extends EndPoint implements Runnab new Thread(this, "Bootstrap registration").start(); } + + // not protected by synchronized + private + BootstrapWrapper getNextBootstrap() { + int bootstrapToRegister = this.connectingBootstrap.getAndIncrement(); + + if (bootstrapToRegister == this.bootstraps.size()) { + return null; + } + + return this.bootstraps.get(bootstrapToRegister); + } + + // not protected by synchronized + private + boolean isRegistrationComplete() { + return this.connectingBootstrap.get() == this.bootstraps.size(); + } + @SuppressWarnings("AutoBoxing") @Override public void run() { synchronized (this.connectingBootstrap) { - int bootstrapToRegister = this.connectingBootstrap.getAndIncrement(); - - BootstrapWrapper bootstrapWrapper = this.bootstraps.get(bootstrapToRegister); + BootstrapWrapper bootstrapWrapper = getNextBootstrap(); + if (bootstrapWrapper == null) { + return; + } ChannelFuture future; @@ -116,7 +136,7 @@ class EndPointClient extends EndPoint implements Runnab protected boolean registerNextProtocol0() { synchronized (this.connectingBootstrap) { - this.registrationComplete = this.connectingBootstrap.get() == this.bootstraps.size(); + this.registrationComplete = isRegistrationComplete(); if (!this.registrationComplete) { registerNextProtocol(); }