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