本文整理汇总了Java中org.apache.helix.HelixManager.addExternalViewChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java HelixManager.addExternalViewChangeListener方法的具体用法?Java HelixManager.addExternalViewChangeListener怎么用?Java HelixManager.addExternalViewChangeListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.helix.HelixManager
的用法示例。
在下文中一共展示了HelixManager.addExternalViewChangeListener方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBecomeLeaderFromStandby
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@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());
}
}
}
示例2: TestSpectator
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void TestSpectator() throws Exception {
HelixManager relayHelixManager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
relayHelixManager.connect();
relayHelixManager.addExternalViewChangeListener(this);
_setupTool.addResourceToCluster(CLUSTER_NAME, "NextDB", 64, STATE_MODEL);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, "NextDB", 3);
boolean result =
ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(
ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
Assert.assertTrue(_externalViewChanges.containsKey("NextDB"));
Assert.assertTrue(_externalViewChanges.containsKey(TEST_DB));
}
示例3: onBecomeOnlineFromOffline
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Transition(to = "ONLINE", from = "OFFLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context)
throws Exception {
LOG.debug(_workerId + " becomes ONLINE from OFFLINE for " + _partition);
ConfigAccessor clusterConfig = context.getManager().getConfigAccessor();
HelixManager manager = context.getManager();
HelixConfigScope clusterScope =
new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(
manager.getClusterName()).build();
String json = clusterConfig.get(clusterScope, message.getResourceName());
Dag.Node node = Dag.Node.fromJson(json);
Set<String> parentIds = node.getParentIds();
String resourceName = message.getResourceName();
int numPartitions = node.getNumPartitions();
Task task = _taskFactory.createTask(resourceName, parentIds, manager, _taskResultStore);
manager.addExternalViewChangeListener(task);
LOG.debug("Starting task for " + _partition + "...");
int partitionNum = Integer.parseInt(_partition.split("_")[1]);
task.execute(resourceName, numPartitions, partitionNum);
LOG.debug("Task for " + _partition + " done");
}
示例4: start
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void start() throws Exception {
MySQLAdmin mysqlAdmin = new MySQLAdmin(_instanceConfig);
Replicator replicator = new Replicator(_instanceConfig);
HelixManager helixManager =
HelixManagerFactory.getZKHelixManager(_clusterName, _instanceName,
InstanceType.PARTICIPANT, _zkAddress);
_context.setHelixManager(helixManager);
_context.setMysqlAdmin(mysqlAdmin);
_context.setReplicator(replicator);
MasterSlaveTransitionHandlerFactory factory = new MasterSlaveTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("MasterSlave", factory);
DatabaseTransitionHandlerFactory databaseTransitionHandlerFactory =
new DatabaseTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
databaseTransitionHandlerFactory, "DatabaseTransitionHandlerFactory");
TableTransitionHandlerFactory tableTransitionHandlerFactory =
new TableTransitionHandlerFactory(_context);
helixManager.getStateMachineEngine().registerStateModelFactory("OnlineOffline",
tableTransitionHandlerFactory, "TableTransitionHandlerFactory");
helixManager.connect();
ReplicationManager observer = new ReplicationManager(_context);
helixManager.addExternalViewChangeListener(observer);
MasterSlaveRebalancer rebalancer = new MasterSlaveRebalancer(_context);
HelixCustomCodeRunner helixCustomCodeRunner =
new HelixCustomCodeRunner(helixManager, _zkAddress).invoke(rebalancer)
.on(ChangeType.CONFIG, ChangeType.LIVE_INSTANCE)
.usingLeaderStandbyModel("MasterSlave_rebalancer");
helixCustomCodeRunner.start();
monitor();
}
示例5: registerWith
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void registerWith(HelixManager helixManager) throws Exception {
this.helixManager = helixManager;
helixManager.addIdealStateChangeListener(this);
helixManager.addInstanceConfigChangeListener(this);
helixManager.addExternalViewChangeListener(this);
helixManager.addLiveInstanceChangeListener(this);
helixManager.addControllerListener(this);
}
示例6: testSpectator
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@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();
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);
}
示例7: test
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
@Test
public void test() throws Exception {
HelixManager manager =
HelixManagerFactory.getZKHelixManager(CLUSTER_NAME, null, InstanceType.SPECTATOR, ZK_ADDR);
manager.connect();
manager.addExternalViewChangeListener(this);
manager.addIdealStateChangeListener(this);
enablePersistBestPossibleAssignment(_gZkClient, CLUSTER_NAME, true);
// Start half number of nodes.
int i = 0;
for (; i < NUM_NODE / 2; i++) {
_participants.get(i).syncStart();
}
int replica = 3;
int partition = 30;
for (String stateModel : TestStateModels) {
String db = "Test-DB-" + stateModel;
createResourceWithDelayedRebalance(CLUSTER_NAME, db, stateModel, partition, replica, replica,
0);
}
Assert.assertTrue(_clusterVerifier.verify(50000));
_startListen = true;
DelayedTransition.setDelay(50);
// add the other half of nodes.
for (; i < NUM_NODE; i++) {
_participants.get(i).syncStart();
}
Assert.assertTrue(_clusterVerifier.verify(50000));
Assert.assertTrue(_testSuccess);
}
示例8: start
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public void start() {
try {
HelixManager manager =
HelixManagerFactory.getZKHelixManager(clusterName, null, InstanceType.SPECTATOR,
zkConnectString);
manager.connect();
manager.addExternalViewChangeListener(_routingTableProvider);
} catch (Exception e) {
e.printStackTrace();
}
}
示例9: FileStoreStateModel
import org.apache.helix.HelixManager; //导入方法依赖的package包/类
public FileStoreStateModel(HelixManager manager, String resource, String partition) {
String clusterName = manager.getClusterName();
String instanceName = manager.getInstanceName();
instanceConfig = manager.getClusterManagmentTool().getInstanceConfig(clusterName, instanceName);
replicator = new Replicator(instanceConfig, resource, partition);
try {
manager.addExternalViewChangeListener(replicator);
} catch (Exception e) {
e.printStackTrace();
}
_partition = partition;
_serverId = instanceName;
}