E
- Type of the data in the queue.public class QueueConsumerGroup<E> extends Object
One working thread will be created for each QueueConsumer when necessary.
每个QueueConsumer相应的会有一个工作线程在需要的时候被创建。
Modifier and Type | Field and Description |
---|---|
protected Map<String,QueueConsumer<E>> |
consumers |
protected BlockingQueue<E> |
queue |
protected ExecutorService |
threadPool |
Modifier | Constructor and Description |
---|---|
protected |
QueueConsumerGroup(BlockingQueue<E> workQueue)
Internal constructor, without specifying thread pool.
(内部用)创建实例,不指定统一的线程池。 |
|
QueueConsumerGroup(BlockingQueue<E> workQueue,
Collection<? extends QueueConsumer<E>> queueConsumers)
Constructor, without specifying thread pool.
创建实例,不指定统一的线程池。 |
protected |
QueueConsumerGroup(BlockingQueue<E> workQueue,
ExecutorService executorService)
Internal constructor, specifying one thread pool for all QueueConsumers to use.
(内部用)创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(BlockingQueue<E> workQueue,
ExecutorService executorService,
Collection<? extends QueueConsumer<E>> queueConsumers)
Constructor, specifying one thread pool for all QueueConsumers to use.
创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(BlockingQueue<E> workQueue,
ExecutorService executorService,
QueueConsumer<E>... queueConsumers)
Constructor, specifying one thread pool for all QueueConsumers to use.
创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(BlockingQueue<E> workQueue,
QueueConsumer<E>... queueConsumers)
Constructor, without specifying thread pool.
创建实例,不指定统一的线程池。 |
protected |
QueueConsumerGroup(int workQueueSize)
Internal constructor, without specifying thread pool.
(内部用)创建实例,不指定统一的线程池。 |
|
QueueConsumerGroup(int workQueueSize,
Collection<? extends QueueConsumer<E>> queueConsumers)
Constructor, without specifying thread pool.
创建实例,不指定统一的线程池。 |
protected |
QueueConsumerGroup(int workQueueSize,
ExecutorService executorService)
Internal constructor, specifying one thread pool for all QueueConsumers to use.
(内部用)创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(int workQueueSize,
ExecutorService executorService,
Collection<? extends QueueConsumer<E>> queueConsumers)
Constructor, specifying one thread pool for all QueueConsumers to use.
创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(int workQueueSize,
ExecutorService executorService,
QueueConsumer<E>... queueConsumers)
Constructor, specifying one thread pool for all QueueConsumers to use.
创建实例,让所有的QueueConsumer统一使用指定的线程池。 |
|
QueueConsumerGroup(int workQueueSize,
QueueConsumer<E>... queueConsumers)
Constructor, without specifying thread pool.
创建实例,不指定统一的线程池。 |
Modifier and Type | Method and Description |
---|---|
QueueConsumer<E> |
getConsumer(String name)
Get QueueConsumer instance by its name.
按名称寻找得到QueueConsumer。 |
Map<String,QueueConsumer<E>> |
getConsumers()
Get the Map of all QueueConsumer.
获得含有全部QueueConsumer的Map。 |
BlockingQueue<E> |
getQueue()
Get the work queue.
取得工作队列。 |
void |
queue(E obj)
Put data into the queue for processing, if the queue still has space
this method will return immediately
without waiting for the data to be actually processed.
把待处理数据放入队列,如果队列中还有空位置则这个方法会立即返回而不是等待实际处理完成。 |
void |
start()
Start all QueueConsumer(s) one by one.
逐个启动所有Consumer。 |
void |
stop()
Stop working threads after the queue is empty;
This method will not return until working thread finishes.
让所有处理线程在队列处理空了之后停止,这个方法会等到所有工作处理线程结束才返回。 |
void |
stop(boolean afterQueueEmpty)
Stop all the working threads one by one;
This method will not return until all threads are stopped.
逐个停止所工作线程,这个方法会等到所有工作线程结束才返回。 |
protected BlockingQueue<E> queue
protected Map<String,QueueConsumer<E>> consumers
protected ExecutorService threadPool
protected QueueConsumerGroup(BlockingQueue<E> workQueue)
workQueue
- The queue that data for processing will be fetched from.protected QueueConsumerGroup(int workQueueSize)
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.protected QueueConsumerGroup(BlockingQueue<E> workQueue, ExecutorService executorService)
workQueue
- The queue that data for processing will be fetched from.executorService
- Thread pool that working threads will be get from.protected QueueConsumerGroup(int workQueueSize, ExecutorService executorService)
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.executorService
- Thread pool that working threads will be get from.public QueueConsumerGroup(BlockingQueue<E> workQueue, ExecutorService executorService, QueueConsumer<E>... queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueue
- The queue that data for processing will be fetched from.executorService
- Thread pool that working threads will be get from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(int workQueueSize, ExecutorService executorService, QueueConsumer<E>... queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.executorService
- Thread pool that working threads will be get from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(BlockingQueue<E> workQueue, QueueConsumer<E>... queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueue
- The queue that data for processing will be fetched from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(int workQueueSize, QueueConsumer<E>... queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(BlockingQueue<E> workQueue, ExecutorService executorService, Collection<? extends QueueConsumer<E>> queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueue
- The queue that data for processing will be fetched from.executorService
- Thread pool that working threads will be get from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(int workQueueSize, ExecutorService executorService, Collection<? extends QueueConsumer<E>> queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.executorService
- Thread pool that working threads will be get from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(BlockingQueue<E> workQueue, Collection<? extends QueueConsumer<E>> queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueue
- The queue that data for processing will be fetched from.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumerGroup(int workQueueSize, Collection<? extends QueueConsumer<E>> queueConsumers)
Duplicated names of QueueConsumer(s) will be renamed automatically when adding to this QueueConsumerGroup.
当被加入这个QueueConsumerGroup的时候,QueueConsumer如果有名称重复,会被自动改名。
workQueueSize
- Size of the ArrayBlockingQueue to be created from which data for processing will be fetched.queueConsumers
- QueueConsumer(s) that will work together.public QueueConsumer<E> getConsumer(String name)
name
- Name of the QueueConsumerpublic Map<String,QueueConsumer<E>> getConsumers()
public BlockingQueue<E> getQueue()
public void start()
public void queue(E obj) throws InterruptedException
If the queue has no space left, this method will wait for the space then put data into the queue for processing, after that, this method will return immediately without waiting for the data to be actually processed.
如果队列中没有空位置了,则会等待队列空出位置来之后再把数据放进去,放完之后这个方法会立即返回而不是等待实际处理完成。
obj
- Data need to be processedInterruptedException
- if interrupted while waiting for space to become available.public void stop(boolean afterQueueEmpty)
afterQueueEmpty
- true if working thread should keep processing until the queue is empty;public void stop()
Copyright © 2014. All Rights Reserved.