|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.rabbitmq.client.impl.WorkPool<K,W>
K
- Key -- type of clientW
- Work -- type of work itempublic class WorkPool<K,W>
This is a generic implementation of the Channels
specification
in Channeling Work, Nov 2010 (channels.pdf).
registerKey(K)
,
and then they become clients and a queue of
items (type W) is stored for each client.
Each client has a state which is exactly one of dormant,
in progress or ready. Immediately after registration a client is dormant.
Items may be (singly) added to (the end of) a client's queue with addWorkItem(K,W)
.
If the client is dormant it becomes ready thereby. All other states remain unchanged.
The next ready client, together with a collection of its items,
may be retrieved with nextWorkBlock(collection,max)
(making that client in progress).
An in progress client can finish (processing a batch of items) with finishWorkBlock(K)
.
It then becomes either dormant or ready, depending if its queue of work items is empty or no.
If a client has items queued, it is either in progress or ready but cannot be both.
When work is finished it may be marked ready if there is further work,
or dormant if there is not.
There is never any work for a dormant client.
A client may be unregistered, with unregisterKey(K)
, which removes the client from
all parts of the state, and any queue of items stored with it.
All clients may be unregistered with unregisterAllKeys()
.
Concurrent Semanticspool :: map(K, seq W) inProgress :: set K ready :: iseq Kwhere a
seq
is a sequence (queue or list) and an iseq
(i for injective) is a sequence with no duplicates.
State transitionsfinish(k) ------------- -----------> | (dormant) | | ------------- ------------- next() | add(item) | in progress | <--------- | ------------- | V | ------------- -----------> | ready | finish(k) -------------dormant is not represented in the implementation state, and adding items when the client is in progress or ready does not change its state.
Constructor Summary | |
---|---|
WorkPool()
|
Method Summary | |
---|---|
boolean |
addWorkItem(K key,
W item)
Add (enqueue) an item for a specific client. |
boolean |
finishWorkBlock(K key)
Set client no longer in progress. |
K |
nextWorkBlock(java.util.Collection<W> to,
int size)
Return the next ready client, and transfer a collection of that client's items to process. |
void |
registerKey(K key)
Add client key to pool of item queues, with an empty queue. |
void |
unregisterAllKeys()
Remove all clients from pool and from any other state. |
void |
unregisterKey(K key)
Remove client from pool and from any other state. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WorkPool()
Method Detail |
---|
public void registerKey(K key)
key
to pool of item queues, with an empty queue.
A client is initially dormant.
No-op if key
already present.
key
- client to add to poolpublic void unregisterKey(K key)
key
- of client to unregisterpublic void unregisterAllKeys()
public K nextWorkBlock(java.util.Collection<W> to, int size)
null
.
to
- collection object in which to transfer itemssize
- max number of items to transfer
null
if there is none.public boolean addWorkItem(K key, W item)
false
if client not registered.
If dormant, the client will be marked ready.
key
- the client to add to the work item toitem
- the work item to add to the client queue
true
if and only if the client is marked ready
— as a result of this work itempublic boolean finishWorkBlock(K key)
false
).
key
- client that has finished work
true
if and only if client becomes ready
java.lang.IllegalStateException
- if registered client not in progress
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |