Search in sources :

Example 11 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project Protocol-Adapter-OSLP by OSGP.

the class ApplicationContext method serverBootstrapElster.

@Bean(destroyMethod = "releaseExternalResources")
public ServerBootstrap serverBootstrapElster() {
    final ChannelFactory factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    final ServerBootstrap bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(() -> {
        final ChannelPipeline pipeline = ApplicationContext.this.createPipeLine();
        LOGGER.info("Created new server pipeline");
        return pipeline;
    });
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", false);
    bootstrap.bind(new InetSocketAddress(this.oslpElsterPortServer()));
    return bootstrap;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 12 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project Protocol-Adapter-OSLP by OSGP.

the class OslpConfig method serverBootstrap.

@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 = OslpConfig.this.createChannelPipeline(OslpConfig.this.oslpChannelHandlerServer());
            LOGGER.info("Created server new pipeline");
            return pipeline;
        }
    });
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("child.keepAlive", false);
    bootstrap.bind(new InetSocketAddress(this.oslpPortServer()));
    return bootstrap;
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) ProtocolAdapterException(com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) 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 13 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project Protocol-Adapter-OSLP by OSGP.

the class OslpConfig method clientBootstrap.

@Bean(destroyMethod = "releaseExternalResources")
public ClientBootstrap clientBootstrap() {
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    final ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    final ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws ProtocolAdapterException {
            final ChannelPipeline pipeline = OslpConfig.this.createChannelPipeline(OslpConfig.this.oslpChannelHandlerClient());
            LOGGER.info("Created client new pipeline");
            return pipeline;
        }
    };
    final ClientBootstrap bootstrap = new ClientBootstrap(factory);
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", false);
    bootstrap.setOption("connectTimeoutMillis", this.connectionTimeout());
    bootstrap.setPipelineFactory(pipelineFactory);
    return bootstrap;
}
Also used : NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) ChannelFactory(org.jboss.netty.channel.ChannelFactory) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) Bean(org.springframework.context.annotation.Bean)

Example 14 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory 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 15 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project dubbo by alibaba.

the class NettyServer method doOpen.

@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    ExecutorService boss = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerBoss", true));
    ExecutorService worker = Executors.newCachedThreadPool(new NamedThreadFactory("NettyServerWorker", true));
    ChannelFactory channelFactory = new NioServerSocketChannelFactory(boss, worker, getUrl().getPositiveParameter(IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS));
    bootstrap = new ServerBootstrap(channelFactory);
    final NettyHandler nettyHandler = new NettyHandler(getUrl(), this);
    channels = nettyHandler.getChannels();
    // https://issues.jboss.org/browse/NETTY-365
    // https://issues.jboss.org/browse/NETTY-379
    // final Timer timer = new HashedWheelTimer(new NamedThreadFactory("NettyIdleTimer", true));
    bootstrap.setOption("child.tcpNoDelay", true);
    bootstrap.setOption("backlog", getUrl().getPositiveParameter(BACKLOG_KEY, Constants.DEFAULT_BACKLOG));
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyServer.this);
            ChannelPipeline pipeline = Channels.pipeline();
            /*int idleTimeout = getIdleTimeout();
                if (idleTimeout > 10000) {
                    pipeline.addLast("timer", new IdleStateHandler(timer, idleTimeout / 1000, 0, 0));
                }*/
            pipeline.addLast("decoder", adapter.getDecoder());
            pipeline.addLast("encoder", adapter.getEncoder());
            pipeline.addLast("handler", nettyHandler);
            return pipeline;
        }
    });
    // bind
    channel = bootstrap.bind(getBindAddress());
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) NamedThreadFactory(org.apache.dubbo.common.utils.NamedThreadFactory) ExecutorService(java.util.concurrent.ExecutorService) 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)

Aggregations

ChannelFactory (org.jboss.netty.channel.ChannelFactory)15 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)12 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)11 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)10 InetSocketAddress (java.net.InetSocketAddress)9 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)9 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)6 Bean (org.springframework.context.annotation.Bean)6 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)3 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)3 Channel (org.jboss.netty.channel.Channel)2 NamedThreadFactory (com.alibaba.dubbo.common.utils.NamedThreadFactory)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.iec61850.exceptions.ProtocolAdapterException)1 ProtocolAdapterException (com.alliander.osgp.adapter.protocol.oslp.elster.exceptions.ProtocolAdapterException)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 TypeLiteral (com.google.inject.TypeLiteral)1 SpanType (com.navercorp.pinpoint.profiler.context.SpanType)1 SpanProcessor (com.navercorp.pinpoint.profiler.context.compress.SpanProcessor)1 CommandDispatcherProvider (com.navercorp.pinpoint.profiler.context.provider.CommandDispatcherProvider)1 ConnectionFactoryProviderProvider (com.navercorp.pinpoint.profiler.context.provider.thrift.ConnectionFactoryProviderProvider)1