Search in sources :

Example 6 with ChannelFactory

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

the class ApplicationContext method clientBootstrap.

@Bean(destroyMethod = "releaseExternalResources")
public ClientBootstrap clientBootstrap() {
    final ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    final ChannelPipelineFactory pipelineFactory = () -> {
        final ChannelPipeline pipeline = ApplicationContext.this.createPipeLine();
        LOGGER.info("Created new client 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) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 7 with ChannelFactory

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

use of org.jboss.netty.channel.ChannelFactory in project pinpoint by naver.

the class DefaultPinpointClientFactory method release.

public void release() {
    if (this.closed.isClosed()) {
        return;
    }
    if (!this.closed.close()) {
        return;
    }
    if (!useExternalResource) {
        final ChannelFactory channelFactory = this.channelFactory;
        if (channelFactory != null) {
            channelFactory.releaseExternalResources();
        }
        Set<Timeout> stop = this.timer.stop();
        if (!stop.isEmpty()) {
            logger.info("stop Timeout:{}", stop.size());
        }
    // stop, cancel something?
    }
}
Also used : Timeout(org.jboss.netty.util.Timeout) ChannelFactory(org.jboss.netty.channel.ChannelFactory)

Example 9 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project pinpoint by naver.

the class ThriftModule method configure.

@Override
protected void configure() {
    logger.info("configure {}", this.getClass().getSimpleName());
    ThriftTransportConfig thriftTransportConfig = loadThriftTransportConfig();
    bind(ThriftTransportConfig.class).toInstance(thriftTransportConfig);
    bind(TransactionIdEncoder.class).to(DefaultTransactionIdEncoder.class).in(Scopes.SINGLETON);
    Key<CommandDispatcher> commandDispatcher = Key.get(CommandDispatcher.class);
    bind(commandDispatcher).toProvider(CommandDispatcherProvider.class).in(Scopes.SINGLETON);
    // expose(commandDispatcher);
    TypeLiteral<SpanProcessor<TSpan, TSpanChunk>> spanPostProcessorType = new TypeLiteral<SpanProcessor<TSpan, TSpanChunk>>() {
    };
    bind(spanPostProcessorType).toProvider(SpanProcessorProvider.class).in(Scopes.SINGLETON);
    bind(ConnectionFactoryProvider.class).toProvider(ConnectionFactoryProviderProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> pinpointClientFactory = Key.get(PinpointClientFactory.class, DefaultClientFactory.class);
    bind(pinpointClientFactory).toProvider(PinpointClientFactoryProvider.class).in(Scopes.SINGLETON);
    // expose(pinpointClientFactory);
    bind(HeaderTBaseSerializer.class).toProvider(HeaderTBaseSerializerProvider.class).in(Scopes.SINGLETON);
    // EnhancedDataSender
    TypeLiteral<EnhancedDataSender<MetaDataType>> dataSenderTypeLiteral = new TypeLiteral<EnhancedDataSender<MetaDataType>>() {
    };
    bind(dataSenderTypeLiteral).toProvider(TcpDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(dataSenderTypeLiteral);
    // Bind AgentDataSender to EnhancedDataSender
    Key<EnhancedDataSender<MetaDataType>> agentDataSender = Key.get(dataSenderTypeLiteral, AgentDataSender.class);
    bind(agentDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON);
    expose(agentDataSender);
    // Bind MetadataDataSender to EnhancedDataSender
    Key<EnhancedDataSender<MetaDataType>> metadataDataSender = Key.get(dataSenderTypeLiteral, MetadataDataSender.class);
    bind(metadataDataSender).to(dataSenderTypeLiteral).in(Scopes.SINGLETON);
    expose(metadataDataSender);
    Key<Timer> spanStatConnectTimer = Key.get(Timer.class, SpanStatChannelFactory.class);
    bind(spanStatConnectTimer).toProvider(SpanStatConnectTimerProvider.class).in(Scopes.SINGLETON);
    Key<ChannelFactory> spanStatChannelFactory = Key.get(ChannelFactory.class, SpanStatChannelFactory.class);
    bind(spanStatChannelFactory).toProvider(SpanStatChannelFactoryProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> spanClientFactory = Key.get(PinpointClientFactory.class, SpanDataSender.class);
    bind(spanClientFactory).toProvider(SpanClientFactoryProvider.class).in(Scopes.SINGLETON);
    Key<PinpointClientFactory> statClientFactory = Key.get(PinpointClientFactory.class, StatDataSender.class);
    bind(statClientFactory).toProvider(StatClientFactoryProvider.class).in(Scopes.SINGLETON);
    TypeLiteral<MessageConverter<SpanType, TBase<?, ?>>> thriftMessageConverter = new TypeLiteral<MessageConverter<SpanType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<SpanType, TBase<?, ?>>> spanMessageConverterKey = Key.get(thriftMessageConverter, SpanDataSender.class);
    bind(spanMessageConverterKey).toProvider(SpanThriftMessageConverterProvider.class).in(Scopes.SINGLETON);
    // expose(spanMessageConverterKey);
    TypeLiteral<MessageConverter<MetaDataType, TBase<?, ?>>> metadataMessageConverter = new TypeLiteral<MessageConverter<MetaDataType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<MetaDataType, TBase<?, ?>>> metadataMessageConverterKey = Key.get(metadataMessageConverter, MetadataDataSender.class);
    bind(metadataMessageConverterKey).toProvider(MetadataMessageConverterProvider.class).in(Scopes.SINGLETON);
    // expose(metadataMessageConverterKey);
    // Stat Thrift Converter
    TypeLiteral<MessageConverter<MetricType, TBase<?, ?>>> statMessageConverter = new TypeLiteral<MessageConverter<MetricType, TBase<?, ?>>>() {
    };
    Key<MessageConverter<MetricType, TBase<?, ?>>> statMessageConverterKey = Key.get(statMessageConverter, StatDataSender.class);
    bind(statMessageConverterKey).toProvider(StatThriftMessageConverterProvider.class).in(Scopes.SINGLETON);
    TypeLiteral<DataSender<SpanType>> spanDataSenderType = new TypeLiteral<DataSender<SpanType>>() {
    };
    Key<DataSender<SpanType>> spanDataSender = Key.get(spanDataSenderType, SpanDataSender.class);
    bind(spanDataSender).toProvider(SpanDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(spanDataSender);
    TypeLiteral<DataSender<MetricType>> statDataSenderType = new TypeLiteral<DataSender<MetricType>>() {
    };
    Key<DataSender<MetricType>> statDataSender = Key.get(statDataSenderType, StatDataSender.class);
    bind(statDataSender).toProvider(StatDataSenderProvider.class).in(Scopes.SINGLETON);
    expose(statDataSender);
    // For AgentInfoSender
    // TypeLiteral<AgentInfoFactory> agentInfoFactoryTypeLiteral = new TypeLiteral<AgentInfoFactory>() {};
    // bind(agentInfoFactoryTypeLiteral).toProvider(AgentInfoFactoryProvider.class).in(Scopes.SINGLETON);
    // expose(agentInfoFactoryTypeLiteral);
    TypeLiteral<MessageConverter<Object, ResultResponse>> resultMessageConverter = new TypeLiteral<MessageConverter<Object, ResultResponse>>() {
    };
    Key<MessageConverter<Object, ResultResponse>> resultMessageConverterKey = Key.get(resultMessageConverter, ResultConverter.class);
    bind(resultMessageConverterKey).toProvider(ThriftMessageToResultConverterProvider.class).in(Scopes.SINGLETON);
    expose(resultMessageConverterKey);
    Key<ModuleLifeCycle> rpcModuleLifeCycleKey = Key.get(ModuleLifeCycle.class, Names.named("RPC-MODULE"));
    bind(rpcModuleLifeCycleKey).to(ThriftModuleLifeCycle.class).in(Scopes.SINGLETON);
    expose(rpcModuleLifeCycleKey);
}
Also used : MetadataMessageConverterProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.MetadataMessageConverterProvider) ResultResponse(com.navercorp.pinpoint.profiler.sender.ResultResponse) DefaultTransactionIdEncoder(com.navercorp.pinpoint.profiler.context.thrift.DefaultTransactionIdEncoder) PinpointClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.PinpointClientFactoryProvider) EnhancedDataSender(com.navercorp.pinpoint.profiler.sender.EnhancedDataSender) DataSender(com.navercorp.pinpoint.profiler.sender.DataSender) EnhancedDataSender(com.navercorp.pinpoint.profiler.sender.EnhancedDataSender) ConnectionFactoryProviderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.ConnectionFactoryProviderProvider) SpanThriftMessageConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.SpanThriftMessageConverterProvider) CommandDispatcherProvider(com.navercorp.pinpoint.profiler.context.provider.CommandDispatcherProvider) MetaDataType(com.navercorp.pinpoint.profiler.metadata.MetaDataType) SpanStatChannelFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatChannelFactoryProvider) ChannelFactory(org.jboss.netty.channel.ChannelFactory) MessageConverter(com.navercorp.pinpoint.profiler.context.thrift.MessageConverter) SpanType(com.navercorp.pinpoint.profiler.context.SpanType) HeaderTBaseSerializerProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.HeaderTBaseSerializerProvider) StatClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.StatClientFactoryProvider) ThriftMessageToResultConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.ThriftMessageToResultConverterProvider) DefaultThriftTransportConfig(com.navercorp.pinpoint.profiler.context.thrift.config.DefaultThriftTransportConfig) ThriftTransportConfig(com.navercorp.pinpoint.profiler.context.thrift.config.ThriftTransportConfig) StatThriftMessageConverterProvider(com.navercorp.pinpoint.profiler.context.thrift.StatThriftMessageConverterProvider) SpanDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanDataSenderProvider) MetricType(com.navercorp.pinpoint.profiler.monitor.metric.MetricType) SpanStatConnectTimerProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanStatConnectTimerProvider) TSpanChunk(com.navercorp.pinpoint.thrift.dto.TSpanChunk) TcpDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.TcpDataSenderProvider) SpanProcessor(com.navercorp.pinpoint.profiler.context.compress.SpanProcessor) SpanClientFactoryProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanClientFactoryProvider) TypeLiteral(com.google.inject.TypeLiteral) PinpointClientFactory(com.navercorp.pinpoint.rpc.client.PinpointClientFactory) CommandDispatcher(com.navercorp.pinpoint.profiler.receiver.CommandDispatcher) StatDataSenderProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.StatDataSenderProvider) Timer(org.jboss.netty.util.Timer) TSpan(com.navercorp.pinpoint.thrift.dto.TSpan) SpanProcessorProvider(com.navercorp.pinpoint.profiler.context.provider.thrift.SpanProcessorProvider) TBase(org.apache.thrift.TBase)

Example 10 with ChannelFactory

use of org.jboss.netty.channel.ChannelFactory in project hadoop by apache.

the class SimpleTcpServer method run.

public void run() {
    // Configure the Server.
    ChannelFactory factory;
    if (workerCount == 0) {
        // Use default workers: 2 * the number of available processors
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
    } else {
        factory = new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool(), workerCount);
    }
    server = new ServerBootstrap(factory);
    server.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, rpcProgram, RpcUtil.STAGE_RPC_TCP_RESPONSE);
        }
    });
    server.setOption("child.tcpNoDelay", true);
    server.setOption("child.keepAlive", true);
    server.setOption("child.reuseAddress", true);
    server.setOption("reuseAddress", true);
    // Listen to TCP port
    ch = server.bind(new InetSocketAddress(port));
    InetSocketAddress socketAddr = (InetSocketAddress) ch.getLocalAddress();
    boundPort = socketAddr.getPort();
    LOG.info("Started listening to TCP requests at port " + boundPort + " for " + rpcProgram + " with workerCount " + workerCount);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) InetSocketAddress(java.net.InetSocketAddress) 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