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

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireUserEventTriggered() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Keeps the upgrade result in {@link #upgradeEvt}.
 */
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (!(evt instanceof UpgradeEvent)) {
        ctx.fireUserEventTriggered(evt);
        return;
    }

    final UpgradeEvent upgradeEvt = (UpgradeEvent) evt;
    if (upgradeEvt == UpgradeEvent.UPGRADE_ISSUED) {
        // Uninterested in this event
        return;
    }

    this.upgradeEvt = upgradeEvt;
}
 
Example 2
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    if (evt == CloseHandler.ProtocolPayloadEndEvent.OUTBOUND) {
        connection.channelOutboundListener.channelOutboundClosed();
    } else if (evt == ChannelOutputShutdownEvent.INSTANCE) {
        connection.closeHandler.channelClosedOutbound(ctx);
        connection.channelOutboundListener.channelClosed(StacklessClosedChannelException.newInstance(
                DefaultNettyConnection.class, "userEventTriggered(...)"));
    } else if (evt == ChannelInputShutdownReadComplete.INSTANCE) {
        // Notify close handler first to enhance error reporting
        connection.closeHandler.channelClosedInbound(ctx);
        // ChannelInputShutdownEvent is not always triggered and can get triggered before we tried to read
        // all the available data. ChannelInputShutdownReadComplete is the one that seems to (at least in
        // the current netty version) gets triggered reliably at the appropriate time.
        connection.nettyChannelPublisher.channelInboundClosed();
    } else if (evt instanceof SslHandshakeCompletionEvent) {
        connection.sslSession = extractSslSession(ctx.pipeline(), (SslHandshakeCompletionEvent) evt,
                this::tryFailSubscriber);
        if (subscriber != null) {
            assert waitForSslHandshake;
            completeSubscriber();
        }
    }
    ctx.fireUserEventTriggered(evt);
}
 
Example 3
@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 4
@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);
//                    超过空闲时间,关闭channel=》
                    closeChannel(ctx.channel());
                    if (NettyRemotingClient.this.channelEventListener != null) {
//                        发布channel空闲超时事件=》
                        NettyRemotingClient.this
                            .putNettyEvent(new NettyEvent(NettyEventType.IDLE, remoteAddress, ctx.channel()));
                    }
                }
            }

            ctx.fireUserEventTriggered(evt);
        }
 
Example 5
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (!(msg instanceof FullHttpResponse)) {
        ctx.fireChannelRead(msg);
        return;
    }

    FullHttpResponse response = (FullHttpResponse) msg;
    try {
        if (!handshaker.isHandshakeComplete()) {
            handshaker.finishHandshake(ctx.channel(), response);
            ctx.fireUserEventTriggered(
                    WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE);
            ctx.pipeline().remove(this);
            return;
        }
        throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet");
    } finally {
        response.release();
    }
}
 
Example 6
private boolean readRect(ChannelHandlerContext ctx, ByteBuf m, List<Object> out) {
  if (!m.isReadable(12)) {
    return false;
  }
  int x = m.readUnsignedShort();
  int y = m.readUnsignedShort();
  int w = m.readUnsignedShort();
  int h = m.readUnsignedShort();
  int enc = m.readInt();

  rect = new FrameRect(x, y, w, h, Encoding.valueOf(enc));
  currentRect++;
  if (logger.isTraceEnabled()){
    logger.trace("{}of{} - ({}) {}", currentRect, numberRects, rect, enc);
  }

  if (w == 0 || h == 0) {
    if (currentRect == numberRects) {
      state = State.INIT;
      ctx.fireUserEventTriggered(ProtocolState.FBU_REQUEST);
      return true;
    }
    return false;
  }
  return true;
}
 
Example 7
Source Project: proxy   File: HttpChannelHandler.java    License: MIT License 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    if (evt instanceof TransferEvent) {
        logger.debug("启动消息转发");
        synchronized (this) {
            this.transfer = true;
        }
        for (FullHttpRequest request : messages) {
            httpHandler(ctx, request);
        }
        messages.clear();
    } else {
        ctx.fireUserEventTriggered(evt);
        logger.debug("向上传递用户事件");
    }
}
 
Example 8
@Override
public void userEventTriggered(final @NotNull ChannelHandlerContext ctx, final @NotNull Object evt) {

    if (evt instanceof IdleStateEvent) {

        if (((IdleStateEvent) evt).state() == IdleState.READER_IDLE) {
            if (log.isDebugEnabled()) {

                log.debug("Client with IP {} disconnected. The client was idle for too long without sending a MQTT CONNECT packet",
                        ChannelUtils.getChannelIP(ctx.channel()).or("UNKNOWN"));
            }
            eventLog.clientWasDisconnected(ctx.channel(), "No CONNECT sent in time");
            ctx.close();
            return;
        }
    }
    ctx.fireUserEventTriggered(evt);
}
 
Example 9
Source Project: rocketmq   File: NettyRemotingServer.java    License: Apache License 2.0 6 votes vote down vote up
@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 10
Source Project: xio   File: MutualAuthHandler.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
  if (evt instanceof SslHandshakeCompletionEvent) {
    ctx.pipeline().remove(this);

    SslHandshakeCompletionEvent handshakeEvent = (SslHandshakeCompletionEvent) evt;
    String peerIdentity = TlsAuthState.UNAUTHENTICATED;
    if (handshakeEvent.isSuccess()) {
      SslHandler sslHandler = ctx.pipeline().get(SslHandler.class);
      if (sslHandler == null) {
        throw new IllegalStateException(
            "cannot find a SslHandler in the pipeline (required for MutualAuthHandler)");
      }
      peerIdentity = getPeerIdentity(sslHandler.engine());
    }
    TlsAuthState.setPeerIdentity(ctx, peerIdentity);
    peerIdentityEstablished(ctx, peerIdentity);
  }

  ctx.fireUserEventTriggered(evt);
}
 
Example 11
Source Project: NioImapClient   File: ResponseDecoder.java    License: Apache License 2.0 5 votes vote down vote up
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 12
@Override
public void userEventTriggered(@Nullable ChannelHandlerContext ctx, @Nullable Object evt) throws Exception {
   if (evt instanceof IrisRtspSdp) {
      IrisRtspSdp sdp = (IrisRtspSdp)evt;
      log.trace("interleaved sdp: {}", sdp);
   }

   ctx.fireUserEventTriggered(evt);
}
 
Example 13
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    if (evt instanceof IdleStateEvent) {
        log.trace("State handler. Hardware timeout disconnect. Event : {}. Closing.",
                ((IdleStateEvent) evt).state());
        ctx.close();
    } else {
        ctx.fireUserEventTriggered(evt);
    }
}
 
Example 14
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    ctx.fireUserEventTriggered(evt);
}
 
Example 15
Source Project: armeria   File: Http1ResponseDecoder.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    ctx.fireUserEventTriggered(evt);
}
 
Example 16
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "userEventTriggered");
  ctx.fireUserEventTriggered(evt);
}
 
Example 17
Source Project: netty-4.1.22   File: Http2FrameCodec.java    License: Apache License 2.0 4 votes vote down vote up
void onHttp2StreamWritabilityChanged(ChannelHandlerContext ctx, Http2FrameStream stream,
                                     @SuppressWarnings("unused") boolean writable) {
    ctx.fireUserEventTriggered(Http2FrameStreamEvent.writabilityChanged(stream));
}
 
Example 18
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    ctx.fireUserEventTriggered(evt);
}
 
Example 19
Source Project: netty-4.1.22   File: Http2FrameCodec.java    License: Apache License 2.0 4 votes vote down vote up
void onHttp2StreamStateChanged(ChannelHandlerContext ctx, Http2FrameStream stream) {
    ctx.fireUserEventTriggered(Http2FrameStreamEvent.stateChanged(stream));
}
 
Example 20
@Override
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception
{
    ctx.fireUserEventTriggered(HttpRequestReadTimeoutEvent.INSTANCE);
}