Last active
December 23, 2015 16:59
-
-
Save fabito/6665650 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.inject.Inject; | |
import org.togglz.core.manager.FeatureManager; | |
import com.google.inject.Provider; | |
/** | |
* Utility class to provide static access to FeatureManager. | |
* @author fabio | |
*/ | |
public class FeatureContext { | |
@Inject | |
static Provider<FeatureManager> featureManagerProvider; | |
public static FeatureManager getFeatureManager() { | |
return featureManagerProvider.get(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.togglz.core.Feature; | |
import org.togglz.core.annotation.EnabledByDefault; | |
import org.togglz.core.annotation.Label; | |
public enum Features implements Feature { | |
@EnabledByDefault | |
@Label("First Feature") | |
FEATURE_ONE, | |
@Label("Second Feature") | |
FEATURE_TWO; | |
public boolean isActive() { | |
return FeatureContext.getFeatureManager().isActive(this); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.togglz.core.manager.FeatureManager; | |
import org.togglz.core.manager.FeatureManagerBuilder; | |
import org.togglz.core.repository.StateRepository; | |
import org.togglz.core.user.NoOpUserProvider; | |
import com.google.appengine.api.datastore.DatastoreService; | |
import com.google.appengine.api.datastore.DatastoreServiceFactory; | |
import com.google.inject.AbstractModule; | |
import com.google.inject.Provides; | |
/** | |
* Guice Module which enables Togglz feature toggles backed by memcache and | |
* datastore. | |
* | |
* @author fabio | |
*/ | |
public class FeatureToggleModule extends AbstractModule { | |
@Override | |
protected void configure() { | |
requestStaticInjection(FeatureContext.class); | |
} | |
@Provides | |
public StateRepository provideStateRepository() { | |
return new MemcacheStateRepository(new DatastoreStateRepository( | |
provideDatastoreService())); | |
} | |
@Provides | |
public FeatureManager provideFeatureManager() { | |
return new FeatureManagerBuilder().featureEnum(Features.class) | |
.stateRepository(provideStateRepository()) | |
.userProvider(new NoOpUserProvider()).build(); | |
} | |
public DatastoreService provideDatastoreService() { | |
return DatastoreServiceFactory.getDatastoreService(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment