Search in sources :

Example 61 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project logprocessing by cloudian.

the class CassandraClient method open.

public void open() throws IOException {
    try {
        this.currentServer = this.serverSet.get();
    } catch (ServerSet.NoServersAvailableException e) {
        throw new IOException("No Cassandra servers available.");
    }
    int splitIndex = this.currentServer.indexOf(':');
    if (splitIndex == -1) {
        throw new IOException("Bad host:port pair: " + this.currentServer);
    }
    String host = this.currentServer.substring(0, splitIndex);
    int port = Integer.parseInt(this.currentServer.substring(splitIndex + 1));
    TSocket sock = new TSocket(host, port);
    this.transport = new TFramedTransport(sock);
    TProtocol protocol = new TBinaryProtocol(transport);
    this.client = new Cassandra.Client(protocol);
    try {
        this.transport.open();
        this.client.set_keyspace(this.keyspace);
    } catch (TException texc) {
        throw new IOException(texc.getMessage());
    } catch (InvalidRequestException exc) {
        throw new IOException(exc.getMessage());
    }
}
Also used : TException(org.apache.thrift.TException) Cassandra(org.apache.cassandra.thrift.Cassandra) IOException(java.io.IOException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) InvalidRequestException(org.apache.cassandra.thrift.InvalidRequestException) TSocket(org.apache.thrift.transport.TSocket)

Example 62 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 63 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 64 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 65 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)

Aggregations

TProtocol (org.apache.thrift.protocol.TProtocol)93 TTransport (org.apache.thrift.transport.TTransport)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TSocket (org.apache.thrift.transport.TSocket)36 TException (org.apache.thrift.TException)25 TFramedTransport (org.apache.thrift.transport.TFramedTransport)24 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)18 IOException (java.io.IOException)16 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)10 THttpClient (org.apache.thrift.transport.THttpClient)9 ArrayList (java.util.ArrayList)8 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 TProcessor (org.apache.thrift.TProcessor)6 InputStream (java.io.InputStream)5 TTransportFactory (org.apache.thrift.transport.TTransportFactory)5 ImageDatasetService (org.vcell.imagedataset.ImageDatasetService)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)4