Search in sources :

Example 1 with DatagramChannelFactory

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;
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) DatagramChannelFactory(org.jboss.netty.channel.socket.DatagramChannelFactory) NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) IOException(java.io.IOException) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 2 with DatagramChannelFactory

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);
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) InetSocketAddress(java.net.InetSocketAddress) DatagramChannelFactory(org.jboss.netty.channel.socket.DatagramChannelFactory) NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Aggregations

ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)2 DatagramChannelFactory (org.jboss.netty.channel.socket.DatagramChannelFactory)2 NioDatagramChannelFactory (org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory)2 IOException (java.io.IOException)1 InetSocketAddress (java.net.InetSocketAddress)1