final byte[] buffer = new byte[BUFFER_SIZE];
while (server.isRunning()) {
int ready = 0;
for (Iterator<Session> selectedSessions = selector.select(); selectedSessions.hasNext(); ready++) {
Session session = selectedSessions.next();
try {
session.process(buffer);
} catch (SocketException e) {
if (server.isRunning() && log.isDebugEnabled()) {
log.debug("Connection closed: " + session.clientIp());
}
session.close();
} catch (Throwable e) {
if (server.isRunning()) {
log.error("Cannot process session from " + session.clientIp(), e);
}
session.close();
}
}
operations++;
sessions += ready;