public abstract class Observer extends Object
Modifier and Type | Field and Description |
---|---|
(package private) Thread |
awakeningThread
The waker behaviour triggered at the end of the timeout
or when the wake up date is reached.
|
private static boolean |
DEBUG |
(package private) static int |
DIRECTLY_OBSERVED |
(package private) QueryResult |
lastQueryResultOnDirectlyObserved
Store the last queried value of the DIRECTLY_OBSERVED formula.
|
(package private) KBase |
myKBase
The KBase the observer belongs to.
|
(package private) ArrayList |
observedFormulas
Stores the formulas to be observed.
|
(package private) long |
timeout
Timeout value to avoid to wait endlessly.
|
(package private) boolean |
timeoutDisabled
A boolean to check if the timeout method should be invoked
(to avoid invoking it after the success of the behaviour).
|
(package private) boolean |
updatedOnce
true if the observer value has been queried at least one time.
|
(package private) Date |
wakeUpDate
Instead of a timeout value, one can use a wake up date.
|
Constructor and Description |
---|
Observer(KBase kbase,
Formula formula)
Build an Observer for the KBase given as an argument.
|
Observer(KBase kbase,
Formula formula,
Date wakeupDate)
Builds an Observer for the kbase given as an argument.
|
Observer(KBase kbase,
Formula formula,
long timeOut)
Builds an Observer for the kbase given as an argument.
|
Modifier and Type | Method and Description |
---|---|
void |
addFormula(Formula formula)
Add a formula to observe.
|
void |
disableTimeout()
Method to disable the timeout method.
|
KBase |
getMyKBase() |
Formula[] |
getObservedFormulas()
This method returns all observed formulas
|
Long |
getTimeOut() |
Date |
getWakeUpDate() |
boolean |
isEnabledTimeout()
Method used in the timeout method of subclasses to know if it should
be executed (if the timeout is enabled) or not.
|
private void |
setupAwakeningThread()
Local method called during the initialisation of the observer (method update).
|
void |
timeout()
Timeout method called by the awakening behaviour that is
triggered at the end of the timeout or at the wakeUpDate.
|
String |
toString() |
boolean |
update(Formula formula)
This method is called to update the observer according to
the change that has just occurred on the given formula.
|
private static final boolean DEBUG
static final int DIRECTLY_OBSERVED
ArrayList observedFormulas
QueryResult lastQueryResultOnDirectlyObserved
KBase myKBase
boolean updatedOnce
long timeout
Date wakeUpDate
Thread awakeningThread
boolean timeoutDisabled
public Observer(KBase kbase, Formula formula)
kbase
- the KBase the observer belongs to. It should not be null.public Observer(KBase kbase, Formula formula, long timeOut)
kbase
- the kbase the observer belongs to. It should not be null.timeOut
- the value of the timeout. It should be positive.public Observer(KBase kbase, Formula formula, Date wakeupDate)
kbase
- the kbase the observer belongs to. It should not be null.wakeupDate
- the date of wake up. It should not be null.public Formula[] getObservedFormulas()
public Long getTimeOut()
public Date getWakeUpDate()
public KBase getMyKBase()
public void addFormula(Formula formula)
the
- formula to observe.private void setupAwakeningThread()
public void timeout()
public void disableTimeout()
public boolean isEnabledTimeout()
public boolean update(Formula formula)
formula
- the formula which has just changed (newly asserted or removed)
or null to force the update of the observer.