Search in sources :

Example 56 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project Protocol-Adapter-IEC61850 by OSGP.

the class Iec61850Config method serverBootstrap.

/**
     * Returns a ServerBootstrap setting up a server pipeline listening for
     * incoming IEC61850 register device requests.
     *
     * @return an IEC61850 server bootstrap.
     */
@Bean(destroyMethod = "releaseExternalResources")
public ServerBootstrap serverBootstrap() {
    final ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    final ServerBootstrap bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws ProtocolAdapterException {
            final ChannelPipeline pipeline = Iec61850Config.this.createChannelPipeline(Iec61850Config.this.iec61850ChannelHandlerServer());
            LOGGER.info("Created new IEC61850 handler pipeline for server");
            return pipeline;
        }
    });
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", false);
    bootstrap.bind(new InetSocketAddress(this.iec61850PortListener()));
    return bootstrap;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) Bean(org.springframework.context.annotation.Bean)

Example 57 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project NabAlive by jcheype.

the class HttpServer method start.

public void start() {
    //Timer timer = new HashedWheelTimer();
    System.out.println("Runtime.getRuntime().availableProcessors(): " + Runtime.getRuntime().availableProcessors());
    //        ExecutorService bossExec = new OrderedMemoryAwareThreadPoolExecutor(2, 400000000, 2000000000, 60, TimeUnit.SECONDS);
    //        ExecutorService ioExec = new OrderedMemoryAwareThreadPoolExecutor(Runtime.getRuntime().availableProcessors() + 1, 400000000, 2000000000, 60, TimeUnit.SECONDS);
    //
    //        bootstrap = new ServerBootstrap(
    //                new NioServerSocketChannelFactory(bossExec, ioExec, Runtime.getRuntime().availableProcessors() + 1));
    // Configure the server.
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", true);
    bootstrap.setOption("receiveBufferSize", 128 * 1024);
    bootstrap.setOption("sendBufferSize", 128 * 1024);
    bootstrap.setOption("reuseAddress", true);
    bootstrap.setOption("backlog", 16384);
    final HttpApiServerHandler httpApiServerHandler = new HttpApiServerHandler(restHandler);
    // Set up the event pipeline factory.
    bootstrap.setPipelineFactory(new HttpApiServerPipelineFactory(httpApiServerHandler));
    // Bind and start to accept incoming connections.
    Channel c = bootstrap.bind(new InetSocketAddress(port));
    cg.add(c);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap)

Example 58 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project NabAlive by jcheype.

the class NabaliveServer method start.

@PostConstruct
public void start() {
    logger.info("Starting server.");
    // Configure the server.
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // Set up the pipeline factory.
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("timeout", new IdleStateHandler(timer, 0, 0, 20));
            pipeline.addLast("nabaliveServerHandler", nabaliveServerHandler);
            return pipeline;
        }
    });
    bootstrap.setOption("reuseAddress", true);
    // Bind and start to accept incoming connections.
    bind = bootstrap.bind(new InetSocketAddress(XMPP_PORT));
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) IdleStateHandler(org.jboss.netty.handler.timeout.IdleStateHandler) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) PostConstruct(javax.annotation.PostConstruct)

Example 59 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project databus by linkedin.

the class DummyHttpRequestHandler method setupServer.

private void setupServer(DummyHttpRequestHandler requestHandler) {
    _serverBootstrap = new ServerBootstrap(new DefaultLocalServerChannelFactory());
    ChannelPipeline serverPipeline = pipeline();
    serverPipeline.addLast("server logger 1", new LoggingHandler("server logger 1", InternalLogLevel.DEBUG, true));
    serverPipeline.addLast("decoder", new HttpRequestDecoder());
    serverPipeline.addLast("encoder", new HttpResponseEncoder());
    serverPipeline.addLast("server loggger 5", new LoggingHandler("server logger 5", InternalLogLevel.DEBUG, true));
    serverPipeline.addLast("handler", requestHandler);
    _serverBootstrap.setPipeline(serverPipeline);
    _serverAddress = new LocalAddress(1);
    _serverChannel = _serverBootstrap.bind(_serverAddress);
}
Also used : HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) DefaultLocalServerChannelFactory(org.jboss.netty.channel.local.DefaultLocalServerChannelFactory) LoggingHandler(org.jboss.netty.handler.logging.LoggingHandler) LocalAddress(org.jboss.netty.channel.local.LocalAddress) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 60 with ServerBootstrap

use of org.jboss.netty.bootstrap.ServerBootstrap in project crate by crate.

the class PostgresNetty method doStart.

@Override
protected void doStart() {
    if (!enabled) {
        return;
    }
    bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-boss")), Executors.newCachedThreadPool(daemonThreadFactory(settings, "postgres-netty-worker"))));
    bootstrap.setOption("child.tcpNoDelay", settings.getAsBoolean("tcp_no_delay", true));
    bootstrap.setOption("child.keepAlive", settings.getAsBoolean("tcp_keep_alive", true));
    bootstrap.setPipelineFactory(() -> {
        ChannelPipeline pipeline = Channels.pipeline();
        ConnectionContext connectionContext = new ConnectionContext(sqlOperations);
        pipeline.addLast("frame-decoder", connectionContext.decoder);
        pipeline.addLast("handler", connectionContext.handler);
        return pipeline;
    });
    boolean success = false;
    try {
        boundAddress = resolveBindAddress();
        namedLogger.info("{}", boundAddress);
        success = true;
    } finally {
        if (!success) {
            // stop boss/worker threads to avoid leaks
            doStop();
        }
    }
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

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