Search in sources :

Example 1 with ChangeType

use of org.apache.helix.HelixConstants.ChangeType in project helix by apache.

the class GenericLeaderStandbyModel method onBecomeLeaderFromStandby.

@Transition(to = "LEADER", from = "STANDBY")
public void onBecomeLeaderFromStandby(Message message, NotificationContext context) throws Exception {
    LOG.info("Become LEADER from STANDBY");
    HelixManager manager = context.getManager();
    if (manager == null) {
        throw new IllegalArgumentException("Require HelixManager in notification conext");
    }
    for (ChangeType notificationType : _notificationTypes) {
        if (notificationType == ChangeType.LIVE_INSTANCE) {
            manager.addLiveInstanceChangeListener(_particHolder);
        } else if (notificationType == ChangeType.CONFIG) {
            manager.addConfigChangeListener(_particHolder);
        } else if (notificationType == ChangeType.EXTERNAL_VIEW) {
            manager.addExternalViewChangeListener(_particHolder);
        } else {
            LOG.error("Unsupport notificationType:" + notificationType.toString());
        }
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) ChangeType(org.apache.helix.HelixConstants.ChangeType) Transition(org.apache.helix.participant.statemachine.Transition)

Example 2 with ChangeType

use of org.apache.helix.HelixConstants.ChangeType in project helix by apache.

the class GenericLeaderStandbyModel method onBecomeStandbyFromLeader.

@Transition(to = "STANDBY", from = "LEADER")
public void onBecomeStandbyFromLeader(Message message, NotificationContext context) {
    LOG.info("Become STANDBY from LEADER");
    HelixManager manager = context.getManager();
    if (manager == null) {
        throw new IllegalArgumentException("Require HelixManager in notification conext");
    }
    Builder keyBuilder = new Builder(manager.getClusterName());
    for (ChangeType notificationType : _notificationTypes) {
        if (notificationType == ChangeType.LIVE_INSTANCE) {
            manager.removeListener(keyBuilder.liveInstances(), _particHolder);
        } else if (notificationType == ChangeType.CONFIG) {
            manager.removeListener(keyBuilder.instanceConfigs(), _particHolder);
        } else if (notificationType == ChangeType.EXTERNAL_VIEW) {
            manager.removeListener(keyBuilder.externalViews(), _particHolder);
        } else {
            LOG.error("Unsupport notificationType:" + notificationType.toString());
        }
    }
}
Also used : HelixManager(org.apache.helix.HelixManager) ChangeType(org.apache.helix.HelixConstants.ChangeType) Builder(org.apache.helix.PropertyKey.Builder) Transition(org.apache.helix.participant.statemachine.Transition)

Aggregations

ChangeType (org.apache.helix.HelixConstants.ChangeType)2 HelixManager (org.apache.helix.HelixManager)2 Transition (org.apache.helix.participant.statemachine.Transition)2 Builder (org.apache.helix.PropertyKey.Builder)1