This section will explain the Codelet Observer Model, in which the Codelet is a Memory Observer.
The Memory Observer Codelet
In this feature, a Memory Object will be observed by a Codelet. This means that the Codelet will be notified when the info in the Memory Object changes. This allows the Codelet to run its proc() method only when the info changes and it does not run attached to a Timer, as it usually runs.
Why it is necessary?
This feature was developed as a necessity for limited environments, like mobile devices, for instance. In a limited environment, when the Codelet runs indiscriminately over time, it can exhaust the environment's resources, but when running as a Memory Observer it will run just when needed, and thus avoid the exhaustion.
How to use it?
First, define your Codelet:
class CodeletToTest extends Codelet {
private int counter = 0;
public int getCounter() {
return counter;
}
public CodeletToTest(String name) {
setName(name);
}
@Override
public void accessMemoryObjects() {
}
@Override
public void calculateActivation() {
}
@Override
public void proc() {
counter++;
}
}
Then, create your Codelet and set it as a Memory Observer, with the method setIsMemoryObserver(boolean isMemoryObserver), and add it to the Memory you want to observe with the memory method, addMemoryObserver(MemoryObserver memoryObserver):
MemoryObject mo = new MemoryObject();
mo.setType("TestObject");
mo.setI(0.55, 0.23);
CodeletToTest c = new CodeletToTest("Codelet 1");
c.setIsMemoryObserver(true);
mo.addMemoryObserver(c);
And that's it! Only when the MemoryObject mo has a call to its method setI(Object info), the CodeletToTest c will be notified and will run its method proc().