use of java.util.concurrent.BlockingQueue in project jstorm by alibaba.
the class SaslTransportPlugin method getServer.
@Override
public TServer getServer(TProcessor processor) throws IOException, TTransportException {
int port = type.getPort(storm_conf);
TTransportFactory serverTransportFactory = getServerTransportFactory();
TServerSocket 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);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class LocalJSR166TestCase method testToArray2.
/**
* toArray(a) contains all elements in FIFO order
*/
@Ignore
@Test
public void testToArray2() {
BlockingQueue q = new LocalConcurrentBlockingObjectQueue(SIZE);
for (int i = 0; i < SIZE; i++) {
checkToArray2(q);
q.add(i);
}
// Provoke wraparound
for (int i = 0; i < SIZE; i++) {
checkToArray2(q);
assertEquals(i, q.poll());
checkToArray2(q);
q.add(SIZE + i);
}
for (int i = 0; i < SIZE; i++) {
checkToArray2(q);
assertEquals(SIZE + i, q.poll());
}
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testTimedPoll0.
/**
* timed poll with zero timeout succeeds when non-empty, else times out
*/
@Test
public void testTimedPoll0() throws Exception {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.poll(0, MILLISECONDS));
}
assertNull(q.poll(0, MILLISECONDS));
checkEmpty(q);
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testRemove.
/**
* remove removes next element, or throws NSEE if empty
*/
@Test
public void testRemove() throws IOException {
BlockingQueue q = populatedQueue(SIZE);
for (int i = 0; i < SIZE; ++i) {
assertEquals(i, q.remove());
}
try {
q.remove();
shouldThrow();
} catch (NoSuchElementException success) {
}
}
use of java.util.concurrent.BlockingQueue in project HugeCollections-OLD by peter-lawrey.
the class SharedJSR166TestCase method testDrainToN.
/**
* drainTo(c, n) empties first min(n, size) elements of queue into c
*/
@Ignore
@Test
public void testDrainToN() throws IOException {
BlockingQueue q = new SharedConcurrentBlockingObjectQueue<Integer>(SIZE * 2, Integer.class);
for (int i = 0; i < SIZE + 2; ++i) {
for (int j = 0; j < SIZE; j++) assertTrue(q.offer(new Integer(j)));
ArrayList l = new ArrayList();
q.drainTo(l, i);
int k = (i < SIZE) ? i : SIZE;
assertEquals(k, l.size());
assertEquals(SIZE - k, q.size());
for (int j = 0; j < k; ++j) assertEquals(l.get(j), new Integer(j));
while (q.poll() != null) ;
}
}
Aggregations