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