Search in sources :

Example 11 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project Honu by jboulon.

the class TServlet method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("application/x-thrift");
    InputStream in = request.getInputStream();
    OutputStream out = response.getOutputStream();
    TTransport client = new TIOStreamTransport(in, out);
    TProcessor processor = null;
    TTransport inputTransport = null;
    TTransport outputTransport = null;
    TProtocol inputProtocol = null;
    TProtocol outputProtocol = null;
    try {
        processor = processor_;
        inputTransport = inputTransportFactory_.getTransport(client);
        outputTransport = outputTransportFactory_.getTransport(client);
        inputProtocol = inputProtocolFactory_.getProtocol(inputTransport);
        outputProtocol = outputProtocolFactory_.getProtocol(outputTransport);
        while (processor.process(inputProtocol, outputProtocol)) {
        }
    } catch (TTransportException ttx) {
    // Client died, just move on
    } catch (TException tx) {
        tx.printStackTrace();
    } catch (Exception x) {
        x.printStackTrace();
    }
    if (inputTransport != null) {
        inputTransport.close();
    }
    if (outputTransport != null) {
        outputTransport.close();
    }
}
Also used : TException(org.apache.thrift.TException) TProcessor(org.apache.thrift.TProcessor) TProtocol(org.apache.thrift.protocol.TProtocol) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TTransportException(org.apache.thrift.transport.TTransportException) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) TTransport(org.apache.thrift.transport.TTransport) ServletException(javax.servlet.ServletException) TTransportException(org.apache.thrift.transport.TTransportException) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Example 12 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.

the class SyncEchoTestClient method echo.

@Override
public final String echo(String message) throws TException {
    TProtocol protocol = this.environment.getProtocolFactory().getProtocol(transport);
    EchoService.Client client = new EchoService.Client(protocol);
    return client.echo(message);
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) EchoService(com.navercorp.pinpoint.plugin.thrift.dto.EchoService) TServiceClient(org.apache.thrift.TServiceClient)

Example 13 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.

the class TServiceClientSendBaseInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    if (target instanceof TServiceClient) {
        TServiceClient client = (TServiceClient) target;
        TProtocol oprot = client.getOutputProtocol();
        TTransport transport = oprot.getTransport();
        final Trace trace = traceContext.currentRawTraceObject();
        if (trace == null) {
            return;
        }
        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();
            recorder.recordServiceType(ThriftConstants.THRIFT_CLIENT);
            // retrieve connection information
            String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
            if (transport instanceof SocketFieldAccessor) {
                Socket socket = ((SocketFieldAccessor) transport)._$PINPOINT$_getSocket();
                if (socket != null) {
                    remoteAddress = ThriftUtils.getHostPort(socket.getRemoteSocketAddress());
                }
            } else {
                if (isDebug) {
                    logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
                }
            }
            recorder.recordDestinationId(remoteAddress);
            String methodName = ThriftConstants.UNKNOWN_METHOD_NAME;
            if (args[0] instanceof String) {
                methodName = (String) args[0];
            }
            String serviceName = ThriftUtils.getClientServiceName(client);
            String thriftUrl = getServiceUrl(remoteAddress, serviceName, methodName);
            recorder.recordAttribute(ThriftConstants.THRIFT_URL, thriftUrl);
            TraceId nextId = trace.getTraceId().getNextTraceId();
            recorder.recordNextSpanId(nextId.getSpanId());
            parentTraceInfo.setTraceId(nextId.getTransactionId());
            parentTraceInfo.setSpanId(nextId.getSpanId());
            parentTraceInfo.setParentSpanId(nextId.getParentSpanId());
            parentTraceInfo.setFlags(nextId.getFlags());
            parentTraceInfo.setParentApplicationName(traceContext.getApplicationName());
            parentTraceInfo.setParentApplicationType(traceContext.getServerTypeCode());
            parentTraceInfo.setAcceptorHost(remoteAddress);
        }
        InterceptorScopeInvocation currentTransaction = this.scope.getCurrentInvocation();
        currentTransaction.setAttachment(parentTraceInfo);
    }
}
Also used : TServiceClient(org.apache.thrift.TServiceClient) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) InterceptorScopeInvocation(com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation) TProtocol(org.apache.thrift.protocol.TProtocol) ThriftRequestProperty(com.navercorp.pinpoint.plugin.thrift.ThriftRequestProperty) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 14 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.

the class TProtocolReadMessageEndInterceptor method recordRootSpan.

private void recordRootSpan(final Trace trace, final ThriftRequestProperty parentTraceInfo, Object target) {
    // begin root span
    SpanRecorder recorder = trace.getSpanRecorder();
    recorder.recordServiceType(ThriftConstants.THRIFT_SERVER);
    recorder.recordApi(this.thriftServerEntryMethodDescriptor);
    if (!trace.isRoot()) {
        recordParentInfo(recorder, parentTraceInfo);
    }
    // record connection information here as the socket may be closed by the time the Span is popped in
    // TBaseAsyncProcessorProcessInterceptor's after section.
    TTransport transport = ((TProtocol) target).getTransport();
    recordConnection(recorder, transport);
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport)

Example 15 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project pinpoint by naver.

the class ChunkHeaderBufferedTBaseSerializer method write.

// write chunk header + header + body
private void write(final TBase<?, ?> base) throws TException {
    final TProtocol protocol = protocolFactory.getProtocol(transport);
    // write chunk header
    writeChunkHeader(protocol);
    // write header
    writeHeader(protocol, locator.headerLookup(base));
    base.write(protocol);
    if (isNeedFlush()) {
        flush();
    }
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol)

Aggregations

TProtocol (org.apache.thrift.protocol.TProtocol)78 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TTransport (org.apache.thrift.transport.TTransport)28 TSocket (org.apache.thrift.transport.TSocket)23 TException (org.apache.thrift.TException)22 TFramedTransport (org.apache.thrift.transport.TFramedTransport)17 IOException (java.io.IOException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)10 THttpClient (org.apache.thrift.transport.THttpClient)9 TTransportException (org.apache.thrift.transport.TTransportException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)7 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 TProcessor (org.apache.thrift.TProcessor)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)4 TTransportFactory (org.apache.thrift.transport.TTransportFactory)4 OutputStream (java.io.OutputStream)3