コード例 #1
0
 /** 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 = NettyUtils.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);
 }
コード例 #2
0
 @Override
 protected void messageReceived(ChannelHandlerContext ctx, FullHttpResponse msg) throws Exception {
   if (!handshaker.isHandshakeComplete()) {
     handshaker.finishHandshake(ctx.channel(), msg);
     ctx.fireUserEventTriggered(
         WebSocketClientProtocolHandler.ClientHandshakeStateEvent.HANDSHAKE_COMPLETE);
     ctx.pipeline().remove(this);
     return;
   }
   throw new IllegalStateException("WebSocketClientHandshaker should have been non finished yet");
 }
コード例 #3
0
  /**
   * Encode (for some cheap value of 'encode') a resulting resource into a ResourceState.
   *
   * @param ctx
   * @param response The response to encode.
   * @throws Exception
   */
  protected void encode(ChannelHandlerContext ctx, ResourceResponse response) {
    final ClientResourceResponse.ResponseType responseType = ClientResourceResponse.ResponseType.OK;
    if (response.resource() == null) {
      ctx.writeAndFlush(
          new ClientResourceResponseImpl(
              response.inReplyTo(),
              responseType,
              response.inReplyTo().resourcePath().toString(),
              null));
      ctx.fireUserEventTriggered(new RequestCompleteEvent(response.requestId()));
      return;
    }

    ctx.writeAndFlush(
        new ClientResourceResponseImpl(
            response.inReplyTo(),
            responseType,
            response.inReplyTo().resourcePath().toString(),
            response.state()));
    ctx.fireUserEventTriggered(new RequestCompleteEvent(response.requestId()));
  }
コード例 #4
0
ファイル: SslHandler.java プロジェクト: njutony1991/netty
  /** Notify all the handshake futures about the successfully handshake */
  private void setHandshakeSuccess() {
    // Work around the JVM crash which occurs when a cipher suite with GCM enabled.
    final String cipherSuite = String.valueOf(engine.getSession().getCipherSuite());
    if (!wantsDirectBuffer && (cipherSuite.contains("_GCM_") || cipherSuite.contains("-GCM-"))) {
      wantsInboundHeapBuffer = true;
    }

    handshakePromise.trySuccess(ctx.channel());

    if (logger.isDebugEnabled()) {
      logger.debug("{} HANDSHAKEN: {}", ctx.channel(), engine.getSession().getCipherSuite());
    }
    ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS);

    if (readDuringHandshake && !ctx.channel().config().isAutoRead()) {
      readDuringHandshake = false;
      ctx.read();
    }
  }
コード例 #5
0
    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
      if (evt instanceof IdleStateEvent) {
        IdleStateEvent event = (IdleStateEvent) evt;

        Channel channel = new NettyChannel(ctx);

        final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(channel);

        if (event.state().equals(io.netty.handler.timeout.IdleState.ALL_IDLE)) {
          LOGGER.warn("CLIENT : IDLE [{}]", remoteAddress);
          closeChannel(channel);
        }

        if (channelEventListener != null) {
          RemotingEventType remotingEventType = RemotingEventType.valueOf(event.state().name());
          putRemotingEvent(new RemotingEvent(remotingEventType, remoteAddress, channel));
        }
      }

      ctx.fireUserEventTriggered(evt);
    }
コード例 #6
0
ファイル: SslHandler.java プロジェクト: njutony1991/netty
 private void notifyHandshakeFailure(Throwable cause) {
   if (handshakePromise.tryFailure(cause)) {
     ctx.fireUserEventTriggered(new SslHandshakeCompletionEvent(cause));
     ctx.close();
   }
 }
コード例 #7
0
  @Override
  public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {

    if (evt == SessionState.Connect) {

      final CMPPEndpointEntity finalentity = (CMPPEndpointEntity) getEndpointEntity();
      final Channel ch = ctx.channel();
      EventLoopGroupFactory.INS.submitUnlimitCircleTask(
          new Callable<Boolean>() {
            private Message createTestReq() {

              Map<String, Object> map = new HashMap<String, Object>();
              map.put("chanid", "Z001");
              map.put("b", "adf");

              if (finalentity instanceof ServerEndpoint) {
                CmppDeliverRequestMessage msg = new CmppDeliverRequestMessage();
                msg.setDestId("10085");
                msg.setLinkid("0000");
                msg.setMsgContent("SMRZ");

                msg.setMsgId(new MsgId());
                msg.setRegisteredDelivery((short) 0);
                if (msg.getRegisteredDelivery() == 1) {
                  msg.setReportRequestMessage(new CmppReportRequestMessage());
                }
                // msg.setServiceid("10085101");
                msg.setSrcterminalId("13800138000");
                msg.setSrcterminalType((short) 1);
                msg.setAttachment((Serializable) map);
                return msg;
              } else {
                CmppSubmitRequestMessage msg = new CmppSubmitRequestMessage();
                msg.setDestterminalId(String.valueOf(System.nanoTime()));
                msg.setLinkID("0000");
                msg.setMsgContent("下行测试");
                msg.setMsgid(new MsgId());
                msg.setServiceId("10086");
                msg.setSrcId("10086");
                msg.setAttachment((Serializable) map);
                return msg;
              }
            }

            @Override
            public Boolean call() throws Exception {

              //	logger.info("last msg cnt : {}" ,totleCnt<0?0:totleCnt);
              while (totleCnt-- > 0) {
                ChannelFuture future =
                    ChannelUtil.asyncWriteToEntity(getEndpointEntity(), createTestReq());
                future.sync();
              }
              return true;
            }
          },
          new ExitUnlimitCirclePolicy() {
            @Override
            public boolean notOver(Future future) {

              return true;
            }
          },
          1000);
    }
    ctx.fireUserEventTriggered(evt);
  }
コード例 #8
0
ファイル: SslHandler.java プロジェクト: hsoumare/netty
 /** Notify all the handshake futures about the successfully handshake */
 private void setHandshakeSuccess() {
   if (handshakePromise.trySuccess(ctx.channel())) {
     ctx.fireUserEventTriggered(SslHandshakeCompletionEvent.SUCCESS);
   }
 }