服务端记录反序列化请求的大小和耗时

@param requestCommand 请求对象
162421
private void recordDeserializeRequest(RequestCommand requestCommand) {
        if (!RpcInternalContext.isAttachmentEnable()) {
            return;
        }
        RpcInternalContext context = RpcInternalContext.getContext();
        int cost = context.getStopWatch().tick().read();
        int requestSize = RpcProtocol.getRequestHeaderLength()
            + requestCommand.getClazzLength()
            + requestCommand.getContentLength()
            + requestCommand.getHeaderLength();
        // 记录请求反序列化大小和请求反序列化耗时
        context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_SIZE, requestSize);
        context.setAttachment(RpcConstants.INTERNAL_KEY_REQ_DESERIALIZE_TIME, cost);
    }
775707
function queryRequest(queryOptions) {

    if (!queryOptions) {
        return;
    }

    var options = util._extend({}, queryOptions);

    if (options.query && options.query.length) {
        options.query = '&sq=' + encodeURIComponent(options.query);
    }

    if (options.sort) {
        options.orderBy = '&orderby=column:' + options.sort;
        delete options.sort;
    }

    if (options.descending) {
        options.reverse = '&reverse=true';
        delete options.descending;
    }

    return options;
}
448289
public static String removeSemicolonContent(String requestUri) {
		int semicolonIndex = requestUri.indexOf(';');
		while (semicolonIndex != -1) {
			int slashIndex = requestUri.indexOf('/', semicolonIndex);
			String start = requestUri.substring(0, semicolonIndex);
			requestUri = (slashIndex != -1) ? start + requestUri.substring(slashIndex) : start;
			semicolonIndex = requestUri.indexOf(';', semicolonIndex);
		}
		return requestUri;
	}
150759
private function readNameValuePair(int $requestId, ?string &$buffer): void
    {
        $nameLength  = $this->readFieldLength($buffer);
        $valueLength = $this->readFieldLength($buffer);

        $contentFormat = (
            'a'.$nameLength.'name/'.
            'a'.$valueLength.'value/'
        );

        $content = unpack($contentFormat, $buffer);
        $this->requests[$requestId]['params'][$content['name']] = $content['value'];

        $buffer = substr($buffer, $nameLength + $valueLength);
    }
204668
@Override
	public void handleRequest(final Request request) {
		if (clrBtn.isPressed()) {
			textFld.setText("");
		} else if (dupBtn.isPressed()) {
			// Get the text entered by the user.
			String text = textFld.getText();

			// Now duplicate it.
			textFld.setText(text + text);
		}
	}
820014
public function makeSignPlainText($requestParams, $requestMethod = 'POST', $requestHost = '', $requestPath = '/v2/index.php')
    {
        $url = $requestHost . $requestPath;
        // 取出所有的参数
        $paramStr = $this->_buildParamStr($requestParams, $requestMethod);
        $plainText = $requestMethod . $url . $paramStr;
        return $plainText;
    }
1036044
void handleRequest(ByteBuf buffer) {
    long requestId = buffer.readLong();

    try {
      Object request = readRequest(buffer);
      HandlerHolder handler = handlers.get(request.getClass());
      if (handler != null) {
        handler.context.executor().execute(() -> handleRequest(requestId, request, handler));
      } else {
        handleRequestFailure(requestId, new SerializationException("unknown message type: " + request.getClass()), this.context);
      }
    } catch (SerializationException e) {
      handleRequestFailure(requestId, e, this.context);
    } finally {
      buffer.release();
    }
  }
284531
public void setRequesttimeout(double requesttimeout) {
	long rt;
	if (requesttimeout <= 0) rt = Long.MAX_VALUE;
	else rt = (long) (requesttimeout * 1000);

	pageContext.setRequestTimeout(rt);
    }
318726
public void setRequestMap(final Map<String, Object> requestMap) {
		JKThreadLocal.setValue(JKContextConstants.HTTP_REQUEST_MAP, requestMap);
	}
220379
@NotNull
    @ObjectiveCName("requestIntegrationTokenCommandWithGid:")
    public Command<String> requestIntegrationToken(int gid) {
        return callback -> modules.getGroupsModule().requestIntegrationToken(gid)
                .then(v -> callback.onResult(v))
                .failure(e -> callback.onError(e));
    }
917434
public void addTargetRequest(String requestString) {
        if (StringUtils.isBlank(requestString) || requestString.equals("#")) {
            return;
        }
        requestString = UrlUtils.canonicalizeUrl(requestString, url.toString());
        targetRequests.add(new Request(requestString));
    }
1153043
@Override
  public Answer processRequest(Request request) {
    if (logger.isInfoEnabled()) {
      logger.info("Diameter Stack Mux :: processRequest :: Command-Code [" + request.getCommandCode() + "]");
    }

    DiameterListener listener = findListener(request);

    if (listener != null) {
      return listener.processRequest(request);
    }
    else {
      try {
        Answer answer = request.createAnswer(ResultCode.APPLICATION_UNSUPPORTED);
        //this.stack.getSessionFactory().getNewRawSession().send(answer);
        return answer;
      }
      catch (Exception e) {
        logger.error("Failed to create APPLICATION UNSUPPORTED answer.", e);
      }
    }
    return null;
  }
1085922
function (args) {
            var req = args.req;
            var handler = args.requestHandler;
            if (handler == null) {
                handler = this.__getRequestHandler();
            }

            req.data = (req.data == null && req.method == "POST")
                    ? handler.prepareRequestBody(req.jsonData, req.requestObject)
                    : req.data;
            req.headers = handler.getRequestHeaders();
            if (req.requestObject.headers) {
                req.headers = ariaUtilsJson.copy(req.headers, false);
                ariaUtilsJson.inject(req.requestObject.headers, req.headers, false);
            }

            // call the server
            var senderObject = {
                classpath : this.$classpath,
                requestObject : req.requestObject,
                requestData : req.jsonData,

                // the following two properties can be used to communicate from the filters to the RequestMgr and bypass
                // the handler:
                responseData : null,
                responseErrorData : null
            };

            var requestObject = {
                sender : senderObject,
                url : req.url,
                async : (req.requestObject.async !== false),
                method : req.method,
                data : req.data,
                headers : req.headers,
                timeout : req.timeout,
                callback : {
                    fn : this._onresponse,
                    onerror : this._onresponse,
                    scope : this,
                    args : {
                        requestObject : req.requestObject,
                        senderObject : senderObject,
                        cb : args.cb,
                        id : args.id,
                        session : args.session,
                        actionQueuing : args.actionQueuing,
                        requestHandler : handler
                    }
                }
            };
            if (handler.expectedResponseType) {
                requestObject.expectedResponseType = handler.expectedResponseType;
            }
            ariaCoreIO.asyncRequest(requestObject);
        }
754795
@CommandHandler
    public void handle(RequestStartTransactionAcceptedCommand command) {
        apply(new RequestStartTransactionAcceptedEvent(command.getChargingStationId(), command.getEvseId(), command.getIdentifyingToken(), command.getIdentityContext()));
    }
723675
@Override
  public Answer processRequest(Request request) {
    dumpMessage(request,false);
    if (request.getCommandCode() != commandCode) {
      log.error("Received bad answer: " + request.getCommandCode());
      return null;
    }
    AvpSet requestAvpSet = request.getAvps();

    Avp exchangeTypeAvp = requestAvpSet.getAvp(exchangeTypeCode, vendorID);
    Avp exchangeDataAvp = requestAvpSet.getAvp(exchangeDataCode, vendorID);
    if (exchangeTypeAvp == null) {
      log.error("Request does not have Exchange-Type");

      Answer answer = createAnswer(request, 5004, EXCHANGE_TYPE_TERMINATING);
      dumpMessage(answer,true);
      return answer; // set
                                      // exchange
                                      // type
                                      // to
                                      // terminating
    }
    if (exchangeDataAvp == null) {
      log.error("Request does not have Exchange-Data");
      Answer answer = createAnswer(request, 5004, EXCHANGE_TYPE_TERMINATING);
      dumpMessage(answer,true);
      return answer; // set
                                      // exchange
                                      // type
                                      // to
                                      // terminating
    }
    // cast back to int(Enumerated is Unsigned32, and API represents it as
    // long so its easier
    // to manipulate
    try {
      switch ((int) exchangeTypeAvp.getUnsigned32()) {
      case EXCHANGE_TYPE_INITIAL:
        // JIC check;
        String data = exchangeDataAvp.getUTF8String();
        this.session = this.factory.getNewSession(request.getSessionId());
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {
          // create session;

          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_INITIAL); // set
                                                // exchange
                                                // type
                                                // to
                                                // terminating
          toReceiveIndex++;
          dumpMessage(answer,true);
          return answer;
        } else {
          log.error("Received wrong Exchange-Data: " + data);
          Answer answer = request.createAnswer(6000);
        }
        break;
      case EXCHANGE_TYPE_INTERMEDIATE:
        // JIC check;
        data = exchangeDataAvp.getUTF8String();
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {

          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_INTERMEDIATE); // set
                                                // exchange
                                                // type
                                                // to
                                                // terminating
          toReceiveIndex++;
          dumpMessage(answer,true);
          return answer;
        } else {
          log.error("Received wrong Exchange-Data: " + data);
        }
        break;
      case EXCHANGE_TYPE_TERMINATING:
        data = exchangeDataAvp.getUTF8String();
        if (data.equals(TO_RECEIVE[toReceiveIndex])) {
          // good, we reached end of FSM.
          finished = true;
          // release session and its resources.
          Answer answer = createAnswer(request, 2001, EXCHANGE_TYPE_TERMINATING); // set
                                              // exchange
                                              // type
                                              // to
                                              // terminating
          toReceiveIndex++;
          this.session.release();
          finished = true;
          this.session = null;
          dumpMessage(answer,true);
          return answer;

        } else {
          log.error("Received wrong Exchange-Data: " + data);
        }
        break;
      default:
        log.error("Bad value of Exchange-Type avp: " + exchangeTypeAvp.getUnsigned32());
        break;
      }
    } catch (AvpDataException e) {
      // thrown when interpretation of byte[] fails
      e.printStackTrace();
    } catch (InternalException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    //error, something bad happened.
    finished = true;
    return null;
  }
70884
private Observable<R> executeCommandAndObserve(final AbstractCommand<R> _cmd) {
        final HystrixRequestContext currentRequestContext = HystrixRequestContext.getContextForCurrentThread();

        final Action1<R> markEmits = new Action1<R>() {
            @Override
            public void call(R r) {
                if (shouldOutputOnNextEvents()) {
                    executionResult = executionResult.addEvent(HystrixEventType.EMIT);
                    eventNotifier.markEvent(HystrixEventType.EMIT, commandKey);
                }
                if (commandIsScalar()) {
                    long latency = System.currentTimeMillis() - executionResult.getStartTimestamp();
                    eventNotifier.markEvent(HystrixEventType.SUCCESS, commandKey);
                    executionResult = executionResult.addEvent((int) latency, HystrixEventType.SUCCESS);
                    eventNotifier.markCommandExecution(getCommandKey(), properties.executionIsolationStrategy().get(), (int) latency, executionResult.getOrderedList());
                    circuitBreaker.markSuccess();
                }
            }
        };

        final Action0 markOnCompleted = new Action0() {
            @Override
            public void call() {
                if (!commandIsScalar()) {
                    long latency = System.currentTimeMillis() - executionResult.getStartTimestamp();
                    eventNotifier.markEvent(HystrixEventType.SUCCESS, commandKey);
                    executionResult = executionResult.addEvent((int) latency, HystrixEventType.SUCCESS);
                    eventNotifier.markCommandExecution(getCommandKey(), properties.executionIsolationStrategy().get(), (int) latency, executionResult.getOrderedList());
                    circuitBreaker.markSuccess();
                }
            }
        };

        final Func1<Throwable, Observable<R>> handleFallback = new Func1<Throwable, Observable<R>>() {
            @Override
            public Observable<R> call(Throwable t) {
                circuitBreaker.markNonSuccess();
                Exception e = getExceptionFromThrowable(t);
                executionResult = executionResult.setExecutionException(e);
                if (e instanceof RejectedExecutionException) {
                    return handleThreadPoolRejectionViaFallback(e);
                } else if (t instanceof HystrixTimeoutException) {
                    return handleTimeoutViaFallback();
                } else if (t instanceof HystrixBadRequestException) {
                    return handleBadRequestByEmittingError(e);
                } else {
                    /*
                     * Treat HystrixBadRequestException from ExecutionHook like a plain HystrixBadRequestException.
                     */
                    if (e instanceof HystrixBadRequestException) {
                        eventNotifier.markEvent(HystrixEventType.BAD_REQUEST, commandKey);
                        return Observable.error(e);
                    }

                    return handleFailureViaFallback(e);
                }
            }
        };

        final Action1<Notification<? super R>> setRequestContext = new Action1<Notification<? super R>>() {
            @Override
            public void call(Notification<? super R> rNotification) {
                setRequestContextIfNeeded(currentRequestContext);
            }
        };

        Observable<R> execution;
        if (properties.executionTimeoutEnabled().get()) {
            execution = executeCommandWithSpecifiedIsolation(_cmd)
                    .lift(new HystrixObservableTimeoutOperator<R>(_cmd));
        } else {
            execution = executeCommandWithSpecifiedIsolation(_cmd);
        }

        return execution.doOnNext(markEmits)
                .doOnCompleted(markOnCompleted)
                .onErrorResumeNext(handleFallback)
                .doOnEach(setRequestContext);
    }
461297
private boolean requestFull(TCPReadRequestContext req) {
        WsByteBuffer wsBuffArray[] = req.getBuffers();
        boolean rc = !wsBuffArray[wsBuffArray.length - 1].hasRemaining();

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "requestFull: " + rc);
        }
        return rc;
    }