Java 类org.apache.thrift.async.TAsyncMethodCall 实例源码

项目:NeverwinterDP-Commons    文件:scribe.java   
public ResultCode getResult() throws org.apache.thrift.TException {
  if (getState() != org.apache.thrift.async.TAsyncMethodCall.State.RESPONSE_READ) {
    throw new IllegalStateException("Method call not finished!");
  }
  TMemoryInputTransport memoryTransport = new TMemoryInputTransport(getFrameBuffer().array());
  TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
  return (new Client(prot)).recv_Log();
}
项目:pinpoint    文件:AsyncEchoTestClient.java   
@Override
public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception {
    final InetSocketAddress actualServerAddress = this.environment.getServerAddress();
    // ********** Asynchronous Traces
    // SpanEvent - Asynchronous Invocation
    ExpectedTrace asyncInvocationTrace = event("ASYNC", "Asynchronous Invocation");

    // SpanEvent - TAsyncMethodCall.cleanUpAndFireCallback
    Method cleanUpAndFireCallback = TAsyncMethodCall.class.getDeclaredMethod("cleanUpAndFireCallback",
            SelectionKey.class);
    ExpectedTrace cleanUpAndFireCallbackTrace = event("THRIFT_CLIENT_INTERNAL", cleanUpAndFireCallback);

    // SpanEvent - TServiceClient.receiveBase
    Method receiveBase = TServiceClient.class.getDeclaredMethod("receiveBase", TBase.class, String.class);
    ExpectedAnnotation thriftResult = Expectations.annotation("thrift.result", "echo_result(success:"
            + expectedMessage + ")");
    ExpectedTrace receiveBaseTrace = event("THRIFT_CLIENT_INTERNAL", // ServiceType
            receiveBase, // Method
            thriftResult // Annotation("thrift.result")
    );

    // ********** Root trace for Asynchronous traces
    // SpanEvent - TAsyncClientManager.call
    Method call = TAsyncClientManager.class.getDeclaredMethod("call", TAsyncMethodCall.class);
    ExpectedAnnotation thriftUrl = Expectations.annotation("thrift.url", actualServerAddress.getHostName() + ":"
            + actualServerAddress.getPort() + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo_call");
    ExpectedTrace callTrace = event("THRIFT_CLIENT", // ServiceType
            call, // Method
            null, // rpc
            null, // endPoint
            actualServerAddress.getHostName() + ":" + actualServerAddress.getPort(), // destinationId
            thriftUrl // Annotation("thrift.url")
    );
    verifier.verifyTrace(async(callTrace, asyncInvocationTrace, cleanUpAndFireCallbackTrace, receiveBaseTrace));
}
项目:ikasoa    文件:CallBack.java   
public String getResult() throws TException {
    if (getState() != TAsyncMethodCall.State.RESPONSE_READ)
        throw new IllegalStateException("Method call not finished !");
    TProtocol prot = client.getProtocolFactory().getProtocol(new TMemoryInputTransport(getFrameBuffer().array()));
    return (new ServiceClientImpl(prot)).recvGet();
}
项目:pinpoint    文件:ThriftUtils.java   
/**
 * Returns the name of the specified {@link org.apache.thrift.async.TAsyncMethodCall TAsyncMethodCall}
 * to be used in Pinpoint.
 */
public static String getAsyncMethodCallName(TAsyncMethodCall<?> asyncMethodCall) {
    String asyncMethodCallClassName = asyncMethodCall.getClass().getName();
    return convertDotPathToUriPath(ThriftConstants.ASYNC_METHOD_CALL_PATTERN.matcher(asyncMethodCallClassName).replaceAll("."));
}
项目:pinpoint    文件:TAsyncClientManagerCallInterceptor.java   
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }

    if (!validate(target, args)) {
        return;
    }

    final Trace trace = this.traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }

    try {
        ThriftRequestProperty parentTraceInfo = new ThriftRequestProperty();
        final boolean shouldSample = trace.canSampled();
        if (!shouldSample) {
            if (isDebug) {
                logger.debug("set Sampling flag=false");
            }
            parentTraceInfo.setShouldSample(shouldSample);
        } else {
            SpanEventRecorder recorder = trace.traceBlockBegin();
            Object asyncMethodCallObj = args[0];
            // inject async trace info to AsyncMethodCall object
            injectAsyncContext(asyncMethodCallObj, recorder);

            // retrieve connection information
            String remoteAddress = getRemoteAddress(asyncMethodCallObj);

            final TraceId nextId = trace.getTraceId().getNextTraceId();

            // Inject nextSpanId as the actual sending of data will be handled asynchronously.
            final long nextSpanId = nextId.getSpanId();
            parentTraceInfo.setSpanId(nextSpanId);

            parentTraceInfo.setTraceId(nextId.getTransactionId());
            parentTraceInfo.setParentSpanId(nextId.getParentSpanId());

            parentTraceInfo.setFlags(nextId.getFlags());
            parentTraceInfo.setParentApplicationName(this.traceContext.getApplicationName());
            parentTraceInfo.setParentApplicationType(this.traceContext.getServerTypeCode());
            parentTraceInfo.setAcceptorHost(remoteAddress);


            recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
            recorder.recordNextSpanId(nextSpanId);
            recorder.recordDestinationId(remoteAddress);

            String methodUri = ThriftUtils.getAsyncMethodCallName((TAsyncMethodCall<?>) asyncMethodCallObj);
            String thriftUrl = remoteAddress + "/" + methodUri;
            recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
        }
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        currentTransaction.setAttachment(parentTraceInfo);
    } catch (Throwable t) {
        logger.warn("BEFORE error. Caused:{}", t.getMessage(), t);
    }
}