@Override
 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
   exception.compareAndSet(null, cause);
   // System.err.print("[" + Thread.currentThread().getName() + "] ");
   // cause.printStackTrace();
   super.exceptionCaught(ctx, cause);
 }
 @Override
 public void handlerRemoved(ChannelHandlerContext ctx) throws Exception {
   if (channelBuffer.refCnt() >= 1) {
     channelBuffer.release();
   }
   super.handlerRemoved(ctx);
 }
예제 #3
0
 @Override
 public void channelActive(final ChannelHandlerContext ctx) throws Exception {
   super.channelActive(ctx);
   handler
       .apply(bridgeFactory.createChannelBridge(ctx.channel(), input))
       .subscribe(new CloseSubscriber(ctx));
 }
예제 #4
0
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   try {
     inboundEmitter.complete();
     super.channelInactive(ctx);
   } catch (Throwable err) {
     Exceptions.throwIfFatal(err);
     inboundEmitter.fail(err);
   }
 }
    @Override
    public void close(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception {
      Channel channel = new NettyChannel(ctx);

      final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel);
      LOGGER.info("CLIENT : CLOSE {}", remoteAddress);
      closeChannel(channel);
      super.close(ctx, promise);

      if (channelEventListener != null) {
        putRemotingEvent(new RemotingEvent(RemotingEventType.CLOSE, remoteAddress, channel));
      }
    }
예제 #6
0
 @Override
 public void write(final ChannelHandlerContext ctx, Object msg, final ChannelPromise promise)
     throws Exception {
   if (msg instanceof ChannelWriter) {
     @SuppressWarnings("unchecked")
     ChannelWriter dataWriter = (ChannelWriter) msg;
     if (dataWriter.flushMode == FlushMode.MANUAL_COMPLETE) {
       dataWriter.writeStream.subscribe(new FlushOnTerminateSubscriber(ctx, promise));
     } else {
       dataWriter.writeStream.subscribe(new FlushOnEachSubscriber(ctx, promise));
     }
   } else {
     super.write(ctx, msg, promise);
   }
 }
    @Override
    public void connect(
        ChannelHandlerContext ctx,
        SocketAddress remoteAddress,
        SocketAddress localAddress,
        ChannelPromise promise)
        throws Exception {
      final String local = localAddress == null ? "UNKNOW" : localAddress.toString();
      final String remote = remoteAddress == null ? "UNKNOW" : remoteAddress.toString();
      LOGGER.info("CLIENT : CONNECT  {} => {}", local, remote);
      super.connect(ctx, remoteAddress, localAddress, promise);

      if (channelEventListener != null) {
        assert remoteAddress != null;
        putRemotingEvent(
            new RemotingEvent(
                RemotingEventType.CONNECT, remoteAddress.toString(), new NettyChannel(ctx)));
      }
    }
예제 #8
0
    @Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
        throws Exception {
      for (Entry<PacketListener, List<Method>> listener : OUT.entrySet()) {
        for (Method method : listener.getValue()) {

          PacketHandler ann = method.getAnnotation(PacketHandler.class);
          if (!ann.packet().getName().equals(msg.getClass().getSimpleName())) continue;
          PacketEvent evt = new PacketEvent(player, msg);
          method.setAccessible(true);
          method.invoke(listener.getKey(), evt);
          msg = evt.getPacket();
        }
      }

      if (msg != null) {
        super.write(ctx, msg, promise);
      }
    }
 @Override
 public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
   if (bufferedMode && outboundChannel.isActive()) {
     flushedBuffer = true;
     outboundChannel
         .writeAndFlush(interceptor.intercept(ctx, channelBuffer, logger))
         .addListener(
             new ChannelFutureListener() {
               @Override
               public void operationComplete(ChannelFuture future) throws Exception {
                 if (future.isSuccess()) {
                   channelBuffer.clear();
                 } else {
                   future.channel().close();
                 }
               }
             });
   }
   super.channelReadComplete(ctx);
 }
예제 #10
0
    @Override
    public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
      final Channel channel = ctx.channel();
      handleLoginStart(channel, msg);

      for (Entry<PacketListener, List<Method>> listener : IN.entrySet()) {
        for (Method method : listener.getValue()) {
          PacketHandler ann = method.getAnnotation(PacketHandler.class);
          if (!ann.packet().getName().equals(msg.getClass().getSimpleName())) continue;

          PacketEvent evt = new PacketEvent(player, msg);
          method.setAccessible(true);
          method.invoke(listener.getKey(), evt);
          method.setAccessible(false);
          msg = evt.getPacket();
        }
      }
      if (msg != null) {
        super.channelRead(ctx, msg);
      }
    }
  @SuppressWarnings("unchecked")
  @Override
  public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
      throws Exception {
    if (PlayOutTileEntityData.isInstance(msg)) {

      Object tag = ReflectionUtil.getObject(msg, "c");
      Object owner =
          ReflectionUtil.invokeMethod(
              tag.getClass(), tag, "getCompound", new Class<?>[] {String.class}, "Owner");

      if (!owner.toString().isEmpty()) {

        Object props =
            ReflectionUtil.invokeMethod(
                owner.getClass(),
                owner,
                "getCompound",
                new Class<?>[] {String.class},
                "Properties");

        if (!props.toString().isEmpty()) {

          Map<String, Object> map = (Map<String, Object>) ReflectionUtil.getObject(props, "map");

          for (Entry<String, Object> entry : map.entrySet()) {

            if (!entry.getKey().equals("textures")) continue;

            String value = entry.getValue().toString();
            if (value.contains("\"\"") || !value.contains("Value:\"")) {
              return;
            }
          }
        }
      }
    }

    super.write(ctx, msg, promise);
  }
 @Override
 public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
   this.channelBuffer = Unpooled.directBuffer(bufferedCapacity);
   super.handlerAdded(ctx);
 }
예제 #13
0
 @Override
 public void channelInactive(ChannelHandlerContext ctx) throws Exception {
   httpClientResponseHandler.handleChannelInactive(ctx);
   super.channelReadComplete(ctx);
 }