6363 * </pre>
6464 * <i>dormant</i> is not represented in the implementation state, and adding items
6565 * when the client is <i>in progress</i> or <i>ready</i> does not change its state.
66+ * @param <K> Key -- type of client
67+ * @param <W> Work -- type of work item
6668 */
6769public class WorkPool <K , W > {
6870
6971 /** protecting <code>ready</code>, <code>inProgress</code> and <code>pool</code> */
7072 private final Object monitor = new Object ();
71- /** An ordered queue of <i>ready</i> clients. */
73+ /** An injective queue of <i>ready</i> clients. */
7274 private final SetQueue <K > ready = new SetQueue <K >();
7375 /** The set of clients which have work <i>in progress</i>. */
7476 private final Set <K > inProgress = new HashSet <K >();
@@ -79,7 +81,7 @@ public class WorkPool<K, W> {
7981 * Add client <code><b>key</b></code> to pool of item queues, with an empty queue.
8082 * A client is initially <i>dormant</i>.
8183 * <p/>
82- * No-op if <code><b>key</b></code> already present.
84+ * No-op if <code><b>key</b></code> already present.
8385 * @param key client to add to pool
8486 */
8587 public void registerKey (K key ) {
@@ -162,18 +164,16 @@ private static <W> int drainTo(LinkedList<W> deList, Collection<W> c, int maxEle
162164 * @param item the work item to add to the client queue
163165 * @return <code><b>true</b></code> if and only if the client is marked <i>ready</i>
164166 * — <i>as a result of this work item</i>
165- * @throws IllegalArgumentException if key not registered.
166167 */
167168 public boolean addWorkItem (K key , W item ) {
168169 synchronized (this .monitor ) {
169170 Queue <W > queue = this .pool .get (key );
170- if (queue == null ) {
171- throw new IllegalArgumentException ("Client " + key + " not registered" );
172- }
173- queue .offer (item );
174- if (isDormant (key )) {
175- dormantToReady (key );
176- return true ;
171+ if (queue != null ) {
172+ queue .offer (item );
173+ if (isDormant (key )) {
174+ dormantToReady (key );
175+ return true ;
176+ }
177177 }
178178 return false ;
179179 }
@@ -208,7 +208,7 @@ private boolean moreWorkItems(K key) {
208208 LinkedList <W > leList = this .pool .get (key );
209209 return (leList ==null ? false : !leList .isEmpty ());
210210 }
211-
211+
212212 /* State identification functions */
213213 private boolean isInProgress (K key ){ return this .inProgress .contains (key ); }
214214 private boolean isReady (K key ){ return this .ready .contains (key ); }
0 commit comments