Search in sources :

Example 1 with ExtendedThreadPoolExecutor

use of org.apache.storm.utils.ExtendedThreadPoolExecutor in project storm by apache.

the class SaslTransportPlugin method getServer.

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

Example 2 with ExtendedThreadPoolExecutor

use of org.apache.storm.utils.ExtendedThreadPoolExecutor in project storm by apache.

the class DRPCSpout method open.

@Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) {
    _collector = collector;
    if (_local_drpc_id == null) {
        _backround = new ExtendedThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
        _futures = new LinkedList<>();
        int numTasks = context.getComponentTasks(context.getThisComponentId()).size();
        int index = context.getThisTaskIndex();
        int port = Utils.getInt(conf.get(Config.DRPC_INVOCATIONS_PORT));
        List<String> servers = (List<String>) conf.get(Config.DRPC_SERVERS);
        if (servers == null || servers.isEmpty()) {
            throw new RuntimeException("No DRPC servers configured for topology");
        }
        if (numTasks < servers.size()) {
            for (String s : servers) {
                _futures.add(_backround.submit(new Adder(s, port, conf)));
            }
        } else {
            int i = index % servers.size();
            _futures.add(_backround.submit(new Adder(servers.get(i), port, conf)));
        }
    }
}
Also used : SynchronousQueue(java.util.concurrent.SynchronousQueue) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ExtendedThreadPoolExecutor(org.apache.storm.utils.ExtendedThreadPoolExecutor)

Aggregations

SynchronousQueue (java.util.concurrent.SynchronousQueue)2 ExtendedThreadPoolExecutor (org.apache.storm.utils.ExtendedThreadPoolExecutor)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TThreadPoolServer (org.apache.thrift.server.TThreadPoolServer)1 TServerSocket (org.apache.thrift.transport.TServerSocket)1 TTransportFactory (org.apache.thrift.transport.TTransportFactory)1