Search in sources :

Example 66 with TProtocol

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

the class ClientOnlyExample method createConnection.

private static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws TTransportException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    trans.open();
    TProtocol protocol = new TBinaryProtocol(trans);
    return new Cassandra.Client(protocol);
}
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)

Example 67 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)

Example 68 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project alluxio by Alluxio.

the class AbstractClient method connect.

/**
   * Connects with the remote.
   *
   * @throws IOException if an I/O error occurs
   * @throws ConnectionFailedException if network connection failed
   */
public synchronized void connect() throws IOException, ConnectionFailedException {
    if (mConnected) {
        return;
    }
    disconnect();
    Preconditions.checkState(!mClosed, "Client is closed, will not try to connect.");
    RetryPolicy retryPolicy = new ExponentialBackoffRetry(BASE_SLEEP_MS, MAX_SLEEP_MS, RPC_MAX_NUM_RETRY);
    while (!mClosed) {
        mAddress = getAddress();
        LOG.info("Alluxio client (version {}) is trying to connect with {} {} @ {}", RuntimeConstants.VERSION, getServiceName(), mMode, mAddress);
        TProtocol binaryProtocol = new TBinaryProtocol(mTransportProvider.getClientTransport(mParentSubject, mAddress));
        mProtocol = new TMultiplexedProtocol(binaryProtocol, getServiceName());
        try {
            mProtocol.getTransport().open();
            LOG.info("Client registered with {} {} @ {}", getServiceName(), mMode, mAddress);
            mConnected = true;
            afterConnect();
            checkVersion(getClient(), getServiceVersion());
            return;
        } catch (IOException e) {
            if (e.getMessage() != null && FRAME_SIZE_EXCEPTION_PATTERN.matcher(e.getMessage()).find()) {
                // See an error like "Frame size (67108864) larger than max length (16777216)!",
                // pointing to the helper page.
                String message = String.format("Failed to connect to %s %s @ %s: %s. " + "This exception may be caused by incorrect network configuration. " + "Please consult %s for common solutions to address this problem.", getServiceName(), mMode, mAddress, e.getMessage(), RuntimeConstants.ALLUXIO_DEBUG_DOCS_URL);
                throw new IOException(message, e);
            }
            throw e;
        } catch (TTransportException e) {
            LOG.warn("Failed to connect ({}) to {} {} @ {}: {}", retryPolicy.getRetryCount(), getServiceName(), mMode, mAddress, e.getMessage());
            if (e.getCause() instanceof java.net.SocketTimeoutException) {
                // Do not retry if socket timeout.
                String message = "Thrift transport open times out. Please check whether the " + "authentication types match between client and server. Note that NOSASL client " + "is not able to connect to servers with SIMPLE security mode.";
                throw new IOException(message, e);
            }
            // TODO(peis): Consider closing the connection here as well.
            if (!retryPolicy.attemptRetry()) {
                break;
            }
        }
    }
    // Reaching here indicates that we did not successfully connect.
    throw new ConnectionFailedException("Failed to connect to " + getServiceName() + " " + mMode + " @ " + mAddress + " after " + (retryPolicy.getRetryCount()) + " attempts");
}
Also used : TMultiplexedProtocol(org.apache.thrift.protocol.TMultiplexedProtocol) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) ExponentialBackoffRetry(alluxio.retry.ExponentialBackoffRetry) TTransportException(org.apache.thrift.transport.TTransportException) IOException(java.io.IOException) ThriftIOException(alluxio.thrift.ThriftIOException) RetryPolicy(alluxio.retry.RetryPolicy) ConnectionFailedException(alluxio.exception.ConnectionFailedException)

Example 69 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project yyl_example by Relucent.

the class HelloClient method main.

public static void main(String[] args) {
    TTransport transport = null;
    try {
        transport = new TSocket("localhost", 8090);
        transport.open();
        TProtocol protocol = new TBinaryProtocol(transport);
        HelloService.Client client = new HelloService.Client(protocol);
        System.out.println(client.hello("thrift world"));
    } catch (TException e) {
        e.printStackTrace();
    } finally {
        transport.close();
    }
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) TTransport(org.apache.thrift.transport.TTransport) TSocket(org.apache.thrift.transport.TSocket)

Example 70 with TProtocol

use of org.apache.thrift.protocol.TProtocol in project jena by apache.

the class ThriftConverter method getInputProtocol.

private static TProtocol getInputProtocol() {
    TProtocol protocol = inputProtocols.get();
    if (protocol != null)
        return protocol;
    protocol = new TCompactProtocol(getInputTransport());
    inputProtocols.set(protocol);
    return protocol;
}
Also used : TProtocol(org.apache.thrift.protocol.TProtocol) TCompactProtocol(org.apache.thrift.protocol.TCompactProtocol)

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