@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()); } } }
@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()); } } }
@SuppressWarnings("deprecation") @Test public void testSpectator() throws Exception { Map<String, Integer> stateReachedCounts = Maps.newHashMap(); HelixManager participant = HelixManagerFactory.getZKHelixManager(_clusterName, "localhost_12918", InstanceType.PARTICIPANT, ZK_ADDR); participant.getStateMachineEngine().registerStateModelFactory("OnlineOffline", new MyStateModelFactory(stateReachedCounts)); participant.connect(); RoutingTableProvider routingTableProvider = new RoutingTableProvider(); try { HelixManager spectator = HelixManagerFactory .getZKHelixManager(_clusterName, "spectator", InstanceType.SPECTATOR, ZK_ADDR); spectator.connect(); spectator.addConfigChangeListener(routingTableProvider); spectator.addExternalViewChangeListener(routingTableProvider); Thread.sleep(1000); // Now let's stop the ZK server; this should do nothing TestHelper.stopZkServer(_zkServer); Thread.sleep(1000); // Verify routing table still works Assert.assertEquals(routingTableProvider.getInstances("resource0", "ONLINE").size(), 1); Assert.assertEquals(routingTableProvider.getInstances("resource0", "OFFLINE").size(), 0); } finally { routingTableProvider.shutdown(); } }
_manager.addConfigChangeListener(listener, ConfigScopeProperty.CLUSTER); Assert.assertTrue(listener._configChanged, "Should get initial clusterConfig callback invoked"); Assert.assertEquals(listener._configSize, 1, "Cluster Config size should be 1"); _manager.addConfigChangeListener(listener, ConfigScopeProperty.RESOURCE); Assert .assertTrue(listener._configChanged, "Should get initial resourceConfig callback invoked"); _manager.addConfigChangeListener(listener, ConfigScopeProperty.PARTICIPANT); Assert .assertTrue(listener._configChanged, "Should get initial instanceConfig callback invoked");
testHelixManager.addCurrentStateChangeListener(testListener, "localhost_8900", testHelixManager.getSessionId()); testHelixManager.addConfigChangeListener(testListener); testHelixManager.addIdealStateChangeListener(testListener); testHelixManager.addExternalViewChangeListener(testListener);