org.apache.thrift.async.TAsyncMethodCall Java Examples
The following examples show how to use
org.apache.thrift.async.TAsyncMethodCall.
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: CallBack.java From ikasoa with MIT License | 5 votes |
@Override public String getResult() throws TException { if (getState() != TAsyncMethodCall.State.RESPONSE_READ) throw new IllegalStateException("Method call not finished !"); return (new ServiceClientImpl( client.getProtocolFactory().getProtocol(new TMemoryInputTransport(getFrameBuffer().array())))) .recvGet(); }
Example #2
Source File: AsyncEchoTestClient.java From pinpoint with Apache License 2.0 | 5 votes |
@Override public void verifyTraces(PluginTestVerifier verifier, String expectedMessage) throws Exception { final InetSocketAddress socketAddress = this.environment.getServerAddress(); final String hostName = SocketAddressUtils.getHostNameFirst(socketAddress); // refer to com.navercorp.pinpoint.plugin.thrift.ThriftUtils#getHostPort final String remoteAddress = HostAndPort.toHostAndPortString(hostName, socketAddress.getPort()); // ********** 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", remoteAddress + "/com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo"); ExpectedTrace callTrace = event("THRIFT_CLIENT", // ServiceType call, // Method null, // rpc null, // endPoint remoteAddress, // destinationId thriftUrl // Annotation("thrift.url") ); verifier.verifyTrace(async(callTrace, asyncInvocationTrace, cleanUpAndFireCallbackTrace, receiveBaseTrace)); }
Example #3
Source File: ThriftUtils.java From pinpoint with Apache License 2.0 | 5 votes |
/** * 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(); String convertedMethodCallName = convertDotPathToUriPath(ThriftConstants.ASYNC_METHOD_CALL_PATTERN.matcher(asyncMethodCallClassName).replaceAll(".")); // thrift java generator appends "_call" to the method name when naming the function class // https://github.com/apache/thrift/blob/master/compiler/cpp/src/thrift/generate/t_java_generator.cc#L3151 final String callSuffix = "_call"; if (convertedMethodCallName.endsWith(callSuffix)) { return convertedMethodCallName.substring(0, convertedMethodCallName.length() - callSuffix.length()); } return convertedMethodCallName; }
Example #4
Source File: TAsyncClientManagerCallInterceptor.java From pinpoint with Apache License 2.0 | 4 votes |
@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); } }