// set up a resource with the state model definition
ResourceConfig resource = getResource(lockUnlock);
// set up a participant
ParticipantConfig participant = getParticipant();
// cluster id should be unique
ClusterId clusterId = ClusterId.from("exampleCluster");
// a user config is an object that stores arbitrary keys and values for a scope
// in this case, the scope is the cluster with id clusterId
// this is optional
UserConfig userConfig = new UserConfig(Scope.cluster(clusterId));
userConfig.setIntField("sampleInt", 1);
// fully specify the cluster with a ClusterConfig
ClusterConfig.Builder clusterBuilder =
new ClusterConfig.Builder(clusterId).addResource(resource).addParticipant(participant)
.addStateModelDefinition(lockUnlock).userConfig(userConfig).autoJoin(true);
// add a state constraint that is more restrictive than what is in the state model
clusterBuilder.addStateUpperBoundConstraint(Scope.cluster(clusterId),
lockUnlock.getStateModelDefId(), State.from("LOCKED"), 1);
// add a transition constraint (this time with a resource scope)
clusterBuilder.addTransitionConstraint(Scope.resource(resource.getId()),
lockUnlock.getStateModelDefId(),
Transition.from(State.from("RELEASED"), State.from("LOCKED")), 1);
ClusterConfig cluster = clusterBuilder.build();
// set up a connection to work with ZooKeeper-persisted data
HelixConnection connection = new ZkHelixConnection(args[0]);
connection.connect();
// create the cluster
createCluster(cluster, connection);
// update the resource
updateResource(resource, clusterId, connection);
// update the participant
updateParticipant(participant, clusterId, connection);
// start the controller
ControllerId controllerId = ControllerId.from("exampleController");
HelixController helixController = connection.createController(clusterId, controllerId);
helixController.startAsync();
// start the specified participant
HelixParticipant helixParticipant =
connection.createParticipant(clusterId, participant.getId());
helixParticipant.getStateMachineEngine().registerStateModelFactory(
lockUnlock.getStateModelDefId(), new LockUnlockFactory());
helixParticipant.startAsync();
// start another participant via auto join