Search in sources :

Example 1 with Slf4JLoggerFactory

use of org.jboss.netty.logging.Slf4JLoggerFactory 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 2 with Slf4JLoggerFactory

use of org.jboss.netty.logging.Slf4JLoggerFactory in project druid by druid-io.

the class HttpClientInit method createBootstrap.

private static ClientBootstrap createBootstrap(Lifecycle lifecycle, Timer timer, int bossPoolSize, int workerPoolSize) {
    final NioClientBossPool bossPool = new NioClientBossPool(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Netty-Boss-%s").build()), bossPoolSize, timer, ThreadNameDeterminer.CURRENT);
    final NioWorkerPool workerPool = new NioWorkerPool(Executors.newCachedThreadPool(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("HttpClient-Netty-Worker-%s").build()), workerPoolSize, ThreadNameDeterminer.CURRENT);
    final ClientBootstrap bootstrap = new ClientBootstrap(new NioClientSocketChannelFactory(bossPool, workerPool));
    bootstrap.setOption("keepAlive", true);
    bootstrap.setPipelineFactory(new HttpClientPipelineFactory());
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    try {
        lifecycle.addMaybeStartHandler(new Lifecycle.Handler() {

            @Override
            public void start() {
            }

            @Override
            public void stop() {
                bootstrap.releaseExternalResources();
            }
        });
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return bootstrap;
}
Also used : NioClientBossPool(org.jboss.netty.channel.socket.nio.NioClientBossPool) NioWorkerPool(org.jboss.netty.channel.socket.nio.NioWorkerPool) NioClientSocketChannelFactory(org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory) ClientBootstrap(org.jboss.netty.bootstrap.ClientBootstrap) Lifecycle(org.apache.druid.java.util.common.lifecycle.Lifecycle) ThreadFactoryBuilder(com.google.common.util.concurrent.ThreadFactoryBuilder) HttpClientPipelineFactory(org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory)

Example 3 with Slf4JLoggerFactory

use of org.jboss.netty.logging.Slf4JLoggerFactory in project Protocol-Adapter-OSLP by OSGP.

the class WebDeviceSimulatorInitializer method onStartup.

/**
 */
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
    startUp(servletContext);
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING);
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) DispatcherServlet(org.springframework.web.servlet.DispatcherServlet) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory)

Example 4 with Slf4JLoggerFactory

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

use of org.jboss.netty.logging.Slf4JLoggerFactory in project sockjs-netty by cgbystrom.

the class StressTest method main.

public static void main(String[] args) throws Exception {
    Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    rootLogger.setLevel(Level.INFO);
    InternalLoggerFactory.setDefaultFactory(new Slf4JLoggerFactory());
    final int port = 8001;
    final int numClients = 10;
    new StressTestServer(port).start();
    System.out.println("Server running..");
    List<StressTestClient> clients = new ArrayList<StressTestClient>(numClients);
    for (int i = 0; i < numClients; i++) {
        StressTestClient client = new StressTestClient(port);
        client.connect();
        clients.add(client);
    }
    System.out.println("Waiting to disconnect all clients...");
    Thread.sleep(2 * 1000);
    System.out.println("Disconnecting all clients...");
    for (StressTestClient client : clients) {
        client.disconnect();
    }
    System.out.println("All clients disconnected!");
}
Also used : ArrayList(java.util.ArrayList) Logger(ch.qos.logback.classic.Logger) Slf4JLoggerFactory(org.jboss.netty.logging.Slf4JLoggerFactory)

Aggregations

Slf4JLoggerFactory (org.jboss.netty.logging.Slf4JLoggerFactory)5 Logger (ch.qos.logback.classic.Logger)2 ClientBootstrap (org.jboss.netty.bootstrap.ClientBootstrap)2 ChannelPipeline (org.jboss.netty.channel.ChannelPipeline)2 ChannelPipelineFactory (org.jboss.netty.channel.ChannelPipelineFactory)2 NioClientSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory)2 NioServerSocketChannelFactory (org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 BroadcastSession (com.cgbystrom.sockjs.test.BroadcastSession)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 ServletRegistration (javax.servlet.ServletRegistration)1 Lifecycle (org.apache.druid.java.util.common.lifecycle.Lifecycle)1 HttpClientPipelineFactory (org.apache.druid.java.util.http.client.netty.HttpClientPipelineFactory)1