public abstract class BasicBehavior extends Object implements Behavior, TimeProvider
An abstract behavior that provides already basic functionality for
user-implemented behaviors. This behavior is fully implemented apart from the
action()
method which is intended to contain the implementation of
the actual behavior. In particular, this behavior offers several methods for
blocking the behavior until specific events occur.
If the behavior is not explicitly blocked, it is finished after executing the
action()
method. Consequently, it acts as a one-shot behavior by
default.
Note that this behavior can be re-scheduled manually after it is finished and thus automatically de-scheduled. This is due to the fact that it again waits for arbitrary events after being finished.
Constructor and Description |
---|
BasicBehavior(BehaviorController controller)
Instantiates the behavior with the specified controller.
|
Modifier and Type | Method and Description |
---|---|
abstract void |
action()
The actual implementation of this behavior.
|
void |
block()
Block this behavior until an arbitrary message arrives.
|
void |
block(Duration duration)
Block this behavior for the specified duration (measured in model time).
|
void |
blockUntil(MessagePattern pattern)
Block this behavior until a message arrives that matches the specified
message pattern.
|
void |
blockUntil(MessagePattern pattern,
Duration duration)
Block this behavior until a message arrives that matches the specified
message pattern but no longer than the specified duration (measured in
model time).
|
void |
blockUntil(MessagePattern pattern,
Timestamp timestamp)
Block this behavior until a message arrives that matches the specified
message pattern but no longer than specified timeout.
|
void |
blockUntil(Timestamp timestamp)
Block this behavior until the specified timestamp.
|
Timestamp |
currentTime()
Returns the timestamp that represents the current model time.
|
void |
finish()
Indicate that his behavior is finished and does not require
re-scheduling.
|
BehaviorController |
getController()
Returns a reference to an interface that covers those methods of the
agent that are related to behavior controlling.
|
boolean |
isFinished()
Indicates whether the behavior is finished or requires re-scheduling.
|
void |
onEnd()
This method is called by run method after the behavior
execution is finished.
|
void |
onStart()
This method is called by
run() method when the whole behavior is
executed for the first time. |
void |
reschedule()
Requests re-scheduling for this behavior as early as possible.
|
Result |
result()
Returns the result of the behavior.
|
void |
run()
This final method resets the event pattern this
behavior waits for and executes
onStart() , action() ,
and onEnd() . |
void |
setResult(Result result)
Set the result of this behavior.
|
EventPattern |
waitingFor()
Defines the event pattern for re-scheduling.
|
public BasicBehavior(BehaviorController controller)
controller
- the controller of this behaviorpublic BehaviorController getController()
public Timestamp currentTime()
TimeProvider
currentTime
in interface TimeProvider
public final void run()
This final method resets the event pattern this
behavior waits for and executes onStart()
, action()
,
and onEnd()
.
The onStart()
method is only called when the behavior is
executed for the first time. Then, the action()
method is called
every time the behavior is executed. Finally, the onEnd()
method
is called after the last execution of the behavior. A more detailed UML
state diagram can be found in the implementation specification.
public void onStart()
This method is called by run()
method when the whole behavior is
executed for the first time. Originally, the method is empty but can be
overwritten by derived implementations of this class.
This method can, for instance, be used in order to set the event pattern,
this behavior is waiting for. The action()
method of this
behavior will then be called as soon as the event pattern is satisfied.
public abstract void action()
public void onEnd()
public EventPattern waitingFor()
Behavior
waitingFor
in interface Behavior
null
if the behavior is finishedpublic boolean isFinished()
Behavior
isFinished
in interface Behavior
true
if the behavior is finished,
false
otherwisepublic void reschedule()
IllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void block(Duration duration)
duration
- the duration for blockingIllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void blockUntil(Timestamp timestamp)
timestamp
- the timestamp for re-schedulingIllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void block()
blockUntil(MessagePattern, Duration)
or blockUntil(MessagePattern, Timestamp)
.IllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void blockUntil(MessagePattern pattern)
blockUntil(MessagePattern, Duration)
or
blockUntil(MessagePattern, Timestamp)
.pattern
- the message pattern specifying awaited messagesIllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void blockUntil(MessagePattern pattern, Duration duration)
pattern
- the message pattern specifying awaited messagesduration
- the maximum duration for blockingIllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void blockUntil(MessagePattern pattern, Timestamp timestamp)
pattern
- the message pattern specifying awaited messagestimestamp
- the maximum timestamp for re-schedulingIllegalStateException
- if the method is called outside the onStart()
and
action()
call-back methodspublic void setResult(Result result)
result
- the result of this behaviorIllegalStateException
- if the method is called outside the onStart()
,
action()
, and onEnd()
call-back methodspublic void finish()
Indicate that his behavior is finished and does not require re-scheduling.
Note that his method may only be called in the action()
call-back method. If it were called in the onStart()
call-back
method, it would have no effect because the action()
is executed
once anyway (and not re-scheduled if not explicitly requested)
IllegalStateException
- if the method is called outside the action()
call-back methodCopyright © Aimpulse Intelligent Systems GmbH
All rights reserved.