public void invoke() { frameTrans_.reset(buffer_.array()); response_.reset(); try { if (eventHandler_ != null) { eventHandler_.processContext(context_, inTrans_, outTrans_); } ((TBaseAsyncProcessor)processorFactory_.getProcessor(inTrans_)).process(this); return; } catch (TException te) { LOGGER.warn("Exception while invoking!", te); } catch (Throwable t) { LOGGER.error("Unexpected throwable while invoking!", t); } // This will only be reached when there is a throwable. state_ = FrameBufferState.AWAITING_CLOSE; requestSelectInterestChange(); }
@Override public void verifyServerTraces(PluginTestVerifier verifier) throws Exception { final InetSocketAddress actualServerAddress = super.environment.getServerAddress(); verifier.verifyTraceCount(2); Method process = TBaseAsyncProcessor.class.getDeclaredMethod("process", AsyncFrameBuffer.class); // RootSpan verifier.verifyTrace(root("THRIFT_SERVER", // ServiceType, "Thrift Server Invocation", // Method "com/navercorp/pinpoint/plugin/thrift/dto/EchoService/echo", // rpc actualServerAddress.getHostName() + ":" + actualServerAddress.getPort(), // endPoint actualServerAddress.getHostName() // remoteAddress )); // SpanEvent - TBaseAsyncProcessor.process verifier.verifyTrace(event("THRIFT_SERVER_INTERNAL", process)); verifier.verifyTraceCount(0); }
private String getMethodUri(Object target) { String methodUri = ThriftConstants.UNKNOWN_METHOD_URI; InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation(); Object attachment = currentTransaction.getAttachment(); if (attachment instanceof ThriftClientCallContext && target instanceof TBaseAsyncProcessor) { ThriftClientCallContext clientCallContext = (ThriftClientCallContext)attachment; String methodName = clientCallContext.getMethodName(); methodUri = ThriftUtils.getAsyncProcessorNameAsUri((TBaseAsyncProcessor<?>)target); StringBuilder sb = new StringBuilder(methodUri); if (!methodUri.endsWith("/")) { sb.append("/"); } sb.append(methodName); methodUri = sb.toString(); } return methodUri; }
private static Map<String, AsyncProcessFunction<?, ?, ?>> getThriftAsyncProcessMap( Object service, Class<?> iface) { final String name = iface.getName(); if (!name.endsWith("$AsyncIface")) { return null; } final String processorName = name.substring(0, name.length() - 10) + "AsyncProcessor"; try { Class<?> processorClass = Class.forName(processorName, false, iface.getClassLoader()); if (!TBaseAsyncProcessor.class.isAssignableFrom(processorClass)) { return null; } final Constructor<?> processorConstructor = processorClass.getConstructor(iface); @SuppressWarnings("rawtypes") final TBaseAsyncProcessor processor = (TBaseAsyncProcessor) processorConstructor.newInstance(service); @SuppressWarnings("unchecked") Map<String, AsyncProcessFunction<?, ?, ?>> processMap = (Map<String, AsyncProcessFunction<?, ?, ?>>) processor.getProcessMapView(); return processMap; } catch (Exception e) { logger.debug("Failed to retrieve the asynchronous process map from:: {}", iface, e); return null; } }
/** * Returns the name of the specified {@link org.apache.thrift.TBaseAsyncProcessor TBaseAsyncProcessor} * as uri to be used in Pinpoint. */ public static String getAsyncProcessorNameAsUri(TBaseAsyncProcessor<?> asyncProcessor) { String actualAsyncProcessorName = asyncProcessor.getClass().getName(); return convertDotPathToUriPath(ThriftConstants.ASYNC_PROCESSOR_PATTERN.matcher(actualAsyncProcessorName).replaceAll(".")); }