net.jxta.impl.util
Class ResourceDispatcher
java.lang.Object
net.jxta.impl.util.ResourceDispatcher
public class ResourceDispatcher
- extends Object
Constructor Summary |
ResourceDispatcher(long minAccounts,
long minReservedPerAccount,
long maxReservedPerAccount,
long extraItems,
long maxExtraPerAccount,
long minExtraPoolSize,
boolean roundRobin,
String dispatcherName)
Construct a Fair Resource Allocator with the given parameters: |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ResourceDispatcher
public ResourceDispatcher(long minAccounts,
long minReservedPerAccount,
long maxReservedPerAccount,
long extraItems,
long maxExtraPerAccount,
long minExtraPoolSize,
boolean roundRobin,
String dispatcherName)
- Construct a Fair Resource Allocator with the given parameters:
- Parameters:
minAccounts
- The minimum number of client accounts that we want to
garantee we can handle. <0 means 0minReservedPerAccount
- The minimum reservation request that we will
always grant to accounts as long as we have less than minAccounts <0 means
0.maxReservedPerAccount
- The maximum reservation request that we ever
will grant to any given account. extraItems
- The total number of items that we will authorize
beyond what has been reserved. <0 means 0.maxExtraPerAccount
- The maximum number of extra items we will ever
let any given account occupy. <0 or >extraItems means ==extraItems.minExtraPoolSize
- The number of extra items that can never be
taken out of the extra pool to satisfy a reservation request.roundRobin
- If true, when there is no items available, all
eligible accounts are put in a FIFO. Accounts release items often, and the
oldest account in the FIFO will get it. If false, accounts always keep
items for as long as they can use them, and there is no FIFO of eligible
accounts. Accounts can obtain new resources only if available at the time
they try to aquire it. RoundRobin is more fair but has more overhead.
Neither mode will cause starvation as long as accounts reserve at least
one item each. RoundRobin is most usefull when allocating threads.
getNbEligibles
public int getNbEligibles()
newAccount
public ResourceAccount newAccount(long nbReq,
long maxExtra,
Object userObject)
- Creates and returns a new client account.
- Parameters:
nbReq
- the number of reserved items requested (may not be
always granted in full). A negative value is taken to mean 0.maxExtra
- the number of additional items that this account
authorizes to be allocated in addition to the reserved ones. This
is typically usefull if the items are threads and if some accounts
are not re-entrant. Then nbReq would be 1 and maxExtra would be 0.
It is also permitted to have some accounts receive no items at all
ever by setting nbReq and maxExtra both to zero. A negative maxExtra
is taken as meaning no specified limit, in which case an actual limit
may be set silently.userObject
- An opaque cookie that the account object will return
when requested. This is usefull to relate an account returned by
ClientAccount.releaseItem() to an invoking code relevant object.
- Returns:
- ResourceAccount An account with this allocator.