Search in sources :

Example 71 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 72 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 73 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)

Example 74 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 75 with TTransport

use of org.apache.thrift.transport.TTransport in project alluxio by Alluxio.

the class TransportProviderTest method nosaslAuthentrication.

/**
   * In NOSASL mode, the TTransport used should be the same as Alluxio original code.
   */
@Test
public void nosaslAuthentrication() throws Exception {
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.NOSASL.getAuthName());
    mTransportProvider = TransportProvider.Factory.create();
    // start server
    startServerThread();
    // create client and connect to server
    TTransport client = mTransportProvider.getClientTransport(mServerAddress);
    client.open();
    Assert.assertTrue(client.isOpen());
    // clean up
    client.close();
    mServer.stop();
}
Also used : TTransport(org.apache.thrift.transport.TTransport) Test(org.junit.Test)

Aggregations

TTransport (org.apache.thrift.transport.TTransport)81 TSocket (org.apache.thrift.transport.TSocket)29 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)28 TProtocol (org.apache.thrift.protocol.TProtocol)28 TFramedTransport (org.apache.thrift.transport.TFramedTransport)20 TTransportException (org.apache.thrift.transport.TTransportException)18 Test (org.junit.Test)18 TException (org.apache.thrift.TException)14 IOException (java.io.IOException)11 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)8 ArrayList (java.util.ArrayList)7 Socket (java.net.Socket)5 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)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 SocketFieldAccessor (com.navercorp.pinpoint.plugin.thrift.field.accessor.SocketFieldAccessor)3 InetSocketAddress (java.net.InetSocketAddress)3 HashMap (java.util.HashMap)3