protected ChannelServer createChannelServer(final RequestListener requestListener) throws IOException, URISyntaxException {
SynchChannelFactory factory = new SocketSynchChannelFactory();
AsynchChannelServer server = new SynchToAsynchChannelServerAdapter(factory.bindSynchChannel(new URI("tcp://localhost:0")));
server.setAcceptListener(new AcceptListener() {
public void onAccept(Channel channel) {
RequestChannel requestChannel = null;
try {
((SocketMetadata)channel.narrow(SocketMetadata.class)).setTcpNoDelay(true);
requestChannel =
new AsynchChannelToServerRequestChannel(
new PacketAggregatingAsynchChannel(
SynchToAsynchChannelAdapter.adapt(channel)));
requestChannel.setRequestListener(requestListener);
requestChannel.start();
} catch (IOException e) {
if (requestChannel != null)
requestChannel.dispose();
else
channel.dispose();
}
}
public void onAcceptError(IOException error) {
error.printStackTrace();
}
});
serverURI = server.getConnectURI();
return server;
}