Search in sources :

Example 56 with TProtocol

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

the class AnnotationTranscoderTest method write.

private void write(int value) throws TException {
    TCompactProtocol.Factory factory = new TCompactProtocol.Factory();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(16);
    TIOStreamTransport transport = new TIOStreamTransport(baos);
    TProtocol protocol = factory.getProtocol(transport);
    protocol.writeI32(value);
    byte[] buffer = baos.toByteArray();
    logger.debug(Arrays.toString(buffer));
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) LoggerFactory(org.slf4j.LoggerFactory) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

Example 57 with TProtocol

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

the class ByteSizeTest method test.

@Test
public void test() throws TException {
    TCompactProtocol.Factory factory = new TCompactProtocol.Factory();
    ByteArrayOutputStream baos = new ByteArrayOutputStream(16);
    TIOStreamTransport transport = new TIOStreamTransport(baos);
    TProtocol protocol = factory.getProtocol(transport);
    long l = TimeUnit.DAYS.toMillis(1);
    logger.debug("day:{}", l);
    long currentTime = System.currentTimeMillis();
    logger.debug("currentTime:{}" + currentTime);
    protocol.writeI64(l);
    byte[] buffer = baos.toByteArray();
    logger.debug("{}", buffer.length);
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) LoggerFactory(org.slf4j.LoggerFactory) TIOStreamTransport(org.apache.thrift.transport.TIOStreamTransport) ByteArrayOutputStream(java.io.ByteArrayOutputStream) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol) Test(org.junit.Test)

Example 58 with TProtocol

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

the class TBaseProcessorProcessInterceptor method processTraceObject.

private void processTraceObject(final Trace trace, Object target, Object[] args, Throwable throwable) {
    // end spanEvent
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        // TODO Might need a way to collect and record method arguments
        // trace.recordAttribute(...);
        recorder.recordException(throwable);
        recorder.recordApi(this.descriptor);
    } catch (Throwable t) {
        logger.warn("Error processing trace object. Cause:{}", t.getMessage(), t);
    } finally {
        trace.traceBlockEnd();
    }
    // end root span
    SpanRecorder recorder = trace.getSpanRecorder();
    String methodUri = getMethodUri(target);
    recorder.recordRpcName(methodUri);
    // retrieve connection information
    String localIpPort = ThriftConstants.UNKNOWN_ADDRESS;
    String remoteAddress = ThriftConstants.UNKNOWN_ADDRESS;
    if (args.length == 2 && args[0] instanceof TProtocol) {
        TProtocol inputProtocol = (TProtocol) args[0];
        TTransport inputTransport = inputProtocol.getTransport();
        if (inputTransport instanceof SocketFieldAccessor) {
            Socket socket = ((SocketFieldAccessor) inputTransport)._$PINPOINT$_getSocket();
            if (socket != null) {
                localIpPort = ThriftUtils.getHostPort(socket.getLocalSocketAddress());
                remoteAddress = ThriftUtils.getHost(socket.getRemoteSocketAddress());
            }
        } else {
            if (isDebug) {
                logger.debug("Invalid target object. Need field accessor({}).", SocketFieldAccessor.class.getName());
            }
        }
    }
    if (localIpPort != ThriftConstants.UNKNOWN_ADDRESS) {
        recorder.recordEndPoint(localIpPort);
    }
    if (remoteAddress != ThriftConstants.UNKNOWN_ADDRESS) {
        recorder.recordRemoteAddress(remoteAddress);
    }
}
Also used : SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) TProtocol(org.apache.thrift.protocol.TProtocol) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) SocketFieldAccessor(com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor) TTransport(org.apache.thrift.transport.TTransport) Socket(java.net.Socket)

Example 59 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project commons by twitter.

the class PingPongClient method run.

@Override
public void run() {
    TTransport transport = new TSocket("localhost", THRIFT_PORT.get());
    try {
        transport.open();
    } catch (TTransportException e) {
        throw new RuntimeException(e);
    }
    TProtocol protocol = new TBinaryProtocol(transport);
    PingPong.Client client = new PingPong.Client(protocol);
    try {
        LOG.info("Pinging...");
        LOG.info(client.ping());
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) PingPong(com.twitter.common.examples.pingpong.PingPong) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 60 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project eiger by wlloyd.

the class EmbeddedCassandraServiceTest method getClient.

/**
     * Gets a connection to the localhost client
     *
     * @return
     * @throws TTransportException
     */
private Cassandra.Client getClient() throws TTransportException {
    TTransport tr = new TFramedTransport(new TSocket("localhost", DatabaseDescriptor.getRpcPort()));
    TProtocol proto = new TBinaryProtocol(tr);
    Cassandra.Client client = new Cassandra.Client(proto);
    tr.open();
    return client;
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

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