Search in sources :

Example 31 with StringDecoder

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;
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) EncryptionManager(jgnash.util.EncryptionManager) DelimiterBasedFrameDecoder(io.netty.handler.codec.DelimiterBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) Base64Encoder(io.netty.handler.codec.base64.Base64Encoder) StringEncoder(io.netty.handler.codec.string.StringEncoder) Base64Decoder(io.netty.handler.codec.base64.Base64Decoder)

Example 32 with StringDecoder

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();
}
Also used : NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) LoggingHandler(io.netty.handler.logging.LoggingHandler) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 33 with StringDecoder

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();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) StringDecoder(io.netty.handler.codec.string.StringDecoder) Point(com.srotya.sidewinder.core.rpc.Point) Test(org.junit.Test)

Example 34 with StringDecoder

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();
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) StringDecoder(io.netty.handler.codec.string.StringDecoder) Tag(com.srotya.sidewinder.core.rpc.Tag) Test(org.junit.Test)

Example 35 with StringDecoder

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();
    }
}
Also used : DefaultEventExecutorGroup(io.netty.util.concurrent.DefaultEventExecutorGroup) EventExecutorGroup(io.netty.util.concurrent.EventExecutorGroup) LoggingHandler(io.netty.handler.logging.LoggingHandler) SSLEngine(javax.net.ssl.SSLEngine) Channel(io.netty.channel.Channel) LineBasedFrameDecoder(io.netty.handler.codec.LineBasedFrameDecoder) StringDecoder(io.netty.handler.codec.string.StringDecoder) IOException(java.io.IOException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ChannelPipeline(io.netty.channel.ChannelPipeline) StringEncoder(io.netty.handler.codec.string.StringEncoder)

Aggregations

StringDecoder (io.netty.handler.codec.string.StringDecoder)65 StringEncoder (io.netty.handler.codec.string.StringEncoder)42 ChannelPipeline (io.netty.channel.ChannelPipeline)36 SocketChannel (io.netty.channel.socket.SocketChannel)28 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)22 ChannelFuture (io.netty.channel.ChannelFuture)18 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)17 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)16 DelimiterBasedFrameDecoder (io.netty.handler.codec.DelimiterBasedFrameDecoder)16 LineBasedFrameDecoder (io.netty.handler.codec.LineBasedFrameDecoder)15 Bootstrap (io.netty.bootstrap.Bootstrap)14 EventLoopGroup (io.netty.channel.EventLoopGroup)14 LengthFieldPrepender (io.netty.handler.codec.LengthFieldPrepender)13 LengthFieldBasedFrameDecoder (io.netty.handler.codec.LengthFieldBasedFrameDecoder)12 Channel (io.netty.channel.Channel)11 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)11 LoggingHandler (io.netty.handler.logging.LoggingHandler)9 Test (org.junit.Test)7 ChannelHandler (io.netty.channel.ChannelHandler)6 ByteBuf (io.netty.buffer.ByteBuf)5