|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectorg.curjent.agent.DynamicTasks
public abstract class DynamicTasks
Source for dynamically created tasks. This abstract class defines two method
templates for subclasses: create and discard. This
class is useful for creating and caching tasks that are too expensive in time
or memory to create up front.
This implementation is not thread-safe.
| Constructor Summary | |
|---|---|
protected |
DynamicTasks(int acquireMax,
int cacheMax,
Collection<?> cacheSeed)
Initializes the cache of tasks. |
| Method Summary | |
|---|---|
Object |
acquire()
Acquires a task. |
protected abstract Object |
create()
Creates a new task. |
protected void |
discard(Object task)
Discards a task. |
void |
release(Object task)
Releases a task. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
protected DynamicTasks(int acquireMax,
int cacheMax,
Collection<?> cacheSeed)
null) cacheSeed.
When a task is acquired, it is taken from the cache if available. If the
cache is empty, a new task is created. As many as acquireMax
tasks may be acquired. When a task is released, it is added to the cache.
The cache can hold as many as cacheMax tasks. If the cache
is full, the released task is discarded.
acquireMax - Maximum number of tasks that can be acquired.cacheMax - Maximum number of tasks that can be cached.cacheSeed - Initial cache of tasks. Possibly empty or
null.
IllegalArgumentException - acquireMax <= 0
IllegalArgumentException - acquireMax < cacheMax
IllegalArgumentException - cacheMax < 0
IllegalArgumentException - cacheSeed.size() > acquireMax| Method Detail |
|---|
protected abstract Object create()
throws Throwable
null, the acquire method returns
null, too. In this way the subclass can dynamically control
how many tasks are created and acquired. This may be fewer than or equal
to acquireMax but never more.
Throwableacquire()
protected void discard(Object task)
throws Throwable
Throwablerelease(Object)
public final Object acquire()
throws Throwable
create() returns null, this method returns
null, too.
acquire in interface AgentTasksThrowable - An unexpected error.create()
public final void release(Object task)
throws Throwable
release in interface AgentTasksNullPointerException - task == null
IllegalStateException - acquireCount <= 0
Throwable - An unexpected error.discard(Object)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||