Search code examples
javaannotationstoggletogglz

togglz annotation based approach for feature validation


I have been using the togglz since last few days.

I am trying to find out if there is annotation based approach available in togglez API.

I want to do it like below -

public class Application {
  public static void main(String[] args) {
    Application application = new Application();
    boolean first=false;

    first=application.validate1();

    System.out.println(first);
  }

  @Togglz(feature = "FEATURE_01")
  public boolean validate1() {
      System.out.println("validate1");
      return false;
  }
}

Is there anything available in togglz.

I could not find it anywhere , if you have any idea about such annotation please help.

My requirement is to skip the method execution based on feature value passed into it


Solution

  • No, there is no such annotation in Togglz. You will need some framework that support interceptors for that (like Spring, CDI, EJB). Then you can implement such an interceptor yourself.

    However, to be honest I'm not sure if such an annotation would make sense. What should be the result if the feature is off? What does the method return? null? Explicit feature checks using a simple if statement are more straight forward to use in theses cases. But that's just my opinion. ;-)