WRITTEN_TYPE
- The type of data the BlackboardStorer wants to write to the
blackboard.public interface BlackboardStorer<WRITTEN_TYPE extends Serializable>
WRITTEN_TYPE
.
To illustrate the usage of this interface, two examples follow. We look at a typical
use case: Two
ResultAnalysers, MyAnalyser
and YourAnalyser
. Both want to store data
on the Blackboard to keep track of whether there is something new to look
at.
YourAnalyser
simply wants to keep track of the SEFFLoops he has already seen. He wants to use an HashSet
to do so:
public class YourAnalyser implements ResultAnalyser, BlackboardStorer<HashSet<SeffLoop>> {
public boolean canContribute(ReadOnlyBlackboardView blackboard) {
Set<SeffLoop> alreadySeen = blackboard.readFor(YourAnalyser.class);
Set<SeffLoop> allLoops = blackboard.getAllSEFFLoops();
return allLoops.size() > 0 && (alreadySeen == null || !alreadySeen.containsAll(allLoops));
}
public boolean contribute(AnalyserBlackboardView blackboard) {
Set<SeffLoop> alreadySeen = blackboard.readFor(YourAnalyser.class);
if (alreadySeen == null) {
alreadySeen = new HashSet<SeffLoop>();
blackboard.writeFor(YourAnalyser.class, alreadySeen);
}
Set<SeffLoop> allLoops = blackboard.getAllSEFFLoops();
Set<SeffLoop> todo = allLoops.removeAll(alreadySeen);
for (SeffLoop loop : todo) {
// do the logic here
alreadySeen.add(loop);
}
}
}
MyAnalyser
however, wants to use its own data structure:
public MyAnalyserDataStructure implements Serializable {
// a whole bunch of getters and setters
}
public class MyAnalyser implements ResultAnalyser, BlackboardStorer<MyAnalyserDataStructure> {
// everything here is like above:
public boolean canContribute(ReadOnlyBlackboardView blackboard) {
MyAnalyserDataStructure stored = blackboard.readFor(MyAnalyser.class);
// …
}
public boolean contribute(AnalyserBlackboardView blackboard) {
MyAnalyserDataStructure stored = blackboard.readFor(MyAnalyser.class);
// …
MyAnalyserDataStructure newData = new MyAnalyserDataStructure();
// …
blackboard.writeFor(MyAnalyser.class, newData);
// …
}
Blackboard