public class MultiEventCollector extends Activity
MultiEventCollector
is an Activity
that just waits for a specific number of events, and collects them.
It provides a method waitForEvents()
, to be used by other activities, to collect the events and block until the
specified number of events is reached, after which the MultiEventCollector
will finish.Modifier and Type | Field and Description |
---|---|
static org.slf4j.Logger |
logger |
Constructor and Description |
---|
MultiEventCollector(AbstractContext c,
int events)
Constructs a
MultiEventCollector with the specified activity context and event count. |
Modifier and Type | Method and Description |
---|---|
void |
cleanup(Constellation c)
The implementation of this method is called when the activity is finished.
|
int |
initialize(Constellation c)
The implementation of this method should perform the initial processing when the activity is first activated.
|
boolean |
isFinished()
This method returns whether the event collector is finished, without blocking.
|
int |
process(Constellation c,
Event e)
The implementation of this method is called when an event is received for this activity.
|
java.lang.String |
toString() |
Event[] |
waitForEvents()
This method blocks waiting for the specified number of events.
|
expectsEvents, getContext, identifier, mayBeStolen, setIdentifier
public MultiEventCollector(AbstractContext c, int events)
MultiEventCollector
with the specified activity context and event count. Note: this is an
activity that will receive events (see Activity.Activity(AbstractContext, boolean)
).c
- the activity context of this event collectorevents
- the number of events to be collectedpublic int initialize(Constellation c)
Activity
Activity.SUSPEND
or Activity.FINISH
, depending on what the activity is to do next:
Activity.SUSPEND
when it wants to wait for events, and Activity.FINISH
when it is done.
Note that this method does not throw checked exceptions. It can, however, throw runtime exceptions or errors, and the
Constellation
running this Activity will deal with that.initialize
in class Activity
c
- the Constellation
on which the Activity is runningFINISH
if this Activity is done or SUSPEND
if this Activity expects events.public int process(Constellation c, Event e)
Activity
Activity.SUSPEND
or Activity.FINISH
, depending on what the activity is to do next: Activity.SUSPEND
when it
expects other events, and Activity.FINISH
when it is done.
This method is invoked once at a time, even if more events arrive more or less simultaneously.
Note that this method does not throw checked exceptions. It can, however, throw runtime exceptions or errors, and the
Constellation
running this Activity will deal with that.process
in class Activity
c
- the Constellation
on which the Activity is runninge
- the Event
to process.FINISH
if this Activity is done or SUSPEND
if this Activity expects events.public void cleanup(Constellation c)
Activity
Constellation
running this Activity will deal with that.cleanup
in class Activity
c
- the Constellation
on which the Activity is runningpublic java.lang.String toString()
toString
in class java.lang.Object
public Event[] waitForEvents()
public boolean isFinished()