|
JXTA | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.jxta.impl.util.Dlink
net.jxta.impl.util.ResourceDispatcher.ClientAccount
class ResourceDispatcher.ClientAccount
Constructor Summary | |
---|---|
ResourceDispatcher.ClientAccount(long fromReservedItems,
long fromExtraItems,
long extraLimit,
Object userObject)
Creates a client account with this resource manager. |
Method Summary | |
---|---|
void |
beEligible()
Put that account in the queue of accounts eligible to receive a resource when one becomes available. |
void |
close()
Tear down this account. |
protected void |
finalize()
Will close the account. |
long |
getNbReserved()
Returns the number of reserved items that can still be obtained by this account. |
Object |
getUserObject()
|
void |
inNeed(boolean needs)
Call this with true as soon as this account needs a new item. |
boolean |
isEligible()
|
boolean |
isIdle()
Tells if this account is idle (that is, none of the resources that it controls are currently in use). |
void |
notEligible()
Remove that account from the queue of accounts eligible to receive a resource when one becomes available. |
boolean |
obtainItem()
Try and grant a new item to this account. |
boolean |
obtainQuantity(long quantity)
Try and grant a certain quantity. |
ResourceAccount |
releaseItem()
This will release an item and return the most eligible account to re-use this item for. |
void |
releaseQuantity(long quantity)
This will release a number of items at once rather than once. |
void |
setUserObject(Object object)
Set the userObject associated with that account. |
String |
toString()
Returns some human-readable status and identity information useful for debugging. |
Methods inherited from class net.jxta.impl.util.Dlink |
---|
isLinked, linkNewNext, linkNewPrev, next, prev, unlink |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
ResourceDispatcher.ClientAccount(long fromReservedItems, long fromExtraItems, long extraLimit, Object userObject)
fromReservedItems
- fromExtraItems
- extraLimit
- userObject
- Method Detail |
---|
public void close()
finalize
.
Calling close() or letting the account be GC'ed while some of the
resources have not been returned is an error, may create a leak and
may display a warning message.
close
in interface ResourceAccount
protected void finalize() throws Throwable
finalize
in class Object
Throwable
public boolean isIdle()
isIdle
in interface ResourceAccount
public boolean isEligible()
public void beEligible()
public void notEligible()
public boolean obtainQuantity(long quantity)
obtainQuantity
in interface ResourceAccount
quantity
- The number of units wanted. The unit is arbitrary
It is only meaningfull to the code that uses this dispatcher.
public boolean obtainItem()
obtainItem
in interface ResourceAccount
public void releaseQuantity(long quantity)
releaseQuantity
in interface ResourceAccount
quantity
- the number of items to be released.public ResourceAccount releaseItem()
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. That is typical if the items are threads.
That is normally not happening if the items are only memory.
releaseItem
in interface ResourceAccount
public void inNeed(boolean needs)
inNeed
in interface ResourceAccount
needs
- Whether the account needs a new item or not.public Object getUserObject()
getUserObject
in interface ResourceAccount
public void setUserObject(Object object)
setUserObject
in interface ResourceAccount
public long getNbReserved()
getNbReserved
in interface ResourceAccount
public String toString()
toString
in class Object
|
JXSE | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |