Example usage for io.netty.handler.traffic ChannelTrafficShapingHandler ChannelTrafficShapingHandler

List of usage examples for io.netty.handler.traffic ChannelTrafficShapingHandler ChannelTrafficShapingHandler

Introduction

In this page you can find the example usage for io.netty.handler.traffic ChannelTrafficShapingHandler ChannelTrafficShapingHandler.

Prototype

public ChannelTrafficShapingHandler(long checkInterval) 

Source Link

Document

Create a new instance using default max time as delay allowed value of 15000 ms and no limit.

Usage

From source file:in.voidma.lemming.InternalClientBuilder.java

License:Open Source License

public InternalClientBuilder throttling(long checkInterval) {
    ChannelTrafficShapingHandler throttlingHandler = new ChannelTrafficShapingHandler(checkInterval);
    return this;
}

From source file:net.NettyEngine4.ServerUtil.java

License:Apache License

/**
 *???/*  w ww .j  a  v  a2 s  . co  m*/
 * @return       ChannelTrafficShapingHandler
 */
public static ChannelTrafficShapingHandler getChannelTrafficShapingHandler() {
    return new ChannelTrafficShapingHandler(Config.DEFAULT_VALUE.SERVER_VALUE.checkInterval);
}

From source file:subterranean.crimson.server.network.ClientListener.java

License:Open Source License

@Override
public void run() {
    if (UPNP) {//ww  w.j av  a2  s .c  om
        Logger.add("Attempting to automatically forward the port");
        try {
            PortMapper.forward(PORT);
            Logger.add("Port mapping Success!");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Logger.add("Port mapping failed!");
        }
    }

    EventLoopGroup bossGroup = new NioEventLoopGroup(1);
    EventLoopGroup workerGroup = new NioEventLoopGroup();

    try {
        ServerBootstrap b = new ServerBootstrap();
        b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class)
                .handler(new LoggingHandler(LogLevel.INFO))
                .childHandler(new ChannelInitializer<SocketChannel>() {
                    @Override
                    public void initChannel(final SocketChannel ch) throws Exception {
                        ChannelPipeline p = ch.pipeline();
                        if (sslCtx != null) {
                            p.addLast("SSL Handler", sslCtx.newHandler(ch.alloc()));
                        }
                        final ServerHandler sh = new ServerHandler();
                        final ChannelTrafficShapingHandler ctsh = new ChannelTrafficShapingHandler(300);
                        p.addLast(ctsh, new ObjectEncoder(),
                                new ObjectDecoder(Integer.MAX_VALUE, ClassResolvers.cacheDisabled(null)), sh);
                        // spawn a new connection object
                        new Thread(new Runnable() {
                            public void run() {
                                Connection c = new Connection(key, encryption, sh, ctsh, ch.remoteAddress());
                                c.handshake();
                            }
                        }).start();

                    }
                });

        // Bind and start to accept incoming connections.
        b.bind(PORT).sync().channel().closeFuture().sync();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        bossGroup.shutdownGracefully();
        workerGroup.shutdownGracefully();

        if (UPNP) {
            Logger.add("Attempting to remove port mapping");
            try {
                PortMapper.unforward(PORT);
                Logger.add("Port mapping removed");
            } catch (Exception e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
                Logger.add("Failed to remove port mapping");
            }
        }
    }

}