public abstract class SimpleActivity extends Activity
SimpleActivity
is an activity that only requires a single invocation of its simpleActivity(ibis.constellation.Constellation)
method. In
particular, it has (default) implementations of Activity.initialize(ibis.constellation.Constellation)
and Activity.cleanup(ibis.constellation.Constellation)
, and it does not
expect events. It does provide a concept of a parent activity.Modifier | Constructor and Description |
---|---|
protected |
SimpleActivity(ActivityIdentifier parent,
AbstractContext context)
Constructs a
SimpleActivity with the specified parameters. |
protected |
SimpleActivity(ActivityIdentifier parent,
AbstractContext context,
boolean mayBeStolen)
Constructs a
SimpleActivity with the specified parameters. |
Modifier and Type | Method and Description |
---|---|
void |
cleanup(Constellation c)
The implementation of this method is called when the activity is finished.
|
ActivityIdentifier |
getParent()
Returns the activity identifier of the parent (as set in the constructor), so it may be
null ). |
int |
initialize(Constellation c)
The implementation of this method should perform the initial processing when the activity is first activated.
|
int |
process(Constellation c,
Event e)
The implementation of this method is called when an event is received for this activity.
|
abstract void |
simpleActivity(Constellation c)
This method, to be implemented by the activity, is called once, after which the activity will finish.
|
expectsEvents, getContext, identifier, mayBeStolen, setIdentifier
protected SimpleActivity(ActivityIdentifier parent, AbstractContext context)
SimpleActivity
with the specified parameters. This activity can only be executed by a local
executor.parent
- the activity identifier of the parent activity (may be null
).context
- the context that specifies which executors can actually execute this activity.protected SimpleActivity(ActivityIdentifier parent, AbstractContext context, boolean mayBeStolen)
SimpleActivity
with the specified parameters.parent
- the activity identifier of the parent activity (may be null
).context
- the context that specifies which executors can actually execute this activity.mayBeStolen
- when set, this activity may be stolen by other Constellations.public int initialize(Constellation c)
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.
This version of Activity.initialize(ibis.constellation.Constellation)
calls simpleActivity(ibis.constellation.Constellation)
and returns Activity.FINISH
.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 final 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 final 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 abstract void simpleActivity(Constellation c)
c
- the Constellation
on which the Activity is runningpublic ActivityIdentifier getParent()
null
).