Search in sources :

Example 26 with ConnectionlessBootstrap

use of org.jboss.netty.bootstrap.ConnectionlessBootstrap in project traccar by traccar.

the class AtrackProtocol method initTrackerServers.

@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new AtrackFrameDecoder());
            pipeline.addLast("objectEncoder", new AtrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this));
        }
    });
    serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("objectEncoder", new AtrackProtocolEncoder());
            pipeline.addLast("objectDecoder", new AtrackProtocolDecoder(AtrackProtocol.this));
        }
    });
}
Also used : TrackerServer(org.traccar.TrackerServer) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 27 with ConnectionlessBootstrap

use of org.jboss.netty.bootstrap.ConnectionlessBootstrap in project traccar by traccar.

the class Tr900Protocol method initTrackerServers.

@Override
public void initTrackerServers(List<TrackerServer> serverList) {
    serverList.add(new TrackerServer(new ServerBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LineBasedFrameDecoder(1024));
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
        }
    });
    serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("objectDecoder", new Tr900ProtocolDecoder(Tr900Protocol.this));
        }
    });
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) LineBasedFrameDecoder(org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder) StringDecoder(org.jboss.netty.handler.codec.string.StringDecoder) TrackerServer(org.traccar.TrackerServer) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 28 with ConnectionlessBootstrap

use of org.jboss.netty.bootstrap.ConnectionlessBootstrap in project feeyo-hlsserver by variflight.

the class UdpServer method startup.

public void startup(int port) {
    ChannelFactory channelFactory = new NioDatagramChannelFactory(Executors.newCachedThreadPool());
    bootstrap = new ConnectionlessBootstrap(channelFactory);
    bootstrap.setOption("reuseAddress", false);
    bootstrap.setOption("child.reuseAddress", false);
    // 15M
    bootstrap.setOption("readBufferSize", 1024 * 1024 * 15);
    bootstrap.setOption("writeBufferSize", 1024 * 20);
    bootstrap.setOption("receiveBufferSizePredictor", new FixedReceiveBufferSizePredictor(1024 * 3));
    bootstrap.setOption("receiveBufferSizePredictorFactory", new FixedReceiveBufferSizePredictorFactory(1024 * 3));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("handler", new UdpServerChannelHandler());
            return pipeline;
        }
    });
    datagramChannel = (DatagramChannel) bootstrap.bind(new InetSocketAddress(port));
}
Also used : FixedReceiveBufferSizePredictor(org.jboss.netty.channel.FixedReceiveBufferSizePredictor) NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) InetSocketAddress(java.net.InetSocketAddress) NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) FixedReceiveBufferSizePredictorFactory(org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 29 with ConnectionlessBootstrap

use of org.jboss.netty.bootstrap.ConnectionlessBootstrap 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)

Example 30 with ConnectionlessBootstrap

use of org.jboss.netty.bootstrap.ConnectionlessBootstrap in project pinpoint by naver.

the class NettyUdpReceiverTest method server.

/*
    * netty io thread is single-threaded even for udp.
    * this is for running multiple workers.
    * */
@Test
public void server() throws IOException, InterruptedException {
    final ConnectionlessBootstrap udpServer = createUdpServer();
    Thread thread = new Thread(new Runnable() {

        @Override
        public void run() {
            udpServer.bind(new InetSocketAddress("127.0.0.1", PORT));
            try {
                logger.debug("server-await");
                latch.await();
            } catch (InterruptedException ignored) {
            }
            logger.debug("server-shutdown");
            udpServer.shutdown();
        }
    });
    thread.start();
    Thread.sleep(1000);
    logger.debug("start--------");
    //        ExecutorService executorService = Executors.newFixedThreadPool(10);
    //        for (int i =0; i< 10; i++) {
    //            executorService.execute(new Runnable() {
    //                @Override
    //                public void run() {
    //                    try {
    start();
    //                    } catch (IOException e) {
    //                        e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    //                    }
    //                }
    //            });
    //        }
    //        executorService.awaitTermination(120, TimeUnit.SECONDS) ;
    latch.countDown();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap) Test(org.junit.Test)

Aggregations

ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)61 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)50 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)47 TrackerServer (org.traccar.TrackerServer)46 StringEncoder (org.jboss.netty.handler.codec.string.StringEncoder)24 StringDecoder (org.jboss.netty.handler.codec.string.StringDecoder)20 NioDatagramChannelFactory (org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory)10 CharacterDelimiterFrameDecoder (org.traccar.CharacterDelimiterFrameDecoder)10 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)8 InetSocketAddress (java.net.InetSocketAddress)7 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)4 FixedReceiveBufferSizePredictorFactory (org.jboss.netty.channel.FixedReceiveBufferSizePredictorFactory)4 LineBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LineBasedFrameDecoder)4 DatagramChannelFactory (org.jboss.netty.channel.socket.DatagramChannelFactory)3 IOException (java.io.IOException)2 Map (java.util.Map)2 Channel (org.jboss.netty.channel.Channel)2 FixedLengthFrameDecoder (org.jboss.netty.handler.codec.frame.FixedLengthFrameDecoder)2 Test (org.junit.Test)2 ServerPipelineFactory (com.jcumulus.server.rtmfp.ServerPipelineFactory)1