}
// Create ServerSocket for peers
ServerSocket peerSS = createServerSocketWithinPortRange();
if (peerSS == null) {
logger.info("Insufficient Capacity");
Message errorResponse = relayAllocationMessage.buildFailureResponse(
STUNErrorCode.INSUFFICIENT_CAPACITY, "Insufficient Capacity");
controlConnectionWriter.writeMessage(errorResponse);
} else {
// TODO listener tasks in threadpool, listener also in pool?
logger.info("Created allocation on {}", peerSS.getLocalSocketAddress());
SocketListener peerSocketListener = new SocketListener(peerSS, Executors.newCachedThreadPool(),
new PeerHandlerTaskFactory(connIDToQueue, controlConnectionWriter, relayExecutor));
controlConnectionHandlerExecutor.execute(new RefreshMessageHandlerTask(controlConnection,
controlConnectionWriter, lifetime, peerSocketListener));
peerSocketListener.start();
Message successResponse = relayAllocationMessage.buildSuccessResponse();
successResponse.addAttribute(new XorMappedAddress(new InetSocketAddress(peerSS.getInetAddress(), peerSS
.getLocalPort())));
successResponse.addAttribute(new EndpointClass(EndpointCategory.RELAY));
successResponse.addAttribute(new RelayingLifetime(lifetime));
controlConnectionWriter.writeMessage(successResponse);
}
} catch (IOException e) {
logger.error("IOException while handling allocation request: {}", e);
}