📄 resourcedispatcher.clientaccount.html
字号:
(close is idempotent).<P><DD><DL></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="isIdle()"><!-- --></A><H3>isIdle</H3><PRE>public boolean <B>isIdle</B>()</PRE><DL><DD>Tells if this account is idle (that is, none of the resources that it controls are currently in use). This means it can be closed safely.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#isIdle()">isIdle</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="isEligible()"><!-- --></A><H3>isEligible</H3><PRE>public boolean <B>isEligible</B>()</PRE><DL><DD><DL></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="beEligible()"><!-- --></A><H3>beEligible</H3><PRE>public void <B>beEligible</B>()</PRE><DL><DD>Put that account in the queue of accounts elligible to receive a resource when one becomes available.<P><DD><DL></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="notEligible()"><!-- --></A><H3>notEligible</H3><PRE>public void <B>notEligible</B>()</PRE><DL><DD>Remove that account from the queue of accounts elligible to receive a resource when one becomes available.<P><DD><DL></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="obtainQuantity(long)"><!-- --></A><H3>obtainQuantity</H3><PRE>public boolean <B>obtainQuantity</B>(long quantity)</PRE><DL><DD>Try and grant a certain quantity. It is usefull to manage the allocation of variable sized aggregates when what matters is the cummulated quantity rather than an item count. Quantity could be a number of bytes needed to store something for example. The advantage of using this method rather than obtainItem repeatedly is that it is obvisouly faster if quantity is more than one or two, and also that it is atomic; the entire quantity is either granted or denied. Using this routine is by definition incompatible with the round-robin mode, which could only re-assign quantities of 1. It is legal to use this routine along with round-robin mode if the same dispatcher is used to manage quantities of 1 in this manner, but an account that has failed to obtain its desired quantity is not queued for later re-assignment. And items released with releaseQuantity() are not re-assigned, so overall it is probably best to not mix the two.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#obtainQuantity(long)">obtainQuantity</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>quantity</CODE> - The number of units wanted. The unit is arbitrary It is only meaningfull to the code that uses this dispatcher.<DT><B>Returns:</B><DD>boolean whether the requested quantity is authorized.</DL></DD></DL><HR><A NAME="obtainItem()"><!-- --></A><H3>obtainItem</H3><PRE>public boolean <B>obtainItem</B>()</PRE><DL><DD>Try and grant a new item to this account. If it cannot be done, the account may be eligible for the next available extra item. That there is need is assumed (otherwise, why is this called ?).<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#obtainItem()">obtainItem</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>boolean true if an item was granted, false otherwise.</DL></DD></DL><HR><A NAME="releaseQuantity(long)"><!-- --></A><H3>releaseQuantity</H3><PRE>public void <B>releaseQuantity</B>(long quantity)</PRE><DL><DD>This will release a number of items at once rather than once. To be used in conjunctino with obtainItems(). See that method.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#releaseQuantity(long)">releaseQuantity</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>quantity</CODE> - the number of items to be released.</DL></DD></DL><HR><A NAME="releaseItem()"><!-- --></A><H3>releaseItem</H3><PRE>public <A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A> <B>releaseItem</B>()</PRE><DL><DD>This will release an item and return the most eligible account to re-use this item for. The account that is returned has been granted the item and thus the invoker is expected to do with this account whatever an invoker of obtainItem() would do in case of success. If the items that are managed are threads, the invoker is likely to be one these threads and it should therefore process the returned account as it did the one for which it was calling releaseItem, however be very carefull not to process the new account in the context of the old one; that would rapidly lead to stack overflow. In other words, be carefull of not making a construct equivalent to: process() { doStuff(); myAccount.releaseItem().getUserObject().process(); } That won't work. Instead do: work() { while (myAccount != null) { myAccount.getUserObject().doStuff(); myAccount = myAccount.releaseItem(); } } Or similar; always go back to base stack level. It is mandatory to handle accounts returned by releaseItem(). If handling leads to releaseItem, then it has to be done in a forever loop. No choice. That's typical if the items are threads. That's normally not happening if the items are memory. If this account is not using any extra item, it is the only eligible account to reuse this item. In that case, if this account needs the item, "this" is returned. Else the item is accounted as released and null is returned. If this account is using extra items, the item is accounted as released for this account, and granted to the most eligible account, which is returned. If roundRobin mode is OFF, the most eligible account can only be this. If no account has any need for the item, the item is counted as released for this item and globaly, and null is returned. If RoundRobin is ON, this account may not always be eligible for an extra item.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#releaseItem()">releaseItem</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>ResourceAccount the account to which the released item has been re-assigned. null if the released item was not re-assigned.</DL></DD></DL><HR><A NAME="inNeed(boolean)"><!-- --></A><H3>inNeed</H3><PRE>public void <B>inNeed</B>(boolean needs)</PRE><DL><DD>Call this with true as soon as account needs a new item. Call this with false as soon as account has all it needs. Accounts are taken out of the eligible list as soon as one item is obtained. Calling inNeed() is a way to get the item back in list (at the end) if the need is still present.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#inNeed(boolean)">inNeed</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Parameters:</B><DD><CODE>needs</CODE> - Whether the account needs a new item or not.</DL></DD></DL><HR><A NAME="getUserObject()"><!-- --></A><H3>getUserObject</H3><PRE>public java.lang.Object <B>getUserObject</B>()</PRE><DL><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#getUserObject()">getUserObject</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>Object The userObject that was supplied when creating the account.</DL></DD></DL><HR><A NAME="setUserObject(java.lang.Object)"><!-- --></A><H3>setUserObject</H3><PRE>public void <B>setUserObject</B>(java.lang.Object obj)</PRE><DL><DD>Set the userObject associated with that account.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#setUserObject(java.lang.Object)">setUserObject</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL></DL></DD></DL><HR><A NAME="getNbReserved()"><!-- --></A><H3>getNbReserved</H3><PRE>public long <B>getNbReserved</B>()</PRE><DL><DD>Returns the number of reserved items that can still be obtained by this account. If that number is negative it means that all reserved items are currently in use, and the number is the opposite of the number of extra items that are also currently in use by that account.<P><DD><DL><DT><B>Specified by:</B><DD><CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html#getNbReserved()">getNbReserved</A></CODE> in interface <CODE><A HREF="../../../../net/jxta/impl/util/ResourceAccount.html" title="interface in net.jxta.impl.util">ResourceAccount</A></CODE></DL></DD><DD><DL><DT><B>Returns:</B><DD>long The number of reserved items.</DL></DD></DL><HR><A NAME="toString()"><!-- --></A><H3>toString</H3><PRE>public java.lang.String <B>toString</B>()</PRE><DL><DD>Returns some human-readable status and identity information.<P><DD><DL></DL></DD><DD><DL></DL></DD></DL><!-- ========= END OF CLASS DATA ========= --><HR><!-- ======= START OF BOTTOM NAVBAR ====== --><A NAME="navbar_bottom"><!-- --></A><A HREF="#skip-navbar_bottom" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=3 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_bottom_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/ResourceDispatcher.ClientAccount.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>JXTA J2SE</EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../net/jxta/impl/util/ResourceDispatcher.html" title="class in net.jxta.impl.util"><B>PREV CLASS</B></A> <A HREF="../../../../net/jxta/impl/util/ScheduledJxtaTimer.html" title="class in net.jxta.impl.util"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../index.html" target="_top"><B>FRAMES</B></A> <A HREF="ResourceDispatcher.ClientAccount.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--></SCRIPT><NOSCRIPT> <A HREF="../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | FIELD | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: FIELD | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_bottom"></A><!-- ======== END OF BOTTOM NAVBAR ======= --><HR></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -