public static class

StateModelDefinition.Builder

extends Object
java.lang.Object
   ↳ org.apache.helix.model.StateModelDefinition.Builder

Class Overview

Construct a state model

Summary

Public Constructors
StateModelDefinition.Builder(StateModelDefId stateModelDefId)
Start building a state model with a id
StateModelDefinition.Builder(String stateModelName)
Start building a state model with a name
Public Methods
StateModelDefinition.Builder addState(String state)
Sets the priority to Integer.MAX_VALUE
StateModelDefinition.Builder addState(State state)
Sets the priority to Integer.MAX_VALUE
StateModelDefinition.Builder addState(State state, int priority)
Define all valid states using this method.
StateModelDefinition.Builder addState(String state, int priority)
Define all valid states using this method.
StateModelDefinition.Builder addTransition(State fromState, State toState, int priority)
Define all legal transitions between states using this method.
StateModelDefinition.Builder addTransition(State fromState, State toState)
Add a state transition with maximal priority value
StateModelDefinition.Builder addTransition(String fromState, String toState)
Add a state transition with maximal priority value
StateModelDefinition.Builder addTransition(String fromState, String toState, int priority)
Define all legal transitions between states using this method.
StateModelDefinition build()
Create a StateModelDefinition from this Builder
StateModelDefinition.Builder dynamicUpperBound(State state, String bound)
You can use this to have the bounds dynamically change based on other parameters.
StateModelDefinition.Builder dynamicUpperBound(String state, String bound)
You can use this to have the bounds dynamically change based on other parameters.
StateModelDefinition.Builder initialState(State initialState)
initial state of a replica when it starts, most commonly used initial state is OFFLINE
StateModelDefinition.Builder initialState(String initialState)
initial state of a replica when it starts, most commonly used initial state is OFFLINE
StateModelDefinition.Builder upperBound(State state, int upperBound)
Set a maximum for replicas in this state
StateModelDefinition.Builder upperBound(String state, int upperBound)
Set a maximum for replicas in this state
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public StateModelDefinition.Builder (StateModelDefId stateModelDefId)

Start building a state model with a id

Parameters
stateModelDefId state model id

public StateModelDefinition.Builder (String stateModelName)

Start building a state model with a name

Public Methods

public StateModelDefinition.Builder addState (String state)

Sets the priority to Integer.MAX_VALUE

public StateModelDefinition.Builder addState (State state)

Sets the priority to Integer.MAX_VALUE

public StateModelDefinition.Builder addState (State state, int priority)

Define all valid states using this method. Set the priority in which the constraints must be satisfied. Lets say STATE1 has a constraint of 1 and STATE2 has a constraint of 3 but only one node is up then Helix will uses the priority to see STATE constraint has to be given higher preference
Use -1 to indicates states with no constraints, like OFFLINE

Parameters
state the state to add
priority the state priority, lower number is higher priority

public StateModelDefinition.Builder addState (String state, int priority)

Define all valid states using this method. Set the priority in which the constraints must be satisfied. Lets say STATE1 has a constraint of 1 and STATE2 has a constraint of 3 but only one node is up then Helix will uses the priority to see STATE constraint has to be given higher preference
Use -1 to indicates states with no constraints, like OFFLINE

Parameters
state the state to add
priority the state priority, lower number is higher priority

public StateModelDefinition.Builder addTransition (State fromState, State toState, int priority)

Define all legal transitions between states using this method. Priority is used to order the transitions. Helix tries to maximize the number of transitions that can be fired in parallel without violating the constraint. The transitions are first sorted based on priority and transitions are selected in a greedy way until the constriants are not violated.

Parameters
fromState source
toState destination
priority priority, higher value is higher priority
Returns
  • Builder

public StateModelDefinition.Builder addTransition (State fromState, State toState)

Add a state transition with maximal priority value

Returns
  • Builder

public StateModelDefinition.Builder addTransition (String fromState, String toState)

Add a state transition with maximal priority value

Returns
  • Builder

public StateModelDefinition.Builder addTransition (String fromState, String toState, int priority)

Define all legal transitions between states using this method. Priority is used to order the transitions. Helix tries to maximize the number of transitions that can be fired in parallel without violating the constraint. The transitions are first sorted based on priority and transitions are selected in a greedy way until the constriants are not violated.

Parameters
fromState source
toState destination
priority priority, higher value is higher priority
Returns
  • Builder

public StateModelDefinition build ()

Create a StateModelDefinition from this Builder

Returns
  • StateModelDefinition

public StateModelDefinition.Builder dynamicUpperBound (State state, String bound)

You can use this to have the bounds dynamically change based on other parameters.
Currently support 2 values
R --> Refers to the number of replicas specified during resource creation. This allows having different replication factor for each resource without having to create a different state machine.
N --> Refers to all nodes in the cluster. Useful for resources that need to exist on all nodes. This way one can add/remove nodes without having the change the bounds.

Returns
  • Builder

public StateModelDefinition.Builder dynamicUpperBound (String state, String bound)

You can use this to have the bounds dynamically change based on other parameters.
Currently support 2 values
R --> Refers to the number of replicas specified during resource creation. This allows having different replication factor for each resource without having to create a different state machine.
N --> Refers to all nodes in the cluster. Useful for resources that need to exist on all nodes. This way one can add/remove nodes without having the change the bounds.

Returns
  • Builder

public StateModelDefinition.Builder initialState (State initialState)

initial state of a replica when it starts, most commonly used initial state is OFFLINE

public StateModelDefinition.Builder initialState (String initialState)

initial state of a replica when it starts, most commonly used initial state is OFFLINE

public StateModelDefinition.Builder upperBound (State state, int upperBound)

Set a maximum for replicas in this state

Parameters
state state name
upperBound maximum
Returns
  • Builder

public StateModelDefinition.Builder upperBound (String state, int upperBound)

Set a maximum for replicas in this state

Parameters
state state name
upperBound maximum
Returns
  • Builder