org.apache.servicecomb.swagger.invocation.AsyncResponse类的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(11.3k)|赞(0)|评价(0)|浏览(71)

本文整理了Java中org.apache.servicecomb.swagger.invocation.AsyncResponse类的一些代码示例,展示了AsyncResponse类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AsyncResponse类的具体详情如下:
包路径:org.apache.servicecomb.swagger.invocation.AsyncResponse
类名称:AsyncResponse

AsyncResponse介绍

暂无

代码示例

代码示例来源:origin: apache/servicecomb-java-chassis

private void fail(Throwable finalException) {
  int depth = 10;
  Throwable t = finalException;
  while (depth-- > 0) {
   if (t instanceof InvocationException) {
    asyncResp.consumerFail(t);
    return;
   }
   t = finalException.getCause();
  }
  asyncResp.consumerFail(finalException);
 }
};

代码示例来源:origin: apache/servicecomb-java-chassis

private void next(AsyncResponse asyncResponse) {
  if (handlerIndex >= faultInjectList.size()) {
   asyncResponse.complete(Response.succResp("success"));
   return;
  }

  int runIndex = handlerIndex;
  handlerIndex++;
  faultInjectList.get(runIndex).injectFault(invocation, param, response -> {
   if (response.isFailed()) {
    asyncResponse.complete(response);
   } else {
    FaultExecutor.this.next(asyncResponse);
   }
  });
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void complete(Response resp) {
  handle(resp);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void injectFault(Invocation invocation, FaultParam faultParam, AsyncResponse asyncResponse) {
 if (!shouldAbort(invocation, faultParam)) {
  asyncResponse.success(SUCCESS_RESPONSE);
  return;
 }
 // get the config values related to abort percentage.
 int errorCode = FaultInjectionUtil.getFaultInjectionConfig(invocation, "abort.httpStatus");
 if (errorCode == FaultInjectionConst.FAULT_INJECTION_DEFAULT_VALUE) {
  LOGGER.debug("Fault injection: Abort error code is not configured");
  asyncResponse.success(SUCCESS_RESPONSE);
  return;
 }
 // if request need to be abort then return failure with given error code
 CommonExceptionData errorData = new CommonExceptionData(ABORTED_ERROR_MSG);
 asyncResponse.consumerFail(new InvocationException(errorCode, ABORTED_ERROR_MSG, errorData));
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {

  // prepare the key and lookup for request count.
  String key = invocation.getTransport().getName() + invocation.getMicroserviceQualifiedName();
  AtomicLong reqCount = FaultInjectionUtil.getOperMetTotalReq(key);
  // increment the request count here after checking the delay/abort condition.
  long reqCountCurrent = reqCount.getAndIncrement();

  FaultParam param = new FaultParam(reqCountCurrent);
  Context currentContext = Vertx.currentContext();
  if (currentContext != null && currentContext.isEventLoopContext()) {
   param.setVertx(currentContext.owner());
  }

  FaultExecutor executor = new FaultExecutor(faultInjectionFeatureList, invocation, param);
  executor.execute(response -> {
   try {
    if (response.isFailed()) {
     asyncResp.complete(response);
    } else {
     invocation.next(asyncResp);
    }
   } catch (Exception e) {
    asyncResp.consumerFail(e);
   }
  });
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

private void send(Invocation invocation, AsyncResponse asyncResp, final LoadBalancer chosenLB) throws Exception {
 long time = System.currentTimeMillis();
 ServiceCombServer server = chosenLB.chooseServer(invocation);
 if (null == server) {
  asyncResp.consumerFail(new InvocationException(Status.INTERNAL_SERVER_ERROR, "No available address found."));
  return;
 }
 chosenLB.getLoadBalancerStats().incrementNumRequests(server);
 invocation.setEndpoint(server.getEndpoint());
 invocation.next(resp -> {
  // this stats is for WeightedResponseTimeRule
  chosenLB.getLoadBalancerStats().noteResponseTime(server, (System.currentTimeMillis() - time));
  if (isFailedResponse(resp)) {
   chosenLB.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(server);
   ServiceCombLoadBalancerStats.INSTANCE.markFailure(server);
  } else {
   chosenLB.getLoadBalancerStats().incrementActiveRequestsCount(server);
   ServiceCombLoadBalancerStats.INSTANCE.markSuccess(server);
  }
  asyncResp.handle(resp);
 });
}

代码示例来源:origin: apache/servicecomb-java-chassis

private boolean isLimitNewRequest(QpsController qpsController, AsyncResponse asyncResp) {
  if (qpsController.isLimitNewRequest()) {
   CommonExceptionData errorData = new CommonExceptionData("rejected by qps flowcontrol");
   asyncResp.producerFail(new InvocationException(QpsConst.TOO_MANY_REQUESTS_STATUS, errorData));
   return true;
  } else {
   return false;
  }
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) {
 HystrixObservable<Response> command = delegate.createBizkeeperCommand(invocation);
 Observable<Response> observable = command.toObservable();
 observable.subscribe(asyncResp::complete, error -> {
  LOG.warn("catch error in bizkeeper:" + error.getMessage());
  asyncResp.fail(invocation.getInvocationType(), error);
 }, () -> {
 });
}

代码示例来源:origin: apache/servicecomb-java-chassis

asyncResp.consumerFail(ar.cause());
 return;
     ar.result());
 invocation.getInvocationStageTrace().finishClientFiltersResponse();
 asyncResp.complete(response);
} catch (Throwable e) {
 invocation.getInvocationStageTrace().finishClientFiltersResponse();
 asyncResp.consumerFail(e);

代码示例来源:origin: org.apache.servicecomb/handler-loadbalance

private void send(Invocation invocation, AsyncResponse asyncResp, final LoadBalancer chosenLB) throws Exception {
 long time = System.currentTimeMillis();
 ServiceCombServer server = chosenLB.chooseServer(invocation);
 if (null == server) {
  asyncResp.consumerFail(new InvocationException(Status.INTERNAL_SERVER_ERROR, "No available address found."));
  return;
 }
 chosenLB.getLoadBalancerStats().incrementNumRequests(server);
 invocation.setEndpoint(server.getEndpoint());
 invocation.next(resp -> {
  // this stats is for WeightedResponseTimeRule
  chosenLB.getLoadBalancerStats().noteResponseTime(server, (System.currentTimeMillis() - time));
  if (isFailedResponse(resp)) {
   chosenLB.getLoadBalancerStats().incrementSuccessiveConnectionFailureCount(server);
   ServiceCombLoadBalancerStats.INSTANCE.markFailure(server);
  } else {
   chosenLB.getLoadBalancerStats().incrementActiveRequestsCount(server);
   ServiceCombLoadBalancerStats.INSTANCE.markSuccess(server);
  }
  asyncResp.handle(resp);
 });
}

代码示例来源:origin: org.apache.servicecomb/handler-fault-injection

@Override
public void injectFault(Invocation invocation, FaultParam faultParam, AsyncResponse asyncResponse) {
 if (!shouldAbort(invocation, faultParam)) {
  asyncResponse.success(SUCCESS_RESPONSE);
  return;
 }
 // get the config values related to abort percentage.
 int errorCode = FaultInjectionUtil.getFaultInjectionConfig(invocation, "abort.httpStatus");
 if (errorCode == FaultInjectionConst.FAULT_INJECTION_DEFAULT_VALUE) {
  LOGGER.debug("Fault injection: Abort error code is not configured");
  asyncResponse.success(SUCCESS_RESPONSE);
  return;
 }
 // if request need to be abort then return failure with given error code
 CommonExceptionData errorData = new CommonExceptionData(ABORTED_ERROR_MSG);
 asyncResponse.consumerFail(new InvocationException(errorCode, ABORTED_ERROR_MSG, errorData));
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {

  String token = invocation.getContext(Const.AUTH_TOKEN);
  if (null != token && authenticationTokenManager.valid(token)) {
   invocation.next(asyncResp);
  } else {
   asyncResp.producerFail(new InvocationException(new HttpStatus(401, "UNAUTHORIZED"), "UNAUTHORIZED"));
  }
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

public void send(Invocation invocation, AsyncResponse asyncResp) {
 URIEndpointObject endpoint = (URIEndpointObject) invocation.getEndpoint().getAddress();
 HttpClientWithContext httpClientWithContext;
 if (endpoint.isHttp2Enabled()) {
  httpClientWithContext = findHttp2ClientPool(invocation);
 } else {
  httpClientWithContext = findHttpClientPool(invocation);
 }
 RestClientInvocation restClientInvocation = new RestClientInvocation(httpClientWithContext, httpClientFilters);
 try {
  restClientInvocation.invoke(invocation, asyncResp);
 } catch (Throwable e) {
  asyncResp.fail(invocation.getInvocationType(), e);
  LOGGER.error("vertx rest transport send error.", e);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
 Optional<String> token = Optional.ofNullable(athenticationTokenManager.getToken());
 if (!token.isPresent()) {
  asyncResp.consumerFail(
    new IllegalStateException("rejected by consumer authentication handler"));
  return;
 }
 invocation.addContext(Const.AUTH_TOKEN, token.get());
 invocation.next(asyncResp);
}

代码示例来源:origin: org.apache.servicecomb/handler-fault-injection

@Override
 public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {

  // prepare the key and lookup for request count.
  String key = invocation.getTransport().getName() + invocation.getMicroserviceQualifiedName();
  AtomicLong reqCount = FaultInjectionUtil.getOperMetTotalReq(key);
  // increment the request count here after checking the delay/abort condition.
  long reqCountCurrent = reqCount.getAndIncrement();

  FaultParam param = new FaultParam(reqCountCurrent);
  Context currentContext = Vertx.currentContext();
  if (currentContext != null && currentContext.isEventLoopContext()) {
   param.setVertx(currentContext.owner());
  }

  FaultExecutor executor = new FaultExecutor(faultInjectionFeatureList, invocation, param);
  executor.execute(response -> {
   try {
    if (response.isFailed()) {
     asyncResp.complete(response);
    } else {
     invocation.next(asyncResp);
    }
   } catch (Exception e) {
    asyncResp.consumerFail(e);
   }
  });
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

default void success(Object result) {
 handle(Response.ok(result));
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
public void onExecutionSuccess(ExecutionContext<Invocation> context, Response response,
  ExecutionInfo info) {
 if (info.getNumberOfPastServersAttempted() > 0 || info.getNumberOfPastAttemptsOnServer() > 0) {
  LOGGER.error("Invoke server success. Operation {}; server {}",
    context.getRequest().getInvocationQualifiedName(),
    context.getRequest().getEndpoint());
 }
 if (orginExecutor != null) {
  orginExecutor.execute(() -> {
   asyncResp.complete(response);
  });
 } else {
  asyncResp.complete(response);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

@Override
 public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
  SwaggerProducerOperation producerOperation =
    invocation.getOperationMeta().getExtData(Const.PRODUCER_OPERATION);
  if (producerOperation == null) {
   asyncResp.producerFail(
     ExceptionUtils.producerOperationNotExist(invocation.getSchemaId(),
       invocation.getOperationName()));
   return;
  }
  producerOperation.invoke(invocation, asyncResp);
 }
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected void fail(Throwable e) {
 if (invocation.isFinished()) {
  return;
 }
 InvocationStageTrace stageTrace = invocation.getInvocationStageTrace();
 ConnectionBase connection = (ConnectionBase) clientRequest.connection();
 // connection maybe null when exception happens such as ssl handshake failure
 if (connection != null) {
  DefaultHttpSocketMetric httpSocketMetric = (DefaultHttpSocketMetric) connection.metric();
  stageTrace.finishGetConnection(httpSocketMetric.getRequestBeginTime());
  stageTrace.finishWriteToBuffer(httpSocketMetric.getRequestEndTime());
 }
 // even failed and did not received response, still set time for it
 // that will help to know the real timeout time
 if (stageTrace.getFinishReceiveResponse() == 0) {
  stageTrace.finishReceiveResponse();
 }
 if (stageTrace.getStartClientFiltersResponse() == 0) {
  stageTrace.startClientFiltersResponse();
 }
 stageTrace.finishClientFiltersResponse();
 asyncResp.fail(invocation.getInvocationType(), e);
}

代码示例来源:origin: apache/servicecomb-java-chassis

protected void doEndNormal() {
 try {
  genBodyBuffer();
 } catch (Exception e) {
  asyncResp.consumerFail(e);
  return;
 }
 if (bodyBuffer == null) {
  request.end();
  return;
 }
 request.end(bodyBuffer);
}

相关文章