EVOLUTION-MANAGER
Edit File: WorkPool.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <!-- NewPage --> <html lang="en"> <head> <!-- Generated by javadoc (version 1.7.0_91) on Thu Jan 14 10:04:52 GMT 2016 --> <title>WorkPool</title> <meta name="date" content="2016-01-14"> <link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style"> </head> <body> <script type="text/javascript"><!-- if (location.href.indexOf('is-external=true') == -1) { parent.document.title="WorkPool"; } //--> </script> <noscript> <div>JavaScript is disabled on your browser.</div> </noscript> <!-- ========= START OF TOP NAVBAR ======= --> <div class="topNav"><a name="navbar_top"> <!-- --> </a><a href="#skip-navbar_top" title="Skip navigation links"></a><a name="navbar_top_firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../../../../overview-summary.html">Overview</a></li> <li><a href="package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../../../../deprecated-list.html">Deprecated</a></li> <li><a href="../../../../index-all.html">Index</a></li> <li><a href="../../../../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../../../../com/rabbitmq/client/impl/Version.html" title="class in com.rabbitmq.client.impl"><span class="strong">Prev Class</span></a></li> <li>Next Class</li> </ul> <ul class="navList"> <li><a href="../../../../index.html?com/rabbitmq/client/impl/WorkPool.html" target="_top">Frames</a></li> <li><a href="WorkPool.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_top"> <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_top"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li><a href="#constructor_summary">Constr</a> | </li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li><a href="#constructor_detail">Constr</a> | </li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_top"> <!-- --> </a></div> <!-- ========= END OF TOP NAVBAR ========= --> <!-- ======== START OF CLASS DATA ======== --> <div class="header"> <div class="subTitle">com.rabbitmq.client.impl</div> <h2 title="Class WorkPool" class="title">Class WorkPool<K,W></h2> </div> <div class="contentContainer"> <ul class="inheritance"> <li>java.lang.Object</li> <li> <ul class="inheritance"> <li>com.rabbitmq.client.impl.WorkPool<K,W></li> </ul> </li> </ul> <div class="description"> <ul class="blockList"> <li class="blockList"> <dl><dt><span class="strong">Type Parameters:</span></dt><dd><code>K</code> - Key -- type of client</dd><dd><code>W</code> - Work -- type of work item</dd></dl> <hr> <br> <pre>public class <span class="strong">WorkPool<K,W></span> extends java.lang.Object</pre> <div class="block">This is a generic implementation of the <q>Channels</q> specification in <i>Channeling Work</i>, Nov 2010 (<tt>channels.pdf</tt>). <p/> Objects of type <b>K</b> must be registered, with <code><b>registerKey(K)</b></code>, and then they become <i>clients</i> and a queue of items (type <b>W</b>) is stored for each client. <p/> Each client has a <i>state</i> which is exactly one of <i>dormant</i>, <i>in progress</i> or <i>ready</i>. Immediately after registration a client is <i>dormant</i>. <p/> Items may be (singly) added to (the end of) a client's queue with <code><b>addWorkItem(K,W)</b></code>. If the client is <i>dormant</i> it becomes <i>ready</i> thereby. All other states remain unchanged. <p/> The next <i>ready</i> client, together with a collection of its items, may be retrieved with <code><b>nextWorkBlock(collection,max)</b></code> (making that client <i>in progress</i>). <p/> An <i>in progress</i> client can finish (processing a batch of items) with <code><b>finishWorkBlock(K)</b></code>. It then becomes either <i>dormant</i> or <i>ready</i>, depending if its queue of work items is empty or no. <p/> If a client has items queued, it is either <i>in progress</i> or <i>ready</i> but cannot be both. When work is finished it may be marked <i>ready</i> if there is further work, or <i>dormant</i> if there is not. There is never any work for a <i>dormant</i> client. <p/> A client may be unregistered, with <code><b>unregisterKey(K)</b></code>, which removes the client from all parts of the state, and any queue of items stored with it. All clients may be unregistered with <code><b>unregisterAllKeys()</b></code>. <p/> <b>Concurrent Semantics</b><br/> This implementation is thread-safe. <p/> <b>Implementation Notes</b><br/> The state is, roughly, as follows: <pre> pool :: <i>map</i>(K, <i>seq</i> W) inProgress :: <i>set</i> K ready :: <i>iseq</i> K</pre> <p/> where a <code><i>seq</i></code> is a sequence (queue or list) and an <code><i>iseq</i></code> (<i>i</i> for <i>i</i>njective) is a sequence with no duplicates. <p/> <b>State transitions</b><br/><pre> finish(k) ------------- -----------> | (dormant) | | ------------- ------------- next() | add(item) | in progress | <--------- | ------------- | V | ------------- -----------> | ready | finish(k) ------------- </pre> <i>dormant</i> is not represented in the implementation state, and adding items when the client is <i>in progress</i> or <i>ready</i> does not change its state.</div> </li> </ul> </div> <div class="summary"> <ul class="blockList"> <li class="blockList"> <!-- ======== CONSTRUCTOR SUMMARY ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor_summary"> <!-- --> </a> <h3>Constructor Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Constructor Summary table, listing constructors, and an explanation"> <caption><span>Constructors</span><span class="tabEnd"> </span></caption> <tr> <th class="colOne" scope="col">Constructor and Description</th> </tr> <tr class="altColor"> <td class="colOne"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#WorkPool()">WorkPool</a></strong>()</code> </td> </tr> </table> </li> </ul> <!-- ========== METHOD SUMMARY =========== --> <ul class="blockList"> <li class="blockList"><a name="method_summary"> <!-- --> </a> <h3>Method Summary</h3> <table class="overviewSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> <caption><span>Methods</span><span class="tabEnd"> </span></caption> <tr> <th class="colFirst" scope="col">Modifier and Type</th> <th class="colLast" scope="col">Method and Description</th> </tr> <tr class="altColor"> <td class="colFirst"><code>boolean</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#addWorkItem(K,%20W)">addWorkItem</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key, <a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">W</a> item)</code> <div class="block">Add (enqueue) an item for a specific client.</div> </td> </tr> <tr class="rowColor"> <td class="colFirst"><code>boolean</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#finishWorkBlock(K)">finishWorkBlock</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</code> <div class="block">Set client no longer <i>in progress</i>.</div> </td> </tr> <tr class="altColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#limit(K)">limit</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</code> </td> </tr> <tr class="rowColor"> <td class="colFirst"><code><a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a></code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#nextWorkBlock(java.util.Collection,%20int)">nextWorkBlock</a></strong>(java.util.Collection<<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">W</a>> to, int size)</code> <div class="block">Return the next <i>ready</i> client, and transfer a collection of that client's items to process.</div> </td> </tr> <tr class="altColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#registerKey(K)">registerKey</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</code> <div class="block">Add client <code><b>key</b></code> to pool of item queues, with an empty queue.</div> </td> </tr> <tr class="rowColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#unlimit(K)">unlimit</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</code> </td> </tr> <tr class="altColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#unregisterAllKeys()">unregisterAllKeys</a></strong>()</code> <div class="block">Remove all clients from pool and from any other state.</div> </td> </tr> <tr class="rowColor"> <td class="colFirst"><code>void</code></td> <td class="colLast"><code><strong><a href="../../../../com/rabbitmq/client/impl/WorkPool.html#unregisterKey(K)">unregisterKey</a></strong>(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</code> <div class="block">Remove client from pool and from any other state.</div> </td> </tr> </table> <ul class="blockList"> <li class="blockList"><a name="methods_inherited_from_class_java.lang.Object"> <!-- --> </a> <h3>Methods inherited from class java.lang.Object</h3> <code>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</code></li> </ul> </li> </ul> </li> </ul> </div> <div class="details"> <ul class="blockList"> <li class="blockList"> <!-- ========= CONSTRUCTOR DETAIL ======== --> <ul class="blockList"> <li class="blockList"><a name="constructor_detail"> <!-- --> </a> <h3>Constructor Detail</h3> <a name="WorkPool()"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>WorkPool</h4> <pre>public WorkPool()</pre> </li> </ul> </li> </ul> <!-- ============ METHOD DETAIL ========== --> <ul class="blockList"> <li class="blockList"><a name="method_detail"> <!-- --> </a> <h3>Method Detail</h3> <a name="registerKey(java.lang.Object)"> <!-- --> </a><a name="registerKey(K)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>registerKey</h4> <pre>public void registerKey(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</pre> <div class="block">Add client <code><b>key</b></code> to pool of item queues, with an empty queue. A client is initially <i>dormant</i>. <p/> No-op if <code><b>key</b></code> already present.</div> <dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - client to add to pool</dd></dl> </li> </ul> <a name="limit(java.lang.Object)"> <!-- --> </a><a name="limit(K)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>limit</h4> <pre>public void limit(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</pre> </li> </ul> <a name="unlimit(java.lang.Object)"> <!-- --> </a><a name="unlimit(K)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>unlimit</h4> <pre>public void unlimit(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</pre> </li> </ul> <a name="unregisterKey(java.lang.Object)"> <!-- --> </a><a name="unregisterKey(K)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>unregisterKey</h4> <pre>public void unregisterKey(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</pre> <div class="block">Remove client from pool and from any other state. Has no effect if client already absent.</div> <dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - of client to unregister</dd></dl> </li> </ul> <a name="unregisterAllKeys()"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>unregisterAllKeys</h4> <pre>public void unregisterAllKeys()</pre> <div class="block">Remove all clients from pool and from any other state.</div> </li> </ul> <a name="nextWorkBlock(java.util.Collection, int)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>nextWorkBlock</h4> <pre>public <a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> nextWorkBlock(java.util.Collection<<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">W</a>> to, int size)</pre> <div class="block">Return the next <i>ready</i> client, and transfer a collection of that client's items to process. Mark client <i>in progress</i>. <p/> If there is no <i>ready</i> client, return <code><b>null</b></code>.</div> <dl><dt><span class="strong">Parameters:</span></dt><dd><code>to</code> - collection object in which to transfer items</dd><dd><code>size</code> - max number of items to transfer</dd> <dt><span class="strong">Returns:</span></dt><dd>key of client to whom items belong, or <code><b>null</b></code> if there is none.</dd></dl> </li> </ul> <a name="addWorkItem(java.lang.Object,java.lang.Object)"> <!-- --> </a><a name="addWorkItem(K, W)"> <!-- --> </a> <ul class="blockList"> <li class="blockList"> <h4>addWorkItem</h4> <pre>public boolean addWorkItem(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key, <a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">W</a> item)</pre> <div class="block">Add (enqueue) an item for a specific client. No change and returns <code><b>false</b></code> if client not registered. If <i>dormant</i>, the client will be marked <i>ready</i>.</div> <dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - the client to add to the work item to</dd><dd><code>item</code> - the work item to add to the client queue</dd> <dt><span class="strong">Returns:</span></dt><dd><code><b>true</b></code> if and only if the client is marked <i>ready</i> — <i>as a result of this work item</i></dd></dl> </li> </ul> <a name="finishWorkBlock(java.lang.Object)"> <!-- --> </a><a name="finishWorkBlock(K)"> <!-- --> </a> <ul class="blockListLast"> <li class="blockList"> <h4>finishWorkBlock</h4> <pre>public boolean finishWorkBlock(<a href="../../../../com/rabbitmq/client/impl/WorkPool.html" title="type parameter in WorkPool">K</a> key)</pre> <div class="block">Set client no longer <i>in progress</i>. Ignore unknown clients (and return <code><b>false</b></code>).</div> <dl><dt><span class="strong">Parameters:</span></dt><dd><code>key</code> - client that has finished work</dd> <dt><span class="strong">Returns:</span></dt><dd><code><b>true</b></code> if and only if client becomes <i>ready</i></dd> <dt><span class="strong">Throws:</span></dt> <dd><code>java.lang.IllegalStateException</code> - if registered client not <i>in progress</i></dd></dl> </li> </ul> </li> </ul> </li> </ul> </div> </div> <!-- ========= END OF CLASS DATA ========= --> <!-- ======= START OF BOTTOM NAVBAR ====== --> <div class="bottomNav"><a name="navbar_bottom"> <!-- --> </a><a href="#skip-navbar_bottom" title="Skip navigation links"></a><a name="navbar_bottom_firstrow"> <!-- --> </a> <ul class="navList" title="Navigation"> <li><a href="../../../../overview-summary.html">Overview</a></li> <li><a href="package-summary.html">Package</a></li> <li class="navBarCell1Rev">Class</li> <li><a href="package-tree.html">Tree</a></li> <li><a href="../../../../deprecated-list.html">Deprecated</a></li> <li><a href="../../../../index-all.html">Index</a></li> <li><a href="../../../../help-doc.html">Help</a></li> </ul> </div> <div class="subNav"> <ul class="navList"> <li><a href="../../../../com/rabbitmq/client/impl/Version.html" title="class in com.rabbitmq.client.impl"><span class="strong">Prev Class</span></a></li> <li>Next Class</li> </ul> <ul class="navList"> <li><a href="../../../../index.html?com/rabbitmq/client/impl/WorkPool.html" target="_top">Frames</a></li> <li><a href="WorkPool.html" target="_top">No Frames</a></li> </ul> <ul class="navList" id="allclasses_navbar_bottom"> <li><a href="../../../../allclasses-noframe.html">All Classes</a></li> </ul> <div> <script type="text/javascript"><!-- allClassesLink = document.getElementById("allclasses_navbar_bottom"); if(window==top) { allClassesLink.style.display = "block"; } else { allClassesLink.style.display = "none"; } //--> </script> </div> <div> <ul class="subNavList"> <li>Summary: </li> <li>Nested | </li> <li>Field | </li> <li><a href="#constructor_summary">Constr</a> | </li> <li><a href="#method_summary">Method</a></li> </ul> <ul class="subNavList"> <li>Detail: </li> <li>Field | </li> <li><a href="#constructor_detail">Constr</a> | </li> <li><a href="#method_detail">Method</a></li> </ul> </div> <a name="skip-navbar_bottom"> <!-- --> </a></div> <!-- ======== END OF BOTTOM NAVBAR ======= --> </body> </html>