Search in sources :

Example 1 with ChannelPipelineFactory

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

the class Portmap method start.

void start(final int idleTimeMilliSeconds, final SocketAddress tcpAddress, final SocketAddress udpAddress) {
    tcpServer = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    tcpServer.setPipelineFactory(new ChannelPipelineFactory() {

        private final HashedWheelTimer timer = new HashedWheelTimer();

        private final IdleStateHandler idleStateHandler = new IdleStateHandler(timer, 0, 0, idleTimeMilliSeconds, TimeUnit.MILLISECONDS);

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            return Channels.pipeline(RpcUtil.constructRpcFrameDecoder(), RpcUtil.STAGE_RPC_MESSAGE_PARSER, idleStateHandler, handler, RpcUtil.STAGE_RPC_TCP_RESPONSE);
        }
    });
    tcpServer.setOption("reuseAddress", true);
    tcpServer.setOption("child.reuseAddress", true);
    udpServer = new ConnectionlessBootstrap(new NioDatagramChannelFactory(Executors.newCachedThreadPool()));
    udpServer.setPipeline(Channels.pipeline(RpcUtil.STAGE_RPC_MESSAGE_PARSER, handler, RpcUtil.STAGE_RPC_UDP_RESPONSE));
    udpServer.setOption("reuseAddress", true);
    tcpChannel = tcpServer.bind(tcpAddress);
    udpChannel = udpServer.bind(udpAddress);
    allChannels.add(tcpChannel);
    allChannels.add(udpChannel);
    LOG.info("Portmap server started at tcp://" + tcpChannel.getLocalAddress() + ", udp://" + udpChannel.getLocalAddress());
}
Also used : NioDatagramChannelFactory(org.jboss.netty.channel.socket.nio.NioDatagramChannelFactory) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) IdleStateHandler(org.jboss.netty.handler.timeout.IdleStateHandler) HashedWheelTimer(org.jboss.netty.util.HashedWheelTimer) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) ConnectionlessBootstrap(org.jboss.netty.bootstrap.ConnectionlessBootstrap)

Example 2 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project sockjs-netty by cgbystrom.

the class StressTestServer method start.

public void start() throws Exception {
    final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
    final ServiceRouter router = new ServiceRouter();
    reporter.start();
    router.setMetricRegistry(registry);
    Service echoService = new Service("/stresstest", new SessionCallbackFactory() {

        @Override
        public StressTestSession getSession(String id) throws Exception {
            return new StressTestSession();
        }
    });
    router.registerService(echoService);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Required for WS handshaker or else NPE.
            pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("preflight", new PreflightHandler());
            pipeline.addLast("router", router);
            return pipeline;
        }
    });
    bootstrap.bind(new LocalAddress(port));
}
Also used : LocalAddress(org.jboss.netty.channel.local.LocalAddress) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) JmxReporter(com.codahale.metrics.JmxReporter) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 3 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project sockjs-netty by cgbystrom.

the class TestServer method main.

public static void main(String[] args) {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    LoggerContext loggerContext = rootLogger.getLoggerContext();
    loggerContext.reset();
    PatternLayoutEncoder encoder = new PatternLayoutEncoder();
    encoder.setContext(loggerContext);
    encoder.setPattern("%-5level %-20class{0}: %message%n");
    encoder.start();
    ConsoleAppender<ILoggingEvent> appender = new ConsoleAppender<ILoggingEvent>();
    appender.setContext(loggerContext);
    appender.setEncoder(encoder);
    appender.start();
    rootLogger.addAppender(appender);
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    final MetricRegistry registry = new MetricRegistry();
    final JmxReporter reporter = JmxReporter.forRegistry(registry).build();
    reporter.start();
    final ServiceRouter router = new ServiceRouter();
    router.setMetricRegistry(registry);
    router.registerService(new Service("/disabled_websocket_echo", new DisabledWebSocketEchoSession()));
    router.registerService(new Service("/close", new CloseSession()));
    router.registerService(new Service("/amplify", new AmplifySession()));
    router.registerService(new Service("/broadcast", new SessionCallbackFactory() {

        @Override
        public BroadcastSession getSession(String id) throws Exception {
            return new BroadcastSession();
        }
    }));
    Service echoService = new Service("/echo", new SessionCallbackFactory() {

        @Override
        public EchoSession getSession(String id) throws Exception {
            return new EchoSession();
        }
    });
    echoService.setMaxResponseSize(4096);
    router.registerService(echoService);
    Service cookieNeededEcho = new Service("/cookie_needed_echo", new EchoSession());
    cookieNeededEcho.setMaxResponseSize(4096);
    cookieNeededEcho.setCookieNeeded(true);
    router.registerService(cookieNeededEcho);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        @Override
        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipeline = pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            // Required for WS handshaker or else NPE.
            pipeline.addLast("chunkAggregator", new HttpChunkAggregator(130 * 1024));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("preflight", new PreflightHandler());
            pipeline.addLast("router", router);
            return pipeline;
        }
    });
    bootstrap.bind(new InetSocketAddress(8090));
    System.out.println("Server running..");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) InetSocketAddress(java.net.InetSocketAddress) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) BroadcastSession(com.cgbystrom.sockjs.test.BroadcastSession) LoggerContext(ch.qos.logback.classic.LoggerContext) JmxReporter(com.codahale.metrics.JmxReporter) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 4 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project weave by continuuity.

the class TrackerService method startUp.

@Override
protected void startUp() throws Exception {
    Executor bossThreads = Executors.newFixedThreadPool(NUM_BOSS_THREADS, new ThreadFactoryBuilder().setDaemon(true).setNameFormat("boss-thread").build());
    Executor workerThreads = Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("worker-thread#%d").build());
    ChannelFactory factory = new NioServerSocketChannelFactory(bossThreads, workerThreads);
    bootstrap = new ServerBootstrap(factory);
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() {
            ChannelPipeline pipeline = Channels.pipeline();
            pipeline.addLast("decoder", new HttpRequestDecoder());
            pipeline.addLast("aggregator", new HttpChunkAggregator(MAX_INPUT_SIZE));
            pipeline.addLast("encoder", new HttpResponseEncoder());
            pipeline.addLast("compressor", new HttpContentCompressor());
            pipeline.addLast("handler", new ReportHandler(resourceReport));
            return pipeline;
        }
    });
    Channel channel = bootstrap.bind(new InetSocketAddress(host, 0));
    bindAddress = (InetSocketAddress) channel.getLocalAddress();
    url = URI.create(String.format("http://%s:%d", host, bindAddress.getPort())).resolve(TrackerService.PATH).toURL();
    channelGroup.add(channel);
}
Also used : NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HttpContentCompressor(org.jboss.netty.handler.codec.http.HttpContentCompressor) InetSocketAddress(java.net.InetSocketAddress) Channel(org.jboss.netty.channel.Channel) HttpChunkAggregator(org.jboss.netty.handler.codec.http.HttpChunkAggregator) 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) HttpResponseEncoder(org.jboss.netty.handler.codec.http.HttpResponseEncoder) Executor(java.util.concurrent.Executor) HttpRequestDecoder(org.jboss.netty.handler.codec.http.HttpRequestDecoder) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory)

Example 5 with ChannelPipelineFactory

use of org.jboss.netty.channel.ChannelPipelineFactory in project canal by alibaba.

the class CanalServerWithNetty method start.

public void start() {
    super.start();
    if (!embeddedServer.isStart()) {
        embeddedServer.start();
    }
    this.bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
    // 构造对应的pipeline
    bootstrap.setPipelineFactory(new ChannelPipelineFactory() {

        public ChannelPipeline getPipeline() throws Exception {
            ChannelPipeline pipelines = Channels.pipeline();
            pipelines.addLast(FixedHeaderFrameDecoder.class.getName(), new FixedHeaderFrameDecoder());
            pipelines.addLast(HandshakeInitializationHandler.class.getName(), new HandshakeInitializationHandler());
            pipelines.addLast(ClientAuthenticationHandler.class.getName(), new ClientAuthenticationHandler(embeddedServer));
            SessionHandler sessionHandler = new SessionHandler(embeddedServer);
            pipelines.addLast(SessionHandler.class.getName(), sessionHandler);
            return pipelines;
        }
    });
    // 启动
    if (StringUtils.isNotEmpty(ip)) {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.ip, this.port));
    } else {
        this.serverChannel = bootstrap.bind(new InetSocketAddress(this.port));
    }
}
Also used : SessionHandler(com.alibaba.otter.canal.server.netty.handler.SessionHandler) ClientAuthenticationHandler(com.alibaba.otter.canal.server.netty.handler.ClientAuthenticationHandler) NioServerSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory) HandshakeInitializationHandler(com.alibaba.otter.canal.server.netty.handler.HandshakeInitializationHandler) InetSocketAddress(java.net.InetSocketAddress) ChannelPipelineFactory(org.jboss.netty.channel.ChannelPipelineFactory) FixedHeaderFrameDecoder(com.alibaba.otter.canal.server.netty.handler.FixedHeaderFrameDecoder) ServerBootstrap(org.jboss.netty.bootstrap.ServerBootstrap) ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Aggregations

ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)31 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)29 InetSocketAddress (java.net.InetSocketAddress)12 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)11 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)10 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)7 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)7 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)6 HttpServerCodec (org.jboss.netty.handler.codec.http.HttpServerCodec)6 Log4JLoggerFactory (org.jboss.netty.logging.Log4JLoggerFactory)6 BeforeClass (org.testng.annotations.BeforeClass)6 InvalidConfigException (com.linkedin.databus.core.util.InvalidConfigException)5 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)5 IOException (java.io.IOException)5 ChannelFactory (org.jboss.netty.channel.ChannelFactory)5 DatabusHttpClientImpl (com.linkedin.databus.client.DatabusHttpClientImpl)4 DbusEventV2Factory (com.linkedin.databus.core.DbusEventV2Factory)4 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)4 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)4 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)3