|
24 | 24 | import org.apache.thrift.TException; |
25 | 25 | import org.apache.thrift.protocol.TCompactProtocol; |
26 | 26 | import org.apache.thrift.server.TServer; |
| 27 | +import org.apache.thrift.server.TThreadPoolServer; |
27 | 28 | import org.apache.thrift.server.TThreadedSelectorServer; |
28 | 29 | import org.apache.thrift.transport.TFramedTransport; |
29 | | -import org.apache.thrift.transport.TNonblockingServerSocket; |
30 | | -import org.apache.thrift.transport.TNonblockingServerTransport; |
| 30 | +import org.apache.thrift.transport.TServerSocket; |
| 31 | +import org.apache.thrift.transport.TServerTransport; |
31 | 32 | import org.apache.thrift.transport.TTransportException; |
32 | 33 | import org.microfunctions.queue.local.LocalQueueService.Iface; |
33 | 34 |
|
34 | 35 | public class LocalQueueServer implements Iface, Runnable { |
35 | 36 |
|
36 | | - public static final int DEFAULT_SELECTOR_THREADS = Math.max(2, 2 * Runtime.getRuntime().availableProcessors()); |
37 | | - public static final int DEFAULT_WORKER_THREADS = Math.max(4, 4 * Runtime.getRuntime().availableProcessors()); |
| 37 | + public static final int DEFAULT_MAX_WORKER_THREADS = Integer.MAX_VALUE; |
38 | 38 | public static final int DEFAULT_CLIENT_TIMEOUT = 0; |
39 | 39 | public static final int DEFAULT_MAX_FRAME_LENGTH = Integer.MAX_VALUE; |
40 | 40 |
|
@@ -116,26 +116,25 @@ public long freeMemory() throws TException { |
116 | 116 | return Runtime.getRuntime().maxMemory() - Runtime.getRuntime().totalMemory() + Runtime.getRuntime().freeMemory(); |
117 | 117 | } |
118 | 118 |
|
119 | | - public void start (InetSocketAddress bindAddr, int nSelectorThreads, int nWorkerThreads, int clientTimeout) throws TTransportException { |
120 | | - TNonblockingServerTransport transport = new TNonblockingServerSocket(bindAddr, clientTimeout); |
121 | | - TThreadedSelectorServer.Args args = new TThreadedSelectorServer.Args(transport) |
| 119 | + public void start (InetSocketAddress bindAddr, int maxWorkerThreads, int clientTimeout) throws TTransportException { |
| 120 | + TServerTransport transport = new TServerSocket(bindAddr, clientTimeout); |
| 121 | + TThreadPoolServer.Args args = new TThreadPoolServer.Args(transport) |
122 | 122 | .transportFactory(new TFramedTransport.Factory(DEFAULT_MAX_FRAME_LENGTH)) |
123 | 123 | .protocolFactory(new TCompactProtocol.Factory()) |
124 | 124 | .processor(new LocalQueueService.Processor<Iface>(this)) |
125 | | - .selectorThreads(nSelectorThreads) |
126 | | - .workerThreads(nWorkerThreads); |
127 | | - server = new TThreadedSelectorServer(args); |
| 125 | + .maxWorkerThreads(maxWorkerThreads); |
| 126 | + server = new TThreadPoolServer(args); |
128 | 127 |
|
129 | 128 | LOGGER.info("Starting local queue..."); |
130 | 129 | server.serve(); |
131 | 130 | } |
132 | 131 |
|
133 | | - public void start (InetSocketAddress bindAddr, int nSelectorThreads, int nWorkerThreads) throws TTransportException { |
134 | | - this.start(bindAddr, nSelectorThreads, nWorkerThreads, DEFAULT_CLIENT_TIMEOUT); |
| 132 | + public void start (InetSocketAddress bindAddr, int maxWorkerThreads) throws TTransportException { |
| 133 | + this.start(bindAddr, maxWorkerThreads, DEFAULT_CLIENT_TIMEOUT); |
135 | 134 | } |
136 | 135 |
|
137 | 136 | public void start (InetSocketAddress bindAddr) throws TTransportException { |
138 | | - this.start(bindAddr, DEFAULT_SELECTOR_THREADS, DEFAULT_WORKER_THREADS, DEFAULT_CLIENT_TIMEOUT); |
| 137 | + this.start(bindAddr, DEFAULT_MAX_WORKER_THREADS, DEFAULT_CLIENT_TIMEOUT); |
139 | 138 | } |
140 | 139 |
|
141 | 140 | public void stop () { |
|
0 commit comments