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..");
}
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;
}
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);
}
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;
}
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!");
}
Aggregations