}
private final AtomicInteger sets = new AtomicInteger();
public Session selectSession() throws HandlerSocketException {
Session session = this.sessionList.get(this.sets.incrementAndGet()
% this.sessionList.size());
int retryCount = 0;
while ((session == null || session.isClosed()) && retryCount++ < 6) {
session = this.sessionList.get(this.sets.incrementAndGet()
% this.sessionList.size());
}
if (session == null || session.isClosed()) {
throw new HandlerSocketException(
"Could not find an open connection");
}
return session;
}