Java Code Examples for io.netty.channel.ChannelHandlerContext.fireUserEventTriggered()

The following are Jave code examples for showing how to use fireUserEventTriggered() of the io.netty.channel.ChannelHandlerContext class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: NettyRemotingClient.java   View Source Code Vote up 6 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
            if (NettyRemotingClient.this.channelEventListener != null) {
                NettyRemotingClient.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 2
Project: rocketmq-rocketmq-all-4.1.0-incubating   File: NettyRemotingServer.java   View Source Code Vote up 6 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
    	/**
         *IdleStateEvent事件,在指定时间没有进行读写,会进行回调
         */
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());  //关闭channel
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 3
Project: HappyChat   File: UserAuthHandler.java   View Source Code Vote up 6 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        // 判断Channel是否读空闲, 读空闲时移除Channel
        if (evnet.state().equals(IdleState.READER_IDLE)) {
            final String remoteAddress = NettyUtil.parseChannelRemoteAddr(ctx.channel());
            logger.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            UserInfoManager.removeChannel(ctx.channel());
            UserInfoManager.broadCastInfo(ChatCode.SYS_USER_COUNT,UserInfoManager.getAuthUserCount());
        }
    }
    ctx.fireUserEventTriggered(evt);
}
 
Example 4
Project: rmq4note   File: NettyRemotingClient.java   View Source Code Vote up 6 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
            if (NettyRemotingClient.this.channelEventListener != null) {
                NettyRemotingClient.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 5
Project: rmq4note   File: NettyRemotingServer.java   View Source Code Vote up 6 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
            RemotingUtil.closeChannel(ctx.channel());
            if (NettyRemotingServer.this.channelEventListener != null) {
                NettyRemotingServer.this
                    .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress.toString(), ctx.channel()));
            }
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 6
Project: star-map   File: ClientIdleHandler.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    IdleStateEvent event = (IdleStateEvent) evt;
    if (event.state() == IdleState.WRITER_IDLE) {
        ctx.writeAndFlush("heartbeat").addListener((ChannelFutureListener) future -> {
            if (! future.isSuccess()) {
                future.channel().close();
            }
        });
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}
 
Example 7
Project: wechat-mall   File: NettyRemotingClient.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 8
Project: wechat-mall   File: NettyRemotingServer.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent evnet = (IdleStateEvent) evt;
        if (evnet.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", remoteAddress);
        }
    }

    ctx.fireUserEventTriggered(evt);
}
 
Example 9
Project: elephant   File: NettyRemotingClient.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state().equals(IdleState.ALL_IDLE)) {
            final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel());
            log.warn("NETTY CLIENT PIPELINE: IDLE exception [{}]", remoteAddress);
            closeChannel(ctx.channel());
        }
    }
    ctx.fireUserEventTriggered(evt);
}
 
Example 10
Project: elephant   File: NettyRemotingServer.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt)throws Exception {
	if (evt instanceof IdleStateEvent) {
              IdleStateEvent evnet = (IdleStateEvent) evt;
              if (evnet.state().equals(IdleState.ALL_IDLE)) {
                  log.warn("NETTY SERVER PIPELINE: IDLE exception [{}]", ctx.channel().remoteAddress());
                  RemotingUtil.closeChannel(ctx.channel());
              }
          }
          ctx.fireUserEventTriggered(evt);
}
 
Example 11
Project: spark_deep   File: TransportChannelHandler.java   View Source Code Vote up 5 votes
/** Triggered based on events from an {@link io.netty.handler.timeout.IdleStateHandler}. */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (evt instanceof IdleStateEvent) {
    IdleStateEvent e = (IdleStateEvent) evt;
    // See class comment for timeout semantics. In addition to ensuring we only timeout while
    // there are outstanding requests, we also do a secondary consistency check to ensure
    // there's no race between the idle timeout and incrementing the numOutstandingRequests
    // (see SPARK-7003).
    //
    // To avoid a race between TransportClientFactory.createClient() and this code which could
    // result in an inactive client being returned, this needs to run in a synchronized block.
    synchronized (this) {
      boolean isActuallyOverdue =
        System.nanoTime() - responseHandler.getTimeOfLastRequestNs() > requestTimeoutNs;
      if (e.state() == IdleState.ALL_IDLE && isActuallyOverdue) {
        if (responseHandler.numOutstandingRequests() > 0) {
          String address = getRemoteAddress(ctx.channel());
          logger.error("Connection to {} has been quiet for {} ms while there are outstanding " +
            "requests. Assuming connection is dead; please adjust spark.network.timeout if " +
            "this is wrong.", address, requestTimeoutNs / 1000 / 1000);
          client.timeOut();
          ctx.close();
        } else if (closeIdleConnections) {
          // While CloseIdleConnections is enable, we also close idle connection
          client.timeOut();
          ctx.close();
        }
      }
    }
  }
  ctx.fireUserEventTriggered(evt);
}
 
Example 12
Project: NioImapClient   File: ResponseDecoder.java   View Source Code Vote up 5 votes
private void handleBye(ByteBuf in, ChannelHandlerContext handlerContext) {
  String message = lineParser.parse(in);

  UntaggedResponse response = new UntaggedResponse.Builder()
      .setType(UntaggedResponseType.BYE)
      .setMessage(message)
      .build();

  untaggedResponses.add(response);

  handlerContext.fireUserEventTriggered(new ByeEvent(response));
}
 
Example 13
Project: CustomWorldGen   File: ServerToClientConnectionEstablishedHandler.java   View Source Code Vote up 5 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception
{
    if (evt instanceof NetworkHandshakeEstablished)
    {
        ctx.writeAndFlush(new ForgeMessage.FluidIdMapMessage());
        return;
    }
    // pass it forward
    ctx.fireUserEventTriggered(evt);
}
 
Example 14
Project: hekate   File: NettyClient.java   View Source Code Vote up 4 votes
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof HandshakeDoneEvent) {
        HandshakeDoneEvent handshake = (HandshakeDoneEvent)evt;

        if (trace) {
            log.trace("Processing handshake event [to={}, event={}]", id, evt);
        }

        // Try to update state and decide on whether the user callback should be notified.
        boolean notify = withLock(() -> {
            if (handshake.epoch() == client.epoch && state == CONNECTING) {
                if (debug) {
                    log.debug("Updated connection state [old={}, new={}, to={}]", state, CONNECTED, id);
                }

                state = CONNECTED;

                return true;
            } else {
                return false;
            }
        });

        // Notify callback and future.
        if (notify) {
            callback.onConnect(client);

            epochConnFuture.complete(client);
        } else {
            if (trace) {
                log.trace("Skipped processing of handshake event [to={}, event={}]", id, evt);
            }
        }
    }

    // Check that channel wasn't closed by the callback.
    if (ctx.channel().isOpen()) {
        ctx.fireUserEventTriggered(evt);
    }
}
 
Example 15
Project: NioImapClient   File: ImapCodec.java   View Source Code Vote up 4 votes
@Override
protected void decode(ChannelHandlerContext ctx, Object msg, List<Object> out) throws Exception {
  if (msg instanceof ContinuationResponse) {
    out.add(msg);
  } else if (msg instanceof TaggedResponse) {
    TaggedResponse taggedResponse = ((TaggedResponse) msg);
    fireEvents(ctx, taggedResponse);
    switch (clientState.getCurrentCommand().getCommandType()) {
      case SEARCH:
        taggedResponse = new SearchResponse.Builder().fromResponse(taggedResponse);
        break;
      case LIST:
        taggedResponse = new Builder().fromResponse(taggedResponse);
        break;
      case SELECT:
      case EXAMINE:
        taggedResponse = new OpenResponse.Builder().fromResponse(taggedResponse);

        ctx.fireUserEventTriggered(new OpenEvent(((OpenResponse) taggedResponse)));
        break;
      case FETCH:
        if (CommandUtils.isStreamingFetch(clientState.getCurrentCommand())) {
          taggedResponse = new StreamingFetchResponse.Builder().fromResponse(taggedResponse);
        } else {
          taggedResponse = new FetchResponse.Builder().fromResponse(taggedResponse);
        }

        break;
      case CAPABILITY:
        taggedResponse = new CapabilityResponse.Builder().fromResponse(taggedResponse);
        break;
      case NOOP:
        taggedResponse = new NoopResponse.Builder().fromResponse(taggedResponse);
        break;
      default:
        break;
    }

    out.add(taggedResponse);
  }
}