EvoAl uses a central blackboard in combination with CDI to exchange data between different parts of EvoAl. Every plugin is allowed to add any information to the blackboard. The implementation can be found in de.evoal.core.api.board.Blackboard
. It maps strings to arbitrary objects. Whenever a new value is set in the blackboard, it fires a CDI event of type de.evoal.core.api.board.BlackboardEntry
containing the entry's name. The class contains the entry names of all entries used by EvoAl's core system.
Setting entries using the command line
Using a parameter starting with -B
, you can set any blackboard value from the command line, such as the name of the main class. An equals sign delimit the value to set: -Bcore:main=search
.
Injecting blackboard bindings
You can access blackboard values using two different mechanisms. First of all, you can request a reference to the blackboard by using the inject annotation:
import javax.inject.Inject;
import de.evoal.core.api.board.Blackboard;
class Example {
@Inject
private Blackboard board;
public void someMethod() {
String nameOfMain = board.get(BlackboardEntry.MAIN);
// do something
}
}
Since you are not interested in the blackboard most of the time, you can directly ask CDI for a binding stored in the blackboard:
import javax.inject.Inject;
import de.evoal.core.api.board.Blackboard;
import de.evoal.core.api.cdi.BlackboardValue;
class Example {
@Inject @BlackboardValue(BlackboardEntry.MAIN)
private String nameOfMain;
}
Listening for changes
As long as you write a CDI component, you can easily listen to a change in the blackboard by using the correct method signature:
public void listener(@Observes BlackboardEvent event) {
// add your code here
}
You can choose the method's name as you want to. The important part is the method's parameter and the void
type. As it is a method that is called by the CDI runtime, you can ask for any injectable value as a parameter.
Remark
To avoid collisions between different plugins, you are encouraged to prefix your entries with a custom plugin name followed by a colon. Following this rule, all entries created by EvoAl are starting with core:
, e.g., core:main
.