use of io.netty.handler.codec.string.StringDecoder in project jgnash by ccavanaugh.
the class AttachmentTransferServer method startServer.
public boolean startServer(final char[] password) {
boolean result = false;
// If a password has been specified, create an EncryptionManager
if (password != null && password.length > 0) {
encryptionManager = new EncryptionManager(password);
}
try {
ServerBootstrap b = new ServerBootstrap();
b.group(eventLoopGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(final SocketChannel ch) {
ch.pipeline().addLast(new DelimiterBasedFrameDecoder(((TRANSFER_BUFFER_SIZE + 2) / 3) * 4 + PATH_MAX, true, Delimiters.lineDelimiter()), new StringEncoder(CharsetUtil.UTF_8), new StringDecoder(CharsetUtil.UTF_8), new Base64Encoder(), new Base64Decoder(), new ServerTransferHandler());
}
});
// Start the server.
final ChannelFuture future = b.bind(port).sync();
if (future.isDone() && future.isSuccess()) {
result = true;
logger.info("File Transfer Server started successfully");
} else {
logger.info("Failed to start the File Transfer Server");
}
} catch (final InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
stopServer();
}
return result;
}
use of io.netty.handler.codec.string.StringDecoder in project sidewinder by srotya.
the class StatsdServer method start.
@Override
public void start() throws Exception {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup(2);
ServerBootstrap bs = new ServerBootstrap();
channel = bs.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_RCVBUF, 10485760).handler(new LoggingHandler(LogLevel.DEBUG)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(workerGroup, new LineBasedFrameDecoder(1024, true, true));
p.addLast(workerGroup, new StringDecoder());
p.addLast(workerGroup, new StatdsDecoder(dbName, storageEngine, writeCounter));
}
}).bind(bindAddress, serverPort).sync().channel();
}
use of io.netty.handler.codec.string.StringDecoder in project sidewinder by srotya.
the class TestStatsdDecoder method testStatsdParse.
@Test
public void testStatsdParse() throws IOException {
EmbeddedChannel ch = new EmbeddedChannel(new StringDecoder(), new StatdsDecoder("test", engine, null));
ch.writeInbound(Unpooled.copiedBuffer("http.server_ngnix.latency:1121|ms", Charset.defaultCharset()));
ch.readInbound();
verify(engine, times(1)).writeDataPointWithLock(any(Point.class), anyBoolean());
// MiscUtils.buildDataPoint("test", "http", "latency", tags,
// System.currentTimeMillis(), 1121), false);
ch.close();
}
use of io.netty.handler.codec.string.StringDecoder in project sidewinder by srotya.
the class TestGraphiteDecoder method testHandler.
@Test
public void testHandler() throws IOException {
EmbeddedChannel ch = new EmbeddedChannel(new StringDecoder(), new GraphiteDecoder("test", engine, null));
ch.writeInbound(Unpooled.copiedBuffer("app=1.server=1.s=jvm.heap.max 233123 1497720452", Charset.defaultCharset()));
ch.readInbound();
List<Tag> tags = Arrays.asList(Tag.newBuilder().setTagKey("app").setTagValue("1").build(), Tag.newBuilder().setTagKey("server").setTagValue("1").build(), Tag.newBuilder().setTagKey("s").setTagValue("jvm").build());
verify(engine, times(1)).writeDataPointWithLock(MiscUtils.buildDataPoint("test", "heap", "max", tags, ((long) 1497720452) * 1000, 233123), false);
ch.close();
}
use of io.netty.handler.codec.string.StringDecoder in project netty by netty.
the class SocketStartTlsTest method testStartTls.
private void testStartTls(ServerBootstrap sb, Bootstrap cb, boolean autoRead) throws Throwable {
sb.childOption(ChannelOption.AUTO_READ, autoRead);
cb.option(ChannelOption.AUTO_READ, autoRead);
final EventExecutorGroup executor = SocketStartTlsTest.executor;
SSLEngine sse = serverCtx.newEngine(PooledByteBufAllocator.DEFAULT);
SSLEngine cse = clientCtx.newEngine(PooledByteBufAllocator.DEFAULT);
final StartTlsServerHandler sh = new StartTlsServerHandler(sse, autoRead);
final StartTlsClientHandler ch = new StartTlsClientHandler(cse, autoRead);
sb.childHandler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast("logger", new LoggingHandler(LOG_LEVEL));
p.addLast(new LineBasedFrameDecoder(64), new StringDecoder(), new StringEncoder());
p.addLast(executor, sh);
}
});
cb.handler(new ChannelInitializer<Channel>() {
@Override
public void initChannel(Channel sch) throws Exception {
ChannelPipeline p = sch.pipeline();
p.addLast("logger", new LoggingHandler(LOG_LEVEL));
p.addLast(new LineBasedFrameDecoder(64), new StringDecoder(), new StringEncoder());
p.addLast(executor, ch);
}
});
Channel sc = sb.bind().sync().channel();
Channel cc = cb.connect().sync().channel();
while (cc.isActive()) {
if (sh.exception.get() != null) {
break;
}
if (ch.exception.get() != null) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Ignore.
}
}
while (sh.channel.isActive()) {
if (sh.exception.get() != null) {
break;
}
if (ch.exception.get() != null) {
break;
}
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// Ignore.
}
}
sh.channel.close().awaitUninterruptibly();
cc.close().awaitUninterruptibly();
sc.close().awaitUninterruptibly();
if (sh.exception.get() != null && !(sh.exception.get() instanceof IOException)) {
throw sh.exception.get();
}
if (ch.exception.get() != null && !(ch.exception.get() instanceof IOException)) {
throw ch.exception.get();
}
if (sh.exception.get() != null) {
throw sh.exception.get();
}
if (ch.exception.get() != null) {
throw ch.exception.get();
}
}
Aggregations