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;
}
}
}
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);
}
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);
}
});
}
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);
}
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;
}
Aggregations