Feature Groups since 1.1.0

If you are using Togglz regularly, you will soon end up with a large number of feature toggles. To make sure you don't get lost in all the different feature flags, Togglz allows to define group for features. Currently feature groups are just used for a visual grouping in the admin console. So if you are not using the admin console, there is very little use for feature groups.

There are different ways of using feature groups you can think of:

  • Grouping by some category (e.g. Performance)
  • Grouping by application version number (e.g. Release 2.0)
  • Separation of older feature flags that weren't removed

To define a feature group, there are two ways. First you can add the name of the feature group as a parameter to the @FeatureGroup annotation:

@FeatureGroup("Performance Improvements")

The second way is to create a custom annotation like in the following example:

@FeatureGroup
@Label("Performance Improvements")
@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Performance {
  // no content
}

The annotation itself has to be annotated with @FeatureGroup to tell Togglz that the annotation has to be handled as a feature group. The @Label annotation is optional and allows to define a custom name for the group. If it is omitted, the name of the annotation will be used instead. The other two annotations tell the compiler that the annotation is only allowed on fields and that it should be compiled into the resulting class files.

To add features to the group, just add the new annotation to the feature enum or add the @FeatureGroup containing the value of your feature group like this:

public enum MyFeatures implements Feature {

    @Label("Enable database caching")
    @Performance
    DATABASE_CACHING,

    @FeatureGroup("Performance Improvements")
    PERFORMANCE_IMPROVEMENTS,
    
    @Label("Some other one")
    OTHER_FEATURE;

    /* ... */        
    
}

The example will add two tabs to the togglz console. One is named as "Enable database caching" and the other tab is named "Performance Improvements". All the feature groups will automatically show up as a separate tab in the Togglz Admin Console.