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

The following examples show how to use io.netty.channel.ChannelHandlerContext#fireUserEventTriggered() . 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 check out the related API usage on the sidebar.
Example 1
Source File: MutualAuthHandler.java    From xio with 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 2
Source File: HttpClientPipelineConfigurator.java    From armeria with Apache License 2.0 6 votes vote down vote up
/**
 * 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 3
Source File: DefaultNettyConnection.java    From servicetalk with Apache License 2.0 6 votes vote down vote up
@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 4
Source File: NettyRemotingServer.java    From rocketmq-all-4.1.0-incubating with 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事件,在指定时间没有进行读写,会进行回调
         */
        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 5
Source File: NettyRemotingServer.java    From rocketmq with 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 6
Source File: NoConnectIdleHandler.java    From hivemq-community-edition with Apache License 2.0 6 votes vote down vote up
@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 7
Source File: HttpChannelHandler.java    From proxy with 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
Source File: FramebufferUpdateRectDecoder.java    From jfxvnc with Apache License 2.0 6 votes vote down vote up
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 9
Source File: NettyRemotingClient.java    From rocketmq-4.3.0 with 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 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 10
Source File: WebSocketClientProtocolHandshakeHandler.java    From netty-4.1.22 with Apache License 2.0 6 votes vote down vote up
@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 11
Source File: HardwareChannelStateHandler.java    From blynk-server with GNU General Public License v3.0 5 votes vote down vote up
@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 12
Source File: RtspInterleavedHandler.java    From arcusplatform with Apache License 2.0 5 votes vote down vote up
@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
Source File: ResponseDecoder.java    From NioImapClient with 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 14
Source File: HttpRequestReadTimeoutHandler.java    From zuul with Apache License 2.0 4 votes vote down vote up
@Override
protected void readTimedOut(ChannelHandlerContext ctx) throws Exception
{
    ctx.fireUserEventTriggered(HttpRequestReadTimeoutEvent.INSTANCE);
}
 
Example 15
Source File: Http2FrameCodec.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
void onHttp2StreamStateChanged(ChannelHandlerContext ctx, Http2FrameStream stream) {
    ctx.fireUserEventTriggered(Http2FrameStreamEvent.stateChanged(stream));
}
 
Example 16
Source File: FilterLogginglHandler.java    From netty-http-server with Apache License 2.0 4 votes vote down vote up
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
    ctx.fireUserEventTriggered(evt);
}
 
Example 17
Source File: Http2FrameCodec.java    From netty-4.1.22 with 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
Source File: EndpointedChannelHandler.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
  if (DEBUG_CALLS) Gdx.app.debug(TAG, "userEventTriggered");
  ctx.fireUserEventTriggered(evt);
}
 
Example 19
Source File: Http1ResponseDecoder.java    From armeria with Apache License 2.0 4 votes vote down vote up
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    ctx.fireUserEventTriggered(evt);
}
 
Example 20
Source File: ExceptionChannelHandler.java    From journalkeeper with Apache License 2.0 4 votes vote down vote up
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    ctx.fireUserEventTriggered(evt);
}