Java Code Examples for org.apache.curator.framework.recipes.leader.LeaderSelector#autoRequeue()
The following examples show how to use
org.apache.curator.framework.recipes.leader.LeaderSelector#autoRequeue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchedulerSelector.java From workflow with Apache License 2.0 | 6 votes |
public SchedulerSelector(WorkflowManagerImpl workflowManager, QueueFactory queueFactory, AutoCleanerHolder autoCleanerHolder) { this.workflowManager = workflowManager; this.queueFactory = queueFactory; this.autoCleanerHolder = autoCleanerHolder; LeaderSelectorListener listener = new LeaderSelectorListenerAdapter() { @Override public void takeLeadership(CuratorFramework client) throws Exception { SchedulerSelector.this.takeLeadership(); } }; leaderSelector = new LeaderSelector(workflowManager.getCurator(), ZooKeeperConstants.getSchedulerLeaderPath(), listener); leaderSelector.autoRequeue(); }
Example 2
Source File: MasterElection.java From DDMQ with Apache License 2.0 | 5 votes |
public static void election(final CountDownLatch cdl) { final CuratorFramework client = ZkUtils.getCuratorClient(); final LeaderSelector selector = new LeaderSelector(client, Constants.MASTER_PATH, new LeaderSelectorListenerAdapter() { @Override public void takeLeadership(CuratorFramework curatorFramework) throws Exception { SWITCH_LOGGER.info("take master leadership"); long seekTimestamp = MetaService.getSeekTimestamp(); long zkSeekTimestamp = MetaService.getZkSeekTimestamp(); final long sleepMs = 200; long sleepCount = 0; // 如果zk上的数据丢失了, 则zkSeekTimestamp为0, 此时chronos则被block住 while (seekTimestamp < zkSeekTimestamp && zkSeekTimestamp > 0) { SWITCH_LOGGER.info("sleep {}ms to wait seekTimestamp:{} to catch up with zkSeekTimestamp:{}", sleepMs, seekTimestamp, zkSeekTimestamp); TimeUnit.MILLISECONDS.sleep(sleepMs); seekTimestamp = MetaService.getSeekTimestamp(); zkSeekTimestamp = MetaService.getZkSeekTimestamp(); sleepCount++; } state = ServerState.MASTERING; SWITCH_LOGGER.info("change server state to {}, totalSleepMs:{}ms", state, sleepCount * sleepMs); cdl.await(); state = ServerState.BACKUPING; SWITCH_LOGGER.info("release master leadership"); } }); selector.autoRequeue(); selector.start(); }
Example 3
Source File: ReplicaSetLeaderSelector.java From kylin-on-parquet-v2 with Apache License 2.0 | 5 votes |
public ReplicaSetLeaderSelector(CuratorFramework client, Node currNode, int replicaSetID) { this.node = currNode; this.replicaSetID = replicaSetID; String path = StreamingUtils.REPLICASETS_LEADER_ELECT + "/" + replicaSetID; leaderSelector = new LeaderSelector(client, path, this); leaderSelector.autoRequeue(); leaderChangeListeners = Lists.newArrayList(); }
Example 4
Source File: ExampleClient.java From xian with Apache License 2.0 | 5 votes |
public ExampleClient(CuratorFramework client, String path, String name) { this.name = name; // create a leader selector using the given path for management // all participants in a given leader selection must use the same path // ExampleClient here is also a LeaderSelectorListener but this isn't required leaderSelector = new LeaderSelector(client, path, this); // for most cases you will want your instance to requeue when it relinquishes leadership leaderSelector.autoRequeue(); }
Example 5
Source File: MasterElection.java From DDMQ with Apache License 2.0 | 5 votes |
public static void election(final CountDownLatch cdl) { final CuratorFramework client = ZkUtils.getCuratorClient(); final LeaderSelector selector = new LeaderSelector(client, Constants.MASTER_PATH, new LeaderSelectorListenerAdapter() { @Override public void takeLeadership(CuratorFramework curatorFramework) throws Exception { SWITCH_LOGGER.info("take master leadership"); long seekTimestamp = MetaService.getSeekTimestamp(); long zkSeekTimestamp = MetaService.getZkSeekTimestamp(); final long sleepMs = 200; long sleepCount = 0; // 如果zk上的数据丢失了, 则zkSeekTimestamp为0, 此时chronos则被block住 while (seekTimestamp < zkSeekTimestamp && zkSeekTimestamp > 0) { SWITCH_LOGGER.info("sleep {}ms to wait seekTimestamp:{} to catch up with zkSeekTimestamp:{}", sleepMs, seekTimestamp, zkSeekTimestamp); TimeUnit.MILLISECONDS.sleep(sleepMs); seekTimestamp = MetaService.getSeekTimestamp(); zkSeekTimestamp = MetaService.getZkSeekTimestamp(); sleepCount++; } state = ServerState.MASTERING; SWITCH_LOGGER.info("change server state to {}, totalSleepMs:{}ms", state, sleepCount * sleepMs); cdl.await(); state = ServerState.BACKUPING; SWITCH_LOGGER.info("release master leadership"); } }); selector.autoRequeue(); selector.start(); }
Example 6
Source File: LeaderSelecter.java From PoseidonX with Apache License 2.0 | 5 votes |
/** * 执行选主 */ private void electionLeader(){ cfClient = ZKUtil.getClient(StreamContant.HDFS_HADOOP_ZOOKEEPER); if(cfClient == null){ LOGGER.error("LeaderSelecter electionLeader failed so cfClient is null, HDFS_HADOOP_ZOOKEEPER=" + StreamContant.HDFS_HADOOP_ZOOKEEPER); return ; } leaderSelector = new LeaderSelector(cfClient, StreamContant.ZOOKEEPER_LEADER_DIR, this); leaderSelector.autoRequeue(); leaderSelector.start(); }
Example 7
Source File: ReplicaSetLeaderSelector.java From kylin with Apache License 2.0 | 5 votes |
public ReplicaSetLeaderSelector(CuratorFramework client, Node currNode, int replicaSetID) { this.node = currNode; this.replicaSetID = replicaSetID; String path = StreamingUtils.REPLICASETS_LEADER_ELECT + "/" + replicaSetID; leaderSelector = new LeaderSelector(client, path, this); leaderSelector.autoRequeue(); leaderChangeListeners = Lists.newArrayList(); }
Example 8
Source File: ExampleClient.java From curator with Apache License 2.0 | 5 votes |
public ExampleClient(CuratorFramework client, String path, String name) { this.name = name; // create a leader selector using the given path for management // all participants in a given leader selection must use the same path // ExampleClient here is also a LeaderSelectorListener but this isn't required leaderSelector = new LeaderSelector(client, path, this); // for most cases you will want your instance to requeue when it relinquishes leadership leaderSelector.autoRequeue(); }
Example 9
Source File: Coordinator.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public CoordinatorLeaderSelector() { String path = StreamingUtils.COORDINATOR_LEAD; leaderSelector = new LeaderSelector(zkClient, path, this); leaderSelector.autoRequeue(); }
Example 10
Source File: StreamingCoordinator.java From kylin-on-parquet-v2 with Apache License 2.0 | 4 votes |
public CoordinatorLeaderSelector() { String path = StreamingUtils.COORDINATOR_LEAD; leaderSelector = new LeaderSelector(zkClient, path, this); leaderSelector.autoRequeue(); }
Example 11
Source File: LeaderSelectorClient.java From Juice with GNU General Public License v3.0 | 4 votes |
public LeaderSelectorClient(SchedulerDriver schedulerDriver) { leaderSelector = new LeaderSelector(schedulerDriver.getCuratorUtils().getClient(), ZKLOCKS + HTTP_SEPERATOR + MESOS_FRAMEWORK_TAG, this); leaderSelector.autoRequeue(); this.schedulerDriver = schedulerDriver; }
Example 12
Source File: ClusterLeaderManager.java From cicada with MIT License | 4 votes |
@PostConstruct public void init() { leaderSelector = new LeaderSelector(zkClient, props.getMasterNodePath(), this); leaderSelector.autoRequeue(); }
Example 13
Source File: Coordinator.java From kylin with Apache License 2.0 | 4 votes |
public CoordinatorLeaderSelector() { String path = StreamingUtils.COORDINATOR_LEAD; leaderSelector = new LeaderSelector(zkClient, path, this); leaderSelector.autoRequeue(); }
Example 14
Source File: StreamingCoordinator.java From kylin with Apache License 2.0 | 4 votes |
public CoordinatorLeaderSelector() { String path = StreamingUtils.COORDINATOR_LEAD; leaderSelector = new LeaderSelector(zkClient, path, this); leaderSelector.autoRequeue(); }
Example 15
Source File: ZkClient.java From xio with Apache License 2.0 | 4 votes |
public void electLeader(String ELECTION_PATH, LeaderSelectorListener listener) { leaderSelector = new LeaderSelector(client, ELECTION_PATH, listener); leaderSelector.autoRequeue(); leaderSelector.start(); }
Example 16
Source File: ExampleClient.java From ZKRecipesByExample with Apache License 2.0 | 4 votes |
public ExampleClient(CuratorFramework client, String path, String name) { this.name = name; leaderSelector = new LeaderSelector(client, path, this); leaderSelector.autoRequeue(); }