It is really easy to get a new instance of Unleash. In your app you typically just want one instance,
and inject that where you need it. You will typically use a dependency injection frameworks such as
Spring or Guice to manage this.
You create a new instance with the following command:
URI unleashServer = URI.create("http://unleash.herokuapp.com/features")
Unleash unleash = new DefaultUnleash(unleashServer);
It is really simple to use unleash.
if(unleash.isEnabled("AwesomeFeature")) {
//do some magic
} else {
//do old boring stuff
}
Calling unleash.isEnabled("AwesomeFeature")
is the equvivalent of calling unleash.isEnabled("AwesomeFeature", false)
. Which means that it will return false
if it cannot find the named toggle.
If you want it to default to true, you can pass true
as the second argument:
unleash.isEnabled("AwesomeFeature", true)
By default unleash-client fetches the feature toggles from unleash-server every 10s, and stores the result in unleash-repo.json
which is located in the java.io.tmpdir
directory. This means that if the unleash-server becomes unavailable, the unleash-client will still be able to toggle the features based on the values stored in unleash-repo.json
. As a result of this, the second argument of isEnabled
will be returned in two cases:
- When
unleash-repo.json
does not exists - When the named feature toggle does not exist in
unleash-repo.json
Build:
mvn clean install
Cobertura coverage reports:
mvn cobertura:cobertura -DcoberturaFormat=html
The generated report will be available at target/site/cobertura/index.html