Search in sources :

Example 71 with Channel

use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project java-in-action by xinghalo.

the class LogEventBroadcaster method run.

public void run() throws Exception {
    Channel ch = bootstrap.bind(0).sync().channel();
    long pointer = 0;
    for (; ; ) {
        long len = file.length();
        if (len < pointer) {
            pointer = len;
        } else if (len > pointer) {
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            raf.seek(pointer);
            String line;
            while ((line = raf.readLine()) != null) {
                ch.writeAndFlush(new LogEvent(null, line, file.getAbsolutePath(), -1));
            }
            pointer = raf.getFilePointer();
            raf.close();
        }
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            Thread.interrupted();
            break;
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) Channel(io.netty.channel.Channel) NioDatagramChannel(io.netty.channel.socket.nio.NioDatagramChannel)

Example 72 with Channel

use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project async-http-client by AsyncHttpClient.

the class FailingReactiveStreamsTest method getChannel.

private Channel getChannel(StreamedResponsePublisher publisher) throws Exception {
    Field field = publisher.getClass().getDeclaredField("channel");
    field.setAccessible(true);
    return (Channel) field.get(publisher);
}
Also used : Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel)

Example 73 with Channel

use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project dubbo by alibaba.

the class NettyClient method doOpen.

@Override
protected void doOpen() throws Throwable {
    NettyHelper.setNettyLoggerFactory();
    final NettyClientHandler nettyClientHandler = new NettyClientHandler(getUrl(), this);
    bootstrap = new Bootstrap();
    bootstrap.group(nioEventLoopGroup).option(ChannelOption.SO_KEEPALIVE, true).option(ChannelOption.TCP_NODELAY, true).option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT).channel(NioSocketChannel.class);
    if (getTimeout() < 3000) {
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000);
    } else {
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, getTimeout());
    }
    bootstrap.handler(new ChannelInitializer() {

        protected void initChannel(Channel ch) throws Exception {
            NettyCodecAdapter adapter = new NettyCodecAdapter(getCodec(), getUrl(), NettyClient.this);
            // .addLast("logging",new LoggingHandler(LogLevel.INFO))//for debug
            ch.pipeline().addLast("decoder", adapter.getDecoder()).addLast("encoder", adapter.getEncoder()).addLast("handler", nettyClientHandler);
        }
    });
}
Also used : NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer) RemotingException(com.alibaba.dubbo.remoting.RemotingException)

Example 74 with Channel

use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project tesla by linking12.

the class HttpProxyServer method doStart.

private void doStart() {
    ServerBootstrap serverBootstrap = new ServerBootstrap().group(serverGroup.getClientToProxyAcceptorPoolForTransport(), serverGroup.getClientToProxyWorkerPoolForTransport());
    ChannelInitializer<Channel> initializer = new ChannelInitializer<Channel>() {

        protected void initChannel(Channel ch) throws Exception {
            new ClientToProxyConnection(HttpProxyServer.this, ch.pipeline(), globalTrafficShapingHandler);
        }
    };
    serverBootstrap.channelFactory(new ChannelFactory<ServerChannel>() {

        public ServerChannel newChannel() {
            return new NioServerSocketChannel();
        }
    });
    serverBootstrap.childHandler(initializer);
    ChannelFuture future = serverBootstrap.bind(requestedAddress).addListener(new ChannelFutureListener() {

        public void operationComplete(ChannelFuture future) throws Exception {
            if (future.isSuccess()) {
                registerChannel(future.channel());
            }
        }
    }).awaitUninterruptibly();
    Throwable cause = future.cause();
    if (cause != null) {
        throw new RuntimeException(cause);
    }
    this.boundAddress = ((InetSocketAddress) future.channel().localAddress());
    LOG.info("Proxy started at address: " + this.boundAddress);
    Runtime.getRuntime().addShutdownHook(jvmShutdownHook);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) InetSocketAddress(java.net.InetSocketAddress) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ServerChannel(io.netty.channel.ServerChannel) Channel(io.netty.channel.Channel) ClientToProxyConnection(io.github.tesla.gateway.netty.transmit.connection.ClientToProxyConnection) ServerChannel(io.netty.channel.ServerChannel) ChannelFutureListener(io.netty.channel.ChannelFutureListener) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelInitializer(io.netty.channel.ChannelInitializer)

Example 75 with Channel

use of org.apache.flink.shaded.netty4.io.netty.channel.Channel in project SpaciousLib by anhcraft.

the class PacketListener method getChannel.

public static Channel getChannel(Player player) {
    GVersion v = GameVersion.getVersion();
    try {
        Class<?> craftPlayerClass = Class.forName("org.bukkit.craftbukkit." + v.toString() + ".entity.CraftPlayer");
        Class<?> nmsEntityPlayerClass = Class.forName("net.minecraft.server." + v.toString() + ".EntityPlayer");
        Class<?> playerConnClass = Class.forName("net.minecraft.server." + v.toString() + ".PlayerConnection");
        Class<?> networkManagerClass = Class.forName("net.minecraft.server." + v.toString() + ".NetworkManager");
        Object craftPlayer = craftPlayerClass.cast(player);
        Method handle = craftPlayerClass.getDeclaredMethod("getHandle");
        Object nmsEntity = handle.invoke(craftPlayer);
        Object nmsEntityPlayer = nmsEntityPlayerClass.cast(nmsEntity);
        Field playerConnField = nmsEntityPlayerClass.getDeclaredField("playerConnection");
        playerConnField.setAccessible(true);
        Object playerConn = playerConnField.get(nmsEntityPlayer);
        Field networkManagerField = playerConnClass.getDeclaredField("networkManager");
        networkManagerField.setAccessible(true);
        Object networkManager = networkManagerField.get(playerConn);
        Field channelField = networkManagerClass.getDeclaredField("channel");
        channelField.setAccessible(true);
        return (Channel) channelField.get(networkManager);
    } catch (InvocationTargetException | ClassNotFoundException | NoSuchFieldException | NoSuchMethodException | IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
Also used : GVersion(org.anhcraft.spaciouslib.utils.GVersion) Field(java.lang.reflect.Field) Channel(io.netty.channel.Channel) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

Channel (io.netty.channel.Channel)889 Test (org.junit.Test)242 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)227 ChannelFuture (io.netty.channel.ChannelFuture)204 Bootstrap (io.netty.bootstrap.Bootstrap)201 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)193 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)176 InetSocketAddress (java.net.InetSocketAddress)169 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)152 IOException (java.io.IOException)143 EventLoopGroup (io.netty.channel.EventLoopGroup)142 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)138 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)131 ByteBuf (io.netty.buffer.ByteBuf)112 SocketChannel (io.netty.channel.socket.SocketChannel)105 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)99 ChannelPipeline (io.netty.channel.ChannelPipeline)98 CountDownLatch (java.util.concurrent.CountDownLatch)97 LocalChannel (io.netty.channel.local.LocalChannel)93 LocalServerChannel (io.netty.channel.local.LocalServerChannel)88