use of org.jboss.netty.channel.socket.DatagramChannelFactory in project pinpoint by naver.
the class NettyUdpReceiverTest method createUdpServer.
private ConnectionlessBootstrap createUdpServer() {
DatagramChannelFactory udpFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool(), 4);
ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
@Override
public ChannelPipeline getPipeline() throws Exception {
ChannelPipeline pipeline = Channels.pipeline();
pipeline.addLast("test", new SimpleChannelHandler() {
@Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) throws Exception {
String name = Thread.currentThread().getName();
logger.debug("sleep:{}", name);
Thread.sleep(10000);
// if (!name.equals("New I/O worker #1")) {
logger.debug("messageReceived thread-{} message:", Thread.currentThread().getName());
// }
}
});
return pipeline;
}
};
ConnectionlessBootstrap udpBootstrap = new ConnectionlessBootstrap(udpFactory);
udpBootstrap.setPipelineFactory(pipelineFactory);
return udpBootstrap;
}
use of org.jboss.netty.channel.socket.DatagramChannelFactory in project hadoop by apache.
the class SimpleUdpServer method run.
public void run() {
// Configure the client.
DatagramChannelFactory f = new NioDatagramChannelFactory(Executors.newCachedThreadPool(), workerCount);
server = new ConnectionlessBootstrap(f);
server.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_UDP_RESPONSE));
server.setOption("broadcast", "false");
server.setOption("sendBufferSize", SEND_BUFFER_SIZE);
server.setOption("receiveBufferSize", RECEIVE_BUFFER_SIZE);
server.setOption("reuseAddress", true);
// Listen to the UDP port
ch = server.bind(new InetSocketAddress(port));
InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
boundPort = socketAddr.getPort();
LOG.info("Started listening to UDP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount);
}
Aggregations