public String getNextServer() { if (serversRing.size() > 0) { try { return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } catch (IndexOutOfBoundsException outOfBoundsException) { // In the very rare case where nextServerIndex overflowed, this will end up with a negative number, // resulting in an IndexOutOfBoundsException. // We should then start back at the beginning of the server list. // Note that this might happen on several threads at once, in which the reset might happen a few times log.info("Resetting next server index"); nextServerIndex.set(0); return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } } else { throw new NoServerConfiguredException("No Server is assigned to client to connect"); } }
public String getNextServer() { if (serversRing.size() > 0) { try { return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } catch (IndexOutOfBoundsException outOfBoundsException) { // In the very rare case where nextServerIndex overflowed, this will end up with a negative number, // resulting in an IndexOutOfBoundsException. // We should then start back at the beginning of the server list. // Note that this might happen on several threads at once, in which the reset might happen a few times log.info("Resetting next server index"); nextServerIndex.set(0); return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } } else { throw new NoServerConfiguredException("No Server is assigned to client to connect"); } }
public String getNextServer() { if (serversRing.size() > 0) { try { return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } catch (IndexOutOfBoundsException outOfBoundsException) { // In the very rare case where nextServerIndex overflowed, this will end up with a negative number, // resulting in an IndexOutOfBoundsException. // We should then start back at the beginning of the server list. // Note that this might happen on several threads at once, in which the reset might happen a few times log.info("Resetting next server index"); nextServerIndex.set(0); return serversRing.get(nextServerIndex.getAndIncrement() % serversRing.size()); } } else { throw new NoServerConfiguredException("No Server is assigned to client to connect"); } }