public class ContiguousFIFOAggregator<T> extends Object
execute(Object, Runnable)
must correspond to a key. This
key must have been previously declared with expect(Object, Callback)
.
The task will be scheduled to run when its corresponding key becomes the first expected key
amongst the other keys in this aggregator.
If on execute(Object, Runnable)
the key is not expected, the task will be executed
immediately as an edge case.
A characteristic scenario is as follows:
Modifier and Type | Class and Description |
---|---|
static interface |
ContiguousFIFOAggregator.Callback<T>
Implement this interface if you want to be notified when the key becomes the first
expected key.
|
Constructor and Description |
---|
ContiguousFIFOAggregator()
Create a new ContiguousFIFOAggregator.
|
Modifier and Type | Method and Description |
---|---|
void |
execute(T key,
Runnable task)
Attempt to execute a task corresponding to a previously declared key.
|
void |
expect(T key,
ContiguousFIFOAggregator.Callback<T> callback)
Declare a key to be expected in the future.
|
void |
forget(T key)
Remove a previously declared key that we no longer expect to execute a task for.
|
public ContiguousFIFOAggregator()
execute(Object, Runnable)
. However, in practice, if you are generating tasks in
response to UI elements appearing on the screen, you will only have a bounded set of keys.
UI elements that scroll off the screen will call forget(Object)
while new elements
will call expect(Object, Callback)
. This means that the expected
number of keys and tasks is
the maximum number of UI elements that you expect to show on the screen at any time.public void expect(T key, ContiguousFIFOAggregator.Callback<T> callback)
forget(Object)
or execute(Object, Runnable)
with this key in the future, or you will leak the key.
If you call expect with a previously expected key, the key will be placed at the back of
the expected queue and its callback will be replaced with this one.key
- the key to expect a task for. Use the same key when setting the task later
with (Object, Runnable)
.callback
- the callback to notify when the key becomes the first expected key, or null.public void forget(T key)
key
- the key previously declared in expect(Object, Callback)
.public void execute(T key, Runnable task)
key
- the key previously declared in expect(Object, Callback)
.task
- the task to execute or store, depending on its corresponding key.