Search in sources :

Example 51 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project traccar by tananaev.

the class RitiProtocol method initTrackerServers.

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

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("frameDecoder", new LengthFieldBasedFrameDecoder(1024, 105, 2, 3, 0));
            pipeline.addLast("objectDecoder", new RitiProtocolDecoder(RitiProtocol.this));
        }
    };
    server.setEndianness(ByteOrder.LITTLE_ENDIAN);
    serverList.add(server);
}
Also used : TrackerServer(org.traccar.TrackerServer) LengthFieldBasedFrameDecoder(org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 52 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project traccar by tananaev.

the class XirgoProtocol 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 CharacterDelimiterFrameDecoder(1024, "##"));
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("stringDecoder", new StringDecoder());
            pipeline.addLast("objectEncoder", new XirgoProtocolEncoder());
            pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(XirgoProtocol.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("objectEncoder", new XirgoProtocolEncoder());
            pipeline.addLast("objectDecoder", new XirgoProtocolDecoder(XirgoProtocol.this));
        }
    });
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) CharacterDelimiterFrameDecoder(org.traccar.CharacterDelimiterFrameDecoder) 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 53 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project traccar by tananaev.

the class WondexProtocol 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 WondexFrameDecoder());
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
            pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
        }
    });
    serverList.add(new TrackerServer(new ConnectionlessBootstrap(), getName()) {

        @Override
        protected void addSpecificHandlers(ChannelPipeline pipeline) {
            pipeline.addLast("stringEncoder", new StringEncoder());
            pipeline.addLast("objectEncoder", new WondexProtocolEncoder());
            pipeline.addLast("objectDecoder", new WondexProtocolDecoder(WondexProtocol.this));
        }
    });
}
Also used : StringEncoder(org.jboss.netty.handler.codec.string.StringEncoder) TrackerServer(org.traccar.TrackerServer) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 54 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project hive by apache.

the class ShuffleHandler method stop.

protected void stop() throws Exception {
    accepted.close().awaitUninterruptibly(10, TimeUnit.SECONDS);
    if (selector != null) {
        ServerBootstrap bootstrap = new ServerBootstrap(selector);
        bootstrap.releaseExternalResources();
    }
    if (pipelineFact != null) {
        pipelineFact.destroy();
    }
    if (timer != null) {
        // Release this shared timer resource
        timer.stop();
    }
    if (dirWatcher != null) {
        dirWatcher.stop();
    }
}
Also used : ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 55 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project camel by apache.

the class SingleTCPNettyServerBootstrapFactory method startServerBootstrap.

protected void startServerBootstrap() {
    // prefer using explicit configured thread pools
    BossPool bp = configuration.getBossPool();
    WorkerPool wp = configuration.getWorkerPool();
    if (bp == null) {
        // create new pool which we should shutdown when stopping as its not shared
        bossPool = new NettyServerBossPoolBuilder().withBossCount(configuration.getBossCount()).withName("NettyServerTCPBoss").build();
        bp = bossPool;
    }
    if (wp == null) {
        // create new pool which we should shutdown when stopping as its not shared
        workerPool = new NettyWorkerPoolBuilder().withWorkerCount(configuration.getWorkerCount()).withName("NettyServerTCPWorker").build();
        wp = workerPool;
    }
    channelFactory = new NioServerSocketChannelFactory(bp, wp);
    serverBootstrap = new ServerBootstrap(channelFactory);
    serverBootstrap.setOption("child.keepAlive", configuration.isKeepAlive());
    serverBootstrap.setOption("child.tcpNoDelay", configuration.isTcpNoDelay());
    serverBootstrap.setOption("reuseAddress", configuration.isReuseAddress());
    serverBootstrap.setOption("child.reuseAddress", configuration.isReuseAddress());
    serverBootstrap.setOption("child.connectTimeoutMillis", configuration.getConnectTimeout());
    if (configuration.getBacklog() > 0) {
        serverBootstrap.setOption("backlog", configuration.getBacklog());
    }
    // set any additional netty options
    if (configuration.getOptions() != null) {
        for (Map.Entry<String, Object> entry : configuration.getOptions().entrySet()) {
            serverBootstrap.setOption(entry.getKey(), entry.getValue());
        }
    }
    LOG.debug("Created ServerBootstrap {} with options: {}", serverBootstrap, serverBootstrap.getOptions());
    // set the pipeline factory, which creates the pipeline for each newly created channels
    serverBootstrap.setPipelineFactory(pipelineFactory);
    LOG.info("ServerBootstrap binding to {}:{}", configuration.getHost(), configuration.getPort());
    channel = serverBootstrap.bind(new InetSocketAddress(configuration.getHost(), configuration.getPort()));
    // to keep track of all channels in use
    allChannels.add(channel);
}
Also used : BossPool(org.jboss.netty.channel.socket.nio.BossPool) WorkerPool(org.jboss.netty.channel.socket.nio.WorkerPool) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) Map(java.util.Map) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Aggregations

ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)94 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)58 TrackerServer (org.traccar.TrackerServer)42 InetSocketAddress (java.net.InetSocketAddress)38 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)34 ConnectionlessBootstrap (org.jboss.netty.bootstrap.ConnectionlessBootstrap)25 StringEncoder (org.jboss.netty.handler.codec.string.StringEncoder)16 Channel (org.jboss.netty.channel.Channel)13 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)12 StringDecoder (org.jboss.netty.handler.codec.string.StringDecoder)12 LengthFieldBasedFrameDecoder (org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder)11 ChannelFactory (org.jboss.netty.channel.ChannelFactory)8 ExecutorService (java.util.concurrent.ExecutorService)5 DefaultChannelGroup (org.jboss.netty.channel.group.DefaultChannelGroup)5 Test (org.junit.Test)5 HostnamePort (org.neo4j.helpers.HostnamePort)5 CharacterDelimiterFrameDecoder (org.traccar.CharacterDelimiterFrameDecoder)5 IOException (java.io.IOException)4 ChannelException (org.jboss.netty.channel.ChannelException)4 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)4