Blackboard
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 jakarta.inject.Inject;
import de.evoal.core.api.board.Blackboard;
import de.evoal.core.api.board.BlackboardEntry;
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 jakarta.inject.Inject;
import de.evoal.core.api.board.Blackboard;
import de.evoal.core.api.board.BlackboardEntry;
import de.evoal.core.api.cdi.BlackboardValue;
class Example {
@Inject @BlackboardValue(BlackboardEntry.MAIN)
private String nameOfMain;
}
Injecting configuration values
Components that are configured by the optimisation configuration can inject a value of it
directly. entry names the blackboard entry that holds the configuration, access the path of
attributes from its root:
import jakarta.inject.Inject;
import de.evoal.core.api.cdi.ConfigurationValue;
import de.evoal.optimisation.api.board.OptimisationBlackboardEntries;
class Example {
@Inject
@ConfigurationValue(entry = OptimisationBlackboardEntries.OPTIMISATION_CONFIGURATION,
access = "algorithm.size-of-population")
private int sizeOfPopulation;
}
A component that gets its configuration as an EObject (e.g. in init) reads its attributes
with AttributeHelper.lookup instead, see Definitions.
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 BlackboardEntry entry) {
// entry.getLabel() names the changed entry, e.g. "core:search-path"
}
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.