Since version 2.0.0 Togglz offers Activation Strategies to go with a feature. For instance, you can connect a list of server IP addresses that shall have the feature enabled. However, how are these strategies actually attached to a feature? All I saw was that I can change the strategy in the Togglz console or even edit the data by hand in the database.
What I was looking for is some default mechanism rather similar to @EnabledByDefault
. I could implement a custom state repository, it could even look for annotations, but I suspected that this solution existed out of the box.
Just to share my own solution.
An annotation for defaults
I defined annotations that should be used the way
@EnabledByDefault
is. Here is one for the server-ip strategy:Using the annotation
In the feature definition, use the annotion like this:
State repository to evaluate
I want to take the feature state from a repository if it already has been saved. If not, the annotations must be evaluated. For this, a delegation repository is needed:
Wiring is it in
Finally, to use the repository, I wired it in our
TogglzConfig
component, deferring to JDBC, but letting it be cached as well: