Search in sources :

Example 1 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline 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 ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project storm by apache.

the class StormClientPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    // Decoder
    pipeline.addLast("decoder", new MessageDecoder());
    // Encoder
    pipeline.addLast("encoder", new MessageEncoder());
    boolean isNettyAuth = (Boolean) conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
    if (isNettyAuth) {
        // Authenticate: Removed after authentication completes
        pipeline.addLast("saslClientHandler", new SaslStormClientHandler(client));
    }
    // business logic.
    pipeline.addLast("handler", new StormClientHandler(client, conf));
    return pipeline;
}
Also used : ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 3 with ChannelPipeline

use of org.jboss.netty.channel.ChannelPipeline in project storm by apache.

the class StormServerPipelineFactory method getPipeline.

public ChannelPipeline getPipeline() throws Exception {
    // Create a default pipeline implementation.
    ChannelPipeline pipeline = Channels.pipeline();
    // Decoder
    pipeline.addLast("decoder", new MessageDecoder());
    // Encoder
    pipeline.addLast("encoder", new MessageEncoder());
    boolean isNettyAuth = (Boolean) this.server.storm_conf.get(Config.STORM_MESSAGING_NETTY_AUTHENTICATION);
    if (isNettyAuth) {
        // Authenticate: Removed after authentication completes
        pipeline.addLast("saslServerHandler", new SaslStormServerHandler(server));
        // Authorize
        pipeline.addLast("authorizeServerHandler", new SaslStormServerAuthorizeHandler());
    }
    // business logic.
    pipeline.addLast("handler", new StormServerHandler(server));
    return pipeline;
}
Also used : ChannelPipeline(org.jboss.netty.channel.ChannelPipeline)

Example 4 with ChannelPipeline

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

use of org.jboss.netty.channel.ChannelPipeline 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)

Aggregations

ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)105 InetSocketAddress (java.net.InetSocketAddress)32 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)29 SimpleObjectCaptureHandler (com.linkedin.databus2.test.container.SimpleObjectCaptureHandler)24 Channel (org.jboss.netty.channel.Channel)23 SocketAddress (java.net.SocketAddress)20 SimpleTestServerConnection (com.linkedin.databus2.test.container.SimpleTestServerConnection)17 ChannelBuffer (org.jboss.netty.buffer.ChannelBuffer)16 DefaultHttpResponse (org.jboss.netty.handler.codec.http.DefaultHttpResponse)15 HttpRequest (org.jboss.netty.handler.codec.http.HttpRequest)15 HttpResponse (org.jboss.netty.handler.codec.http.HttpResponse)15 ServerBootstrap (org.jboss.netty.bootstrap.ServerBootstrap)13 HttpResponseEncoder (org.jboss.netty.handler.codec.http.HttpResponseEncoder)13 LoggingHandler (org.jboss.netty.handler.logging.LoggingHandler)13 Checkpoint (com.linkedin.databus.core.Checkpoint)12 HttpRequestDecoder (org.jboss.netty.handler.codec.http.HttpRequestDecoder)12 ConditionCheck (com.linkedin.databus2.test.ConditionCheck)11 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)11 Test (org.testng.annotations.Test)11 DbusEventBuffer (com.linkedin.databus.core.DbusEventBuffer)10