EventLoopGroup bossGroup = new NioEventLoopGroup(2);
EventLoopGroup workerGroup = new NioEventLoopGroup(4);
Configuration conf = new Configuration();
conf.addResource("/usr/local/Cellar/hadoop/1.1.2/libexec/conf/core-site.xml");
final HdfsConsumer hdfs = new HdfsConsumer(conf, "loadtests", "syslog");
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup)
.localAddress(3000)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
pipeline.addLast("decoder", new StringDecoder());
pipeline.addLast("syslogDecoder", new MessageToMessageDecoder<String>() {
Function<Buffer, SyslogMessage> decoder = new SyslogCodec().decoder(null);
@Override
public void decode(ChannelHandlerContext ctx, String msg, List<Object> messages) throws Exception {
messages.add(decoder.apply(Buffer.wrap(msg + "\n")));
}
});
pipeline.addLast("handler", new ChannelInboundHandlerAdapter() {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
latch.countDown();
hdfs.accept((SyslogMessage)msg);
}
});
}
});