Search in sources :

Example 1 with TThreadPoolServer

use of org.apache.storm.thrift.server.TThreadPoolServer in project storm by apache.

the class SaslTransportPlugin method getServer.

@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
    int configuredPort = type.getPort(conf);
    Integer socketTimeout = type.getSocketTimeOut(conf);
    TTransportFactory serverTransportFactory = getServerTransportFactory(type.isImpersonationAllowed());
    TServerSocket serverTransport = null;
    if (socketTimeout != null) {
        serverTransport = new TServerSocket(configuredPort, socketTimeout);
    } else {
        serverTransport = new TServerSocket(configuredPort);
    }
    this.port = serverTransport.getServerSocket().getLocalPort();
    int numWorkerThreads = type.getNumThreads(conf);
    Integer queueSize = type.getQueueSize(conf);
    TThreadPoolServer.Args serverArgs = new TThreadPoolServer.Args(serverTransport).processor(new TUGIWrapProcessor(processor)).minWorkerThreads(numWorkerThreads).maxWorkerThreads(numWorkerThreads).protocolFactory(new TBinaryProtocol.Factory(false, true));
    if (serverTransportFactory != null) {
        serverArgs.transportFactory(serverTransportFactory);
    }
    BlockingQueue<Runnable> workQueue = new SynchronousQueue<>();
    if (queueSize != null) {
        workQueue = new ArrayBlockingQueue<>(queueSize);
    }
    ThreadPoolExecutor executorService = new ExtendedThreadPoolExecutor(numWorkerThreads, numWorkerThreads, 60, TimeUnit.SECONDS, workQueue);
    serverArgs.executorService(executorService);
    return new TThreadPoolServer(serverArgs);
}
Also used : TTransportFactory(org.apache.storm.thrift.transport.TTransportFactory) ExtendedThreadPoolExecutor(org.apache.storm.utils.ExtendedThreadPoolExecutor) TServerSocket(org.apache.storm.thrift.transport.TServerSocket) TBinaryProtocol(org.apache.storm.thrift.protocol.TBinaryProtocol) SynchronousQueue(java.util.concurrent.SynchronousQueue) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) ExtendedThreadPoolExecutor(org.apache.storm.utils.ExtendedThreadPoolExecutor) TThreadPoolServer(org.apache.storm.thrift.server.TThreadPoolServer)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TBinaryProtocol (org.apache.storm.thrift.protocol.TBinaryProtocol)1 TThreadPoolServer (org.apache.storm.thrift.server.TThreadPoolServer)1 TServerSocket (org.apache.storm.thrift.transport.TServerSocket)1 TTransportFactory (org.apache.storm.thrift.transport.TTransportFactory)1 ExtendedThreadPoolExecutor (org.apache.storm.utils.ExtendedThreadPoolExecutor)1