use of io.netty.handler.codec.bytes.ByteArrayDecoder in project camel by apache.
the class NettyUDPByteArrayProviderTest method createNettyUdpReceiver.
public void createNettyUdpReceiver() {
group = new NioEventLoopGroup();
bootstrap = new Bootstrap();
bootstrap.group(group).channel(NioDatagramChannel.class).handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel channel) throws Exception {
channel.pipeline().addLast(new UdpHandler());
channel.pipeline().addLast(new ByteArrayDecoder());
channel.pipeline().addLast(new ContentHandler());
}
}).localAddress(new InetSocketAddress(getPort()));
}
use of io.netty.handler.codec.bytes.ByteArrayDecoder in project java by wavefrontHQ.
the class StreamIngester method run.
public void run() {
activeListeners.inc();
// Configure the server.
ServerBootstrap b = new ServerBootstrap();
EventLoopGroup parentGroup;
EventLoopGroup childGroup;
Class<? extends ServerChannel> socketChannelClass;
if (Epoll.isAvailable()) {
logger.fine("Using native socket transport for port " + listeningPort);
parentGroup = new EpollEventLoopGroup(1);
childGroup = new EpollEventLoopGroup();
socketChannelClass = EpollServerSocketChannel.class;
} else {
logger.fine("Using NIO socket transport for port " + listeningPort);
parentGroup = new NioEventLoopGroup(1);
childGroup = new NioEventLoopGroup();
socketChannelClass = NioServerSocketChannel.class;
}
try {
b.group(parentGroup, childGroup).channel(socketChannelClass).option(ChannelOption.SO_BACKLOG, 1024).localAddress(listeningPort).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("frame decoder", frameDecoderFactory.getDecoder());
pipeline.addLast("byte array decoder", new ByteArrayDecoder());
pipeline.addLast(commandHandler);
}
});
if (parentChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : parentChannelOptions.entrySet()) {
b.option((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
if (childChannelOptions != null) {
for (Map.Entry<ChannelOption<?>, ?> entry : childChannelOptions.entrySet()) {
b.childOption((ChannelOption<Object>) entry.getKey(), entry.getValue());
}
}
// Start the server.
ChannelFuture f = b.bind().sync();
// Wait until the server socket is closed.
f.channel().closeFuture().sync();
} catch (final InterruptedException e) {
logger.log(Level.WARNING, "Interrupted");
parentGroup.shutdownGracefully();
childGroup.shutdownGracefully();
logger.info("Listener on port " + String.valueOf(listeningPort) + " shut down");
} catch (Exception e) {
// ChannelFuture throws undeclared checked exceptions, so we need to handle it
if (e instanceof BindException) {
logger.severe("Unable to start listener - port " + String.valueOf(listeningPort) + " is already in use!");
} else {
logger.log(Level.SEVERE, "StreamIngester exception: ", e);
}
} finally {
activeListeners.dec();
}
}
use of io.netty.handler.codec.bytes.ByteArrayDecoder in project uploader by smoketurner.
the class UploadInitializer method initChannel.
@Override
public void initChannel(final SocketChannel ch) throws Exception {
final ChannelPipeline p = ch.pipeline();
// add the IP ACL filter first
if (ipFilter != null) {
p.addLast("acl", ipFilter);
}
if (sslCtx != null) {
if (configuration.isClientAuth()) {
final SSLEngine engine = sslCtx.newEngine(ch.alloc());
engine.setUseClientMode(false);
engine.setNeedClientAuth(true);
p.addLast("ssl", new SslHandler(engine));
} else {
p.addLast("ssl", sslCtx.newHandler(ch.alloc()));
}
}
// removes idle connections after READER_IDLE_SECONDS seconds
p.addLast("idleStateHandler", new IdleStateHandler(READER_IDLE_SECONDS, 0, 0));
// authenticate via an ACL and mutual certificates
p.addLast("auth", new AuthHandler(configuration.isClientAuth()));
// check to see if the data stream is gzipped or not
// p.addLast("gzipDetector", new OptionalGzipHandler());
// break each data chunk by newlines
p.addLast("line", new LineBasedFrameDecoder(Ints.checkedCast(maxLength), true, true));
// convert each data chunk into a byte array
p.addLast("decoder", new ByteArrayDecoder());
// batch and compress chunks of data up to maxUploadBytes
p.addLast("batcher", new BatchHandler(maxUploadBytes));
// upload the batch to S3
p.addLast("uploader", uploadHandler);
}
Aggregations