In order to create a boolean flag, you need two things:
-
A container class for your flags
-
A defined flag inside the container class
Creating a container class and defining a feature flag
In the examples below, a container class is defined along with a Boolean flag. The flag name, videoChat, is derived from the flag variable name. This flag is false by default.
import Foundation
import ROX
public class Flags: RoxContainer{
public let videoChat = RoxFlag();
}
#import <ROXCore/ROXCore.h>
@interface Flags : ROXBaseContainer
@property (nonatomic) ROXFlag* videoChat;
@end
#import "Flags.h"
@implementation Flags
- (instancetype)init {
self = [super init];
if (self) {
self.videoChat = [[ROXFlag alloc] init];
}
return self;
}
@end
public class Flags implements RoxContainer{
public RoxFlag videoChat = new RoxFlag();
}
const flags = {
videoChat: new Rox.Flag()
};
const flags = {
videoChat: new Rox.Flag()
};
const flags = {
videoChat: new Rox.Flag()
};
import {Flag} from 'rox-ssr';
const flags = {
videoChat: new Flag()
};
public class Flags implements RoxContainer{
public RoxFlag videoChat = new RoxFlag();
}
import kotlin.jvm.JvmField
class Flags: RoxContainer {
@JvmField
val videoChat = RoxFlag()
}
public class Flags : IRoxContainer
{
public RoxFlag videoChat = new RoxFlag();
}
from rox.server.flags.rox_flag import RoxFlag
class MyContainer:
def __init__(self):
self.video_chat = RoxFlag()
import (
"github.com/rollout/rox-go/server"
)
type Container struct {
EnableTutorial server.RoxFlag
}
var flags = &Container {
// Default value must be specified with go
EnableTutorial: server.NewRoxFlag(false),
}
require 'rox/server/rox_server'
class Container
attr_accessor :video_chat
def initialize
@video_chat = Rox::Server::RoxFlag.new
end
end
use Rox\Server\Rox;
use Rox\Server\Flags\RoxFlag;
require __DIR__ . '/vendor/autoload.php';
class Container
{
public $videoChat;
public function __construct()
{
$this->videoChat = new RoxFlag(false);
}
}
RoxStringBase *videoChat = rox_add_flag("demo.video_chat", false);
RoxStringBase *videoChat = rox_add_flag_with_freeze("demo.video_chat", false, RoxFreezeUntilLaunch);
auto videoChat = Rox::Flag::Create("demo.video_chat", false);
auto videoChat = Rox::Client::Flag::Create("demo.video_chat", false, RoxFreezeUntilLaunch);
Registering the container class
Once you have the container class, you need to register its instance to
the CloudBees Feature Management SDK. This is done with the Rox.register()
SDK function.
The namespace parameter is a logical separation between containers, and can be used to find flags on the dashboard.
Important notes
|
In the examples below, the Rox.register()
SDK function is called to
register the class instance:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
ROX.register("<namespace>", container: Flags())
ROX.setup(withKey: ROLLOUT_KEY)
return true
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[ROX register:[[Flags alloc] init]];
[ROX setupWithKey:@<ROLLOUT_KEY>];
return YES;
}
public class App extends Application {
@Override
public void onCreate() {
super.onCreate();
Flags flags = new Flags();
Rox.register("<namespace>", flags);
Rox.setup(this);
// This can also be done in the MainActivity if your app doesn't extends the Application class
}
}
const flags = {
// define Rox entities here
}
Rox.register('<namespace>', flags);
await Rox.setup('<ROLLOUT_KEY>');
const flags = {
// define Rox entities here
}
Rox.register('<namespace>', flags);
Rox.setup('<ROLLOUT_KEY>');
const flags = {
// define Rox entities here
}
Rox.register('<namespace>', flags);
await Rox.setup('<ROLLOUT_KEY>');
import {Rox} from 'rox-ssr';
const flags = {
// define Rox entities here
}
Rox.register('<namespace>', flags);
Rox.setup('<ROLLOUT_KEY>');
Flags flags = new Flags();
Rox.register("<namespace>", flags);
Rox.setup(ROLLOUT_KEY);
Container flags = new Container();
Rox.Register("<namespace>", flags);
await Rox.Setup(<ROLLOUT_KEY>);
from rox.server.rox_server import Rox
flags = MyContainer()
Rox.register(<namespace>, flags)
cancel_event = Rox.setup('<ROLLOUT_KEY>').result()
package main
import "github.com/rollout/rox-go/server"
type Container struct {
EnableTutorial server.RoxFlag
}
var flags = &Container {
// Default value must be specified with go
EnableTutorial: server.NewRoxFlag(false),
}
var rox *server.Rox
func main() {
options := server.NewRoxOptions(server.RoxOptionsBuilder {})
rox = server.NewRox()
rox.Register("<namespace>", flags)
<-rox.Setup("<ROLLOUT_KEY>", options)
}
require 'rox/server/rox_server'
class Container
end
flags = Container.new
Rox::Server::RoxServer.register(<namespace>, flags)
Rox::Server::RoxServer.setup(<ROLLOUT_KEY>).join
use Rox\Server\Flags\RoxFlag;
use Rox\Server\Rox;
class Container
{
public $videoChat;
public function __construct()
{
$this->videoChat = new RoxFlag();
}
}
$container = new Container();
Rox::register(<namespace>, $container);
Rox::setup(<ROLLOUT_KEY>);
#include <rox/server.h>
#define DEFAULT_API_KEY "ROLLOUT_KEY"
int main(int argc, char **argv) {
RoxStringBase *videoChat = rox_add_flag("demo.video_chat", false);
rox_setup(DEFAULT_API_KEY, NULL);
rox_shutdown();
}
#include <rox/client.h>
#define DEFAULT_API_KEY "ROLLOUT_KEY"
int main(int argc, char **argv) {
RoxStringBase *videoChat = rox_add_flag_with_freeze("demo.video_chat", false, RoxFreezeUntilLaunch);
rox_setup(DEFAULT_API_KEY, NULL);
rox_shutdown();
}
#include <roxx/server.h>
#define DEFAULT_API_KEY "ROLLOUT_KEY"
using namespace Rox;
int main(int argc, char **argv) {
auto videoChat = Rox::Flag::Create("demo.video_chat", false);
Rox::Setup(DEFAULT_API_KEY, NULL);
Rox::Shutdown();
}
#include <roxx/client.h>
#define DEFAULT_API_KEY "ROLLOUT_KEY"
using namespace Rox::Client;
int main(int argc, char **argv) {
auto videoChat = Rox::Client::Flag::Create("demo.video_chat", false, RoxFreezeUntilLaunch);
Rox::Setup(DEFAULT_API_KEY, NULL);
Rox::Shutdown();
}
Using the flag
The last two things you need to do in the SDK is to use the flag. You can use the flag by checking the value of the flag.
The examples below show how the flag is used:
flags.videoChat.enabled {
print("VideoChat Feature is Enabled")
}
[myContainer.videoChat enabled:^{
NSLog(@"VideoChat Feature is Enabled");
} disabled:^{
// skip the tutorial
}];
if (flags.videoChat.isEnabled()) {
Log.i(tag, "VideoChat Feature is Enabled");
}
if (flags.videoChat.isEnabled()) {
console.log('videoChat is enabled');
}
if (flags.videoChat.isEnabled()) {
console.log('videoChat is enabled');
}
if (flags.videoChat.isEnabled()) {
console.log('videoChat is enabled');
}
if (flags.videoChat.isEnabled()) {
console.log('videoChat is enabled');
}
if (flags.videoChat.isEnabled()) {
Logger.info(tag, "VideoChat Feature is Enabled");
}
if (flags.videoChat.isEnabled() == true)
{
// videoChat is enabled
}
if my_container.video_chat.is_enabled():
print('video_chat is enabled')
if (flags.VideoChat.IsEnabled(nil)) {
// start the tutorial
}
if container.video_chat.enabled?
puts "video_chat is enabled"
end
if ($container->videoChat->isEnabled()) {
echo 'video chat is enabled';
}
if (rox_is_enabled(videoChat)) {
// ...
}
if (videoChat->IsEnabled()) {
// ...
}
Default flag values
A boolean flag is false by default. To override the value, pass the desired value to the flag.
Flag freeze level Flag freeze is available on client side SDKs by default.
See Understanding a flag freeze for more information. |