Search in sources :

Example 76 with TTransport

use of org.apache.thrift.transport.TTransport in project akela by mozilla-metrics.

the class ClusterHealth method testThrift.

private static boolean testThrift(String host) {
    boolean ret = false;
    TTransport transport = null;
    try {
        transport = new TSocket(host, 9090, 3000);
        Hbase.Client client = new Hbase.Client(new TBinaryProtocol(transport));
        transport.open();
        client.getColumnDescriptors(ByteBuffer.wrap(META_TABLE_NAME));
        System.out.println(String.format("%s ThriftServer - [ ALIVE ]", new Object[] { host }));
        ret = true;
    } catch (TTransportException e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } catch (IOError e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } catch (TException e) {
        System.out.println(String.format("%s ThriftServer - [ DEAD ] - %s", new Object[] { host, e.getMessage() }));
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return ret;
}
Also used : TException(org.apache.thrift.TException) TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) IOError(org.apache.hadoop.hbase.thrift.generated.IOError) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) DFSClient(org.apache.hadoop.hdfs.DFSClient) Hbase(org.apache.hadoop.hbase.thrift.generated.Hbase) TSocket(org.apache.thrift.transport.TSocket)

Example 77 with TTransport

use of org.apache.thrift.transport.TTransport 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 78 with TTransport

use of org.apache.thrift.transport.TTransport in project eiger by wlloyd.

the class ConfigHelper method createConnection.

public static Cassandra.Client createConnection(String host, Integer port, boolean framed) throws IOException {
    TSocket socket = new TSocket(host, port);
    TTransport trans = framed ? new TFramedTransport(socket) : socket;
    try {
        trans.open();
    } catch (TTransportException e) {
        throw new IOException("unable to connect to server", e);
    }
    return new Cassandra.Client(new TBinaryProtocol(trans));
}
Also used : TBinaryProtocol(org.apache.cassandra.thrift.TBinaryProtocol) TFramedTransport(org.apache.thrift.transport.TFramedTransport) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport) IOException(java.io.IOException) TSocket(org.apache.thrift.transport.TSocket)

Example 79 with TTransport

use of org.apache.thrift.transport.TTransport in project eiger by wlloyd.

the class CustomTThreadPoolServer method serve.

public void serve() {
    try {
        serverTransport_.listen();
    } catch (TTransportException ttx) {
        LOGGER.error("Error occurred during listening.", ttx);
        return;
    }
    stopped_ = false;
    while (!stopped_) {
        // block until we are under max clients
        while (activeClients.get() >= args.maxWorkerThreads) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new AssertionError(e);
            }
        }
        try {
            TTransport client = serverTransport_.accept();
            activeClients.incrementAndGet();
            WorkerProcess wp = new WorkerProcess(client);
            executorService_.execute(wp);
        } catch (TTransportException ttx) {
            if (// thrift sucks
            ttx.getCause() instanceof SocketTimeoutException)
                continue;
            if (!stopped_) {
                LOGGER.warn("Transport error occurred during acceptance of message.", ttx);
            }
        }
        if (activeClients.get() >= args.maxWorkerThreads)
            LOGGER.warn("Maximum number of clients " + args.maxWorkerThreads + " reached");
    }
    executorService_.shutdown();
// Thrift's default shutdown waits for the WorkerProcess threads to complete.  We do not,
// because doing that allows a client to hold our shutdown "hostage" by simply not sending
// another message after stop is called (since process will block indefinitely trying to read
// the next meessage header).
//
// The "right" fix would be to update thrift to set a socket timeout on client connections
// (and tolerate unintentional timeouts until stopped_ is set).  But this requires deep
// changes to the code generator, so simply setting these threads to daemon (in our custom
// CleaningThreadPool) and ignoring them after shutdown is good enough.
//
// Remember, our goal on shutdown is not necessarily that each client request we receive
// gets answered first [to do that, you should redirect clients to a different coordinator
// first], but rather (1) to make sure that for each update we ack as successful, we generate
// hints for any non-responsive replicas, and (2) to make sure that we quickly stop
// accepting client connections so shutdown can continue.  Not waiting for the WorkerProcess
// threads here accomplishes (2); MessagingService's shutdown method takes care of (1).
//
// See CASSANDRA-3335 and CASSANDRA-3727.
}
Also used : SocketTimeoutException(java.net.SocketTimeoutException) TTransportException(org.apache.thrift.transport.TTransportException) TTransport(org.apache.thrift.transport.TTransport)

Example 80 with TTransport

use of org.apache.thrift.transport.TTransport 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

TTransport (org.apache.thrift.transport.TTransport)99 TSocket (org.apache.thrift.transport.TSocket)43 TProtocol (org.apache.thrift.protocol.TProtocol)42 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)36 TFramedTransport (org.apache.thrift.transport.TFramedTransport)28 TTransportException (org.apache.thrift.transport.TTransportException)20 Test (org.junit.Test)20 TException (org.apache.thrift.TException)18 IOException (java.io.IOException)12 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 ArrayList (java.util.ArrayList)9 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 HashMap (java.util.HashMap)6 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)5 THttpClient (org.apache.thrift.transport.THttpClient)4 TSaslClientTransport (org.apache.thrift.transport.TSaslClientTransport)4 ChannelBuffer (com.alibaba.dubbo.remoting.buffer.ChannelBuffer)3 Request (com.alibaba.dubbo.remoting.exchange.Request)3 Demo (com.alibaba.dubbo.rpc.gen.thrift.Demo)3