public class

ZKHelixManager

extends Object
implements IZkStateListener HelixManager
java.lang.Object
   ↳ org.apache.helix.manager.zk.ZKHelixManager

Summary

Constants
String ALLOW_PARTICIPANT_AUTO_JOIN
int FLAPPING_TIME_WINDIOW
int MAX_DISCONNECT_THRESHOLD
[Expand]
Inherited Constants
From interface org.apache.helix.HelixManager
Fields
protected final List<HelixTimerTask> _controllerTimerTasks
protected final List<CallbackHandler> _handlers
protected LiveInstanceInfoProvider _liveInstanceInfoProvider
protected final String _zkAddress
protected ZkClient _zkclient
Public Constructors
ZKHelixManager(String clusterName, String instanceName, InstanceType instanceType, String zkAddress)
Public Methods
void addConfigChangeListener(ConfigChangeListener listener)
void addConfigChangeListener(ScopedConfigChangeListener listener, HelixConfigScope.ConfigScopeProperty scope)
void addControllerListener(ControllerChangeListener listener)
Add listener for controller change Used in distributed cluster controller
void addControllerMessageListener(MessageListener listener)
Add message listener for controller
void addCurrentStateChangeListener(CurrentStateChangeListener listener, String instanceName, String sessionId)
void addExternalViewChangeListener(ExternalViewChangeListener listener)
void addHealthStateChangeListener(HealthStateChangeListener listener, String instanceName)
void addIdealStateChangeListener(IdealStateChangeListener listener)
void addInstanceConfigChangeListener(InstanceConfigChangeListener listener)
void addLiveInstanceChangeListener(LiveInstanceChangeListener listener)
void addMessageListener(MessageListener listener, String instanceName)
void addPreConnectCallback(PreConnectCallback callback)
Add a callback that is invoked before a participant joins the cluster.
void connect()
Start participating in the cluster operations.
void disconnect()
Disconnect from the cluster.
synchronized HelixAdmin getClusterManagmentTool()
Provides admin interface to setup and modify cluster.
String getClusterName()
Returns the cluster name associated with this cluster manager
ConfigAccessor getConfigAccessor()
Get config accessor
ParticipantHealthReportCollector getHealthReportCollector()
Participant only component that periodically update participant health report to cluster manager server.
HelixDataAccessor getHelixDataAccessor()
Return the client to perform read/write operations on the cluster data store
synchronized ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore()
Get property store
String getInstanceName()
Returns the instanceName used to connect to the cluster
InstanceType getInstanceType()
Get cluster manager instance type
long getLastNotificationTime()
The time stamp is always updated when a notification is received.
ClusterMessagingService getMessagingService()
Messaging service which can be used to send cluster wide messages.
HelixManagerProperties getProperties()
Get helix manager properties read from helix-core/src/main/resources/cluster-manager.properties
String getSessionId()
Get the sessionId associated with the connection to cluster data store.
StateMachineEngine getStateMachineEngine()
String getVersion()
Get cluster manager version
void handleNewSession()
void handleStateChanged(Watcher.Event.KeeperState state)
boolean isConnected()
Check if the connection is alive, code depending on cluster manager must always do this if( manager.isConnected()){ //custom code } This will prevent client in doing anything when its disconnected from the cluster.
boolean isLeader()
Check if the cluster manager is the leader
boolean removeListener(PropertyKey key, Object listener)
Removes the listener.
void setLiveInstanceInfoProvider(LiveInstanceInfoProvider liveInstanceInfoProvider)
Add a LiveInstanceInfoProvider that is invoked before creating liveInstance.
void startTimerTasks()
start timer tasks when becomes leader
void stopTimerTasks()
stop timer tasks when becomes standby
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.I0Itec.zkclient.IZkStateListener
From interface org.apache.helix.HelixManager

Constants

public static final String ALLOW_PARTICIPANT_AUTO_JOIN

Constant Value: "allowParticipantAutoJoin"

public static final int FLAPPING_TIME_WINDIOW

Constant Value: 300000 (0x000493e0)

public static final int MAX_DISCONNECT_THRESHOLD

Constant Value: 5 (0x00000005)

Fields

protected final List<HelixTimerTask> _controllerTimerTasks

protected final List<CallbackHandler> _handlers

protected LiveInstanceInfoProvider _liveInstanceInfoProvider

protected final String _zkAddress

protected ZkClient _zkclient

Public Constructors

public ZKHelixManager (String clusterName, String instanceName, InstanceType instanceType, String zkAddress)

Public Methods

public void addConfigChangeListener (ConfigChangeListener listener)

Throws
Exception

public void addConfigChangeListener (ScopedConfigChangeListener listener, HelixConfigScope.ConfigScopeProperty scope)

Throws
Exception

public void addControllerListener (ControllerChangeListener listener)

Add listener for controller change Used in distributed cluster controller

public void addControllerMessageListener (MessageListener listener)

Add message listener for controller

public void addCurrentStateChangeListener (CurrentStateChangeListener listener, String instanceName, String sessionId)

Throws
Exception

public void addExternalViewChangeListener (ExternalViewChangeListener listener)

Throws
Exception

public void addHealthStateChangeListener (HealthStateChangeListener listener, String instanceName)

Throws
Exception

public void addIdealStateChangeListener (IdealStateChangeListener listener)

Throws
Exception

public void addInstanceConfigChangeListener (InstanceConfigChangeListener listener)

Throws
Exception

public void addLiveInstanceChangeListener (LiveInstanceChangeListener listener)

Throws
Exception

public void addMessageListener (MessageListener listener, String instanceName)

public void addPreConnectCallback (PreConnectCallback callback)

Add a callback that is invoked before a participant joins the cluster.
This zookeeper connection is established at this time and one can read existing cluster data
The purpose of this method is to allow application to have additional logic to validate their existing state and check for any errors. If the validation fails, throw exception/disable the instance. s

public void connect ()

Start participating in the cluster operations. All listeners will be initialized and will be notified for every cluster state change This method is not re-entrant. One cannot call this method twice.

Throws
Exception

public void disconnect ()

Disconnect from the cluster. All the listeners will be removed and disconnected from the server. Its important for the client to ensure that new manager instance is used when it wants to connect again.

public synchronized HelixAdmin getClusterManagmentTool ()

Provides admin interface to setup and modify cluster.

Returns
  • instantiated HelixAdmin

public String getClusterName ()

Returns the cluster name associated with this cluster manager

Returns
  • the associated cluster name

public ConfigAccessor getConfigAccessor ()

Get config accessor

Returns
  • ConfigAccessor

public ParticipantHealthReportCollector getHealthReportCollector ()

Participant only component that periodically update participant health report to cluster manager server.

Returns
  • ParticipantHealthReportCollector

public HelixDataAccessor getHelixDataAccessor ()

Return the client to perform read/write operations on the cluster data store

Returns
  • ClusterDataAccessor

public synchronized ZkHelixPropertyStore<ZNRecord> getHelixPropertyStore ()

Get property store

Returns
  • the property store that works with ZNRecord objects

public String getInstanceName ()

Returns the instanceName used to connect to the cluster

Returns
  • the associated instance name

public InstanceType getInstanceType ()

Get cluster manager instance type

Returns
  • instance type (e.g. PARTICIPANT, CONTROLLER, SPECTATOR)

public long getLastNotificationTime ()

The time stamp is always updated when a notification is received. This can be used to check if there was any new notification when previous notification was being processed. This is updated based on the notifications from listeners registered.

Returns
  • UNIX timestamp

public ClusterMessagingService getMessagingService ()

Messaging service which can be used to send cluster wide messages.

Returns
  • messaging service

public HelixManagerProperties getProperties ()

Get helix manager properties read from helix-core/src/main/resources/cluster-manager.properties

Returns
  • deserialized properties

public String getSessionId ()

Get the sessionId associated with the connection to cluster data store.

Returns
  • the session identifier

public StateMachineEngine getStateMachineEngine ()

public String getVersion ()

Get cluster manager version

Returns
  • the cluster manager version

public void handleNewSession ()

Throws
Exception

public void handleStateChanged (Watcher.Event.KeeperState state)

Throws
Exception

public boolean isConnected ()

Check if the connection is alive, code depending on cluster manager must always do this if( manager.isConnected()){ //custom code } This will prevent client in doing anything when its disconnected from the cluster. There is no need to invoke connect again if isConnected return false.

Returns
  • true if connected, false otherwise

public boolean isLeader ()

Check if the cluster manager is the leader

Returns
  • true if this is a controller and a leader of the cluster

public boolean removeListener (PropertyKey key, Object listener)

Removes the listener. If the same listener was used for multiple changes, all change notifications will be removed.
This will invoke onChange method on the listener with NotificationContext.type set to FINALIZE. Listener can clean up its state.
The data provided in this callback may not be reliable.
When a session expires all listeners will be removed and re-added automatically.
This provides the ability for listeners to either reset their state or do any cleanup tasks.

Returns
  • true if removed successfully, false otherwise

public void setLiveInstanceInfoProvider (LiveInstanceInfoProvider liveInstanceInfoProvider)

Add a LiveInstanceInfoProvider that is invoked before creating liveInstance.
This allows applications to provide additional metadata that will be published to zk and made available for discovery

public void startTimerTasks ()

start timer tasks when becomes leader

public void stopTimerTasks ()

stop timer tasks when becomes standby