This is an implementation of the Feature Toggles pattern (also known as Feature Flags) for OSGi Service Platform. Feature Flags (also known as Feature Toggles and Feature Controls) is the software development practice that facilitates the easy enablement and disablement of deployed functionalities. Besides, feature flags ease the management of the feature's entire lifecycle. These allow you to manage components and compartmentalise risk. We can also roll out the features to a specific group of users or exclude the group from accessing it, perform A/B test and much more. It’s also the way to test how your features function in the real world and not just in an artificial test environment. Therefore, feature toggle is a widespread agile development practice in the context of continuous deployment and delivery.
- Java 8+
- OSGi R4.3+
This project comprises three bundles -
com.amitinside.featureflags.api
- The core feature flags APIcom.amitinside.featureflags.provider
- The core feature flags implementationcom.amitinside.featureflags.example
- Example project showing how to use core feature flags in codebase
As test dependencies, the following test libraries are used:
- JUnit 4.12
- Mockito Core 2.10
To use feature flags in OSGi environment, you only need to install com.amitinside.featureflags.provider
.
Want to contribute? Great! Check out Contribution Guide
Import as Eclipse Projects
- Install Bndtools
- Import all the projects (
File -> Import -> General -> Existing Projects into Workspace
)
This project is licensed under Apache License
- In your DS Component, add an attribute definition to the existing or new object class definition.
@ObjectClassDefinition
@interface MyConfig {
@AttributeDefinition(name = "My First Feature", description = "My Feature Description")
boolean osgi_feature_myfeature() default true;
}
or provide a metatype XML with the required configuration in your bundle's OSGI-INF/metatype
directory
<?xml version="1.0" encoding="UTF-8"?>
<MetaData xmlns="http://www.osgi.org/xmlns/metatype/v1.2.0" localization="en_us">
<OCD id="ExampleFeatureFlagOCD"
name="My Feature Configuration">
<AD id="osgi.feature.myfeature"
name="My First Feature"
description="My Feature Description"
type="Boolean"
cardinality="0"
required="true"
default="true">
</AD>
</OCD>
<Designate pid="ExampleFeatureFlagOSGiR4WithXML">
<Object ocdref="ExampleFeatureFlagOCD"/>
</Designate>
</MetaData>
- The primary contract of using feature flags in your codebase is to introduce boolean attribute definitions to existing or new object class definitions in metatype. The IDs of the attribute definitions must be osgi.feature.X where X is the name of your feature. And don't forget to add the aforementioned requirement capability to your manifest.
The primary benefit of this approach is that developers can use feature flags without having any dependency to any external API.
For more information, have a look at the example project.