本文整理匯總了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);
}