Search in sources :

Example 16 with TTransportFactory

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

the class TransportProviderTest method startServerThread.

private void startServerThread() throws Exception {
    // create args and use them to build a Thrift TServer
    TTransportFactory tTransportFactory = mTransportProvider.getServerTransportFactory();
    mServer = new TThreadPoolServer(new TThreadPoolServer.Args(mServerTSocket).maxWorkerThreads(2).minWorkerThreads(1).processor(null).transportFactory(tTransportFactory).protocolFactory(new TBinaryProtocol.Factory(true, true)));
    // start the server in a new thread
    Thread serverThread = new Thread(new Runnable() {

        @Override
        public void run() {
            mServer.serve();
        }
    });
    serverThread.start();
    // ensure server is running, and break if it does not start serving in 2 seconds.
    int count = 40;
    while (!mServer.isServing() && serverThread.isAlive()) {
        if (count <= 0) {
            throw new RuntimeException("TThreadPoolServer does not start serving");
        }
        Thread.sleep(50);
        count--;
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TTransportFactory(org.apache.thrift.transport.TTransportFactory) TThreadPoolServer(org.apache.thrift.server.TThreadPoolServer)

Aggregations

TTransportFactory (org.apache.thrift.transport.TTransportFactory)16 TSaslServerTransport (org.apache.thrift.transport.TSaslServerTransport)9 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)8 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)7 LoggerFactory (org.slf4j.LoggerFactory)6 CallbackHandler (javax.security.auth.callback.CallbackHandler)5 TServerSocket (org.apache.thrift.transport.TServerSocket)5 IOException (java.io.IOException)4 TProtocol (org.apache.thrift.protocol.TProtocol)4 TProtocolFactory (org.apache.thrift.protocol.TProtocolFactory)4 HashMap (java.util.HashMap)3 TreeMap (java.util.TreeMap)3 LoginException (javax.security.auth.login.LoginException)3 InetSocketAddress (java.net.InetSocketAddress)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)2 BlockingQueue (java.util.concurrent.BlockingQueue)2 ExecutorService (java.util.concurrent.ExecutorService)2 SynchronousQueue (java.util.concurrent.SynchronousQueue)2