本文整理汇总了Java中kafka.admin.PreferredReplicaLeaderElectionCommand类的典型用法代码示例。如果您正苦于以下问题:Java PreferredReplicaLeaderElectionCommand类的具体用法?Java PreferredReplicaLeaderElectionCommand怎么用?Java PreferredReplicaLeaderElectionCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PreferredReplicaLeaderElectionCommand类属于kafka.admin包,在下文中一共展示了PreferredReplicaLeaderElectionCommand类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: triggerPreferredLeaderElection
import kafka.admin.PreferredReplicaLeaderElectionCommand; //导入依赖的package包/类
private static void triggerPreferredLeaderElection(ZkUtils zkUtils, List<PartitionInfo> partitionInfoList) {
scala.collection.mutable.HashSet<TopicAndPartition> scalaPartitionInfoSet = new scala.collection.mutable.HashSet<>();
for (PartitionInfo javaPartitionInfo : partitionInfoList) {
scalaPartitionInfoSet.add(new TopicAndPartition(javaPartitionInfo.topic(), javaPartitionInfo.partition()));
}
PreferredReplicaLeaderElectionCommand.writePreferredReplicaElectionData(zkUtils, scalaPartitionInfoSet);
}
示例2: handleDataChange
import kafka.admin.PreferredReplicaLeaderElectionCommand; //导入依赖的package包/类
@Override
public void handleDataChange(String dataPath, Object data) throws Exception {
logger.debug("Preferred replica election listener fired for path {}. Record partitions to undergo preferred replica election {}",
dataPath, data.toString());
Set<TopicAndPartition> partitionsForPreferredReplicaElection = PreferredReplicaLeaderElectionCommand.parsePreferredReplicaElectionData(data.toString());
synchronized (controllerContext.controllerLock) {
logger.info("These partitions are already undergoing preferred replica election: {}",
controllerContext.partitionsUndergoingPreferredReplicaElection);
Set<TopicAndPartition> newPartitions = Utils.minus(partitionsForPreferredReplicaElection, controllerContext.partitionsUndergoingPreferredReplicaElection);
controller.onPreferredReplicaElection(newPartitions);
}
}
示例3: moveLeaderToPreferredReplica
import kafka.admin.PreferredReplicaLeaderElectionCommand; //导入依赖的package包/类
public void moveLeaderToPreferredReplica(String topic, int partition) {
ZkClient client = new ZkClient(zkConnects, 10000, 10000, ZKStringSerializer$.MODULE$);
TopicAndPartition topicAndPartition = new TopicAndPartition(topic, partition);
//move leader to broker 1
Set<TopicAndPartition> topicsAndPartitions = asScalaSet(Collections.singleton(topicAndPartition));
PreferredReplicaLeaderElectionCommand commands = new PreferredReplicaLeaderElectionCommand(client, topicsAndPartitions);
commands.moveLeaderToPreferredReplica();
client.close();
}
示例4: getPartitionsUndergoingPreferredReplicaElection
import kafka.admin.PreferredReplicaLeaderElectionCommand; //导入依赖的package包/类
public static Set<TopicAndPartition> getPartitionsUndergoingPreferredReplicaElection(ZkClient zkClient) {
// read the partitions and their new replica list
String jsonPartitionList = readDataMaybeNull(zkClient, PreferredReplicaLeaderElectionPath)._1;
Set<TopicAndPartition> ret = Sets.newHashSet();
if (jsonPartitionList == null) return ret;
return PreferredReplicaLeaderElectionCommand.parsePreferredReplicaElectionData(jsonPartitionList);
}