private void processSessionRequests() throws IOReactorException {
ListenerEndpointImpl request;
while ((request = this.requestQueue.poll()) != null) {
final SocketAddress address = request.getAddress();
final ServerSocketChannel serverChannel;
try {
serverChannel = ServerSocketChannel.open();
} catch (final IOException ex) {
throw new IOReactorException("Failure opening server socket", ex);
}
try {
final ServerSocket socket = serverChannel.socket();
socket.setReuseAddress(this.config.isSoReuseAddress());
serverChannel.configureBlocking(false);
socket.bind(address);
} catch (final IOException ex) {
closeChannel(serverChannel);
request.failed(ex);
if (this.exceptionHandler == null || !this.exceptionHandler.handle(ex)) {
throw new IOReactorException("Failure binding socket to address "
+ address, ex);
} else {
return;
}
}
try {
final SelectionKey key = serverChannel.register(this.selector, SelectionKey.OP_ACCEPT);
key.attach(request);
request.setKey(key);
} catch (final IOException ex) {
closeChannel(serverChannel);
throw new IOReactorException("Failure registering channel " +
"with the selector", ex);
}
this.endpoints.add(request);
request.completed(serverChannel.socket().getLocalSocketAddress());
}
}