use of io.netty.channel.socket.SocketChannel in project rpki-validator-3 by RIPE-NCC.
the class RtrServer method runNetty.
private void runNetty() throws InterruptedException {
bossGroup = new NioEventLoopGroup();
workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ChannelTrafficShapingHandler traffic = new ChannelTrafficShapingHandler(0);
RtrClientHandler rtrClientHandler = rtrClientHandlerProvider.get();
rtrClientHandler.setTrafficShapingHandler(traffic);
ch.pipeline().addLast(traffic, new PduCodec(), new ChunkedWriteHandler(), rtrClientHandler);
}
}).option(ChannelOption.SO_BACKLOG, 128).childOption(ChannelOption.SO_KEEPALIVE, true);
log.info("Running RTR at port {}", port);
ChannelFuture f = b.bind(port).sync();
f.channel().closeFuture().sync();
} finally {
shutdownWorkers();
}
}
use of io.netty.channel.socket.SocketChannel in project runelite by runelite.
the class CacheClient method connect.
public void connect() {
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true).handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
// p.addFirst(new HttpProxyHandler(new InetSocketAddress("runelite.net", 3128)));
p.addLast("decoder", new HandshakeResponseDecoder());
p.addLast(new CacheClientHandler(), new HandshakeResponseHandler(CacheClient.this), new ArchiveResponseHandler(CacheClient.this));
p.addLast(new UpdateHandshakeEncoder(), new EncryptionEncoder(), new ArchiveRequestEncoder());
}
});
// Start the client.
ChannelFuture f = b.connect(host, PORT).syncUninterruptibly();
channel = f.channel();
}
use of io.netty.channel.socket.SocketChannel in project apollo by apollo-rsps.
the class Server method init.
/**
* Initialises the server.
*
* @param releaseName The class name of the current active {@link Release}.
* @throws Exception If an error occurs.
*/
public void init(String releaseName) throws Exception {
Class<?> clazz = Class.forName(releaseName);
Release release = (Release) clazz.newInstance();
int version = release.getReleaseNumber();
logger.info("Initialized " + release + ".");
serviceBootstrap.group(loopGroup);
httpBootstrap.group(loopGroup);
jaggrabBootstrap.group(loopGroup);
World world = new World();
ServiceManager services = new ServiceManager(world);
IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs", Integer.toString(version)), true);
ServerContext context = new ServerContext(release, services, fs);
ApolloHandler handler = new ApolloHandler(context);
ChannelInitializer<SocketChannel> service = new ServiceChannelInitializer(handler);
serviceBootstrap.channel(NioServerSocketChannel.class);
serviceBootstrap.childHandler(service);
ChannelInitializer<SocketChannel> http = new HttpChannelInitializer(handler);
httpBootstrap.channel(NioServerSocketChannel.class);
httpBootstrap.childHandler(http);
ChannelInitializer<SocketChannel> jaggrab = new JagGrabChannelInitializer(handler);
jaggrabBootstrap.channel(NioServerSocketChannel.class);
jaggrabBootstrap.childHandler(jaggrab);
PluginManager manager = new PluginManager(world, new PluginContext(context));
services.startAll();
world.init(version, fs, manager);
}
use of io.netty.channel.socket.SocketChannel in project alien4cloud by alien4cloud.
the class StompConnection method init.
@SneakyThrows({ InterruptedException.class, URISyntaxException.class })
private void init() {
if (this.stompChannel != null) {
throw new IllegalStateException("The stomp connection has already been started");
}
String wsUrl = "ws://" + host + ":" + port + endPoint + "/websocket";
if (log.isDebugEnabled()) {
log.debug("Web socket url {}", wsUrl);
}
String loginUrl = null;
if (user != null && password != null && loginPath != null) {
loginUrl = "http://" + host + ":" + port + loginPath;
if (log.isDebugEnabled()) {
log.debug("Authentication url {}", loginUrl);
}
}
this.eventLoopGroup = new NioEventLoopGroup();
this.stompClientHandler = new StompClientHandler();
DefaultHttpHeaders handshakeHeaders = new DefaultHttpHeaders();
if (this.headers != null) {
for (Map.Entry<String, String> header : this.headers.entrySet()) {
handshakeHeaders.add(header.getKey(), header.getValue());
}
}
final WebSocketClientHandler webSocketHandler = new WebSocketClientHandler(WebSocketClientHandshakerFactory.newHandshaker(new URI(wsUrl), WebSocketVersion.V13, null, false, handshakeHeaders), host, user, password, loginUrl);
Bootstrap b = new Bootstrap();
b.group(eventLoopGroup).channel(NioSocketChannel.class);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(HttpClientCodec.class.getName(), new HttpClientCodec());
pipeline.addLast(HttpObjectAggregator.class.getName(), new HttpObjectAggregator(8192));
pipeline.addLast(WebSocketClientCompressionHandler.class.getName(), new WebSocketClientCompressionHandler());
pipeline.addLast(WebSocketClientHandler.class.getName(), webSocketHandler);
pipeline.addLast(StompSubframeDecoder.class.getName(), new StompSubframeDecoder());
pipeline.addLast(StompSubframeEncoder.class.getName(), new StompSubframeEncoder());
pipeline.addLast(StompSubframeAggregator.class.getName(), new StompSubframeAggregator(1048576));
pipeline.addLast(StompClientHandler.class.getName(), stompClientHandler);
}
});
this.stompChannel = b.connect(host, port).sync().channel();
this.stompClientHandler.connectFuture(this.stompChannel.newPromise());
webSocketHandler.handshakeFuture().addListener(new ChannelFutureListener() {
@Override
public void operationComplete(final ChannelFuture future) throws Exception {
stompClientHandler.beginStomp(stompChannel);
}
});
}
use of io.netty.channel.socket.SocketChannel in project jdepth by Crab2died.
the class C2DServer method bind.
private void bind(String host, int port) throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap().group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(new C2DHessianMsgDecoder(1024 * 1024, 4, 4, -8, 0)).addLast("MessageEncoder", new C2DHessianMsgEncoder()).addLast("ReadTimeoutHandler", new ReadTimeoutHandler(TIME_OUT)).addLast("LoginAuthResp", new LoginAuthRespHandler()).addLast("Pong", new PongHandler());
}
});
ChannelFuture future = bootstrap.bind(host, port).sync();
future.channel().closeFuture().sync();
logger.info("server is started");
} finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
Aggregations