private ConsumerGroupProgress getOrCreateConsumerGroupProgress(final String subject, final String group, final boolean broadcast) { final Table<String, String, ConsumerGroupProgress> progresses = actionCheckpoint.getProgresses(); if (!progresses.contains(subject, group)) { final ConsumerGroupProgress progress = new ConsumerGroupProgress(subject, group, broadcast, -1, new HashMap<>()); progresses.put(subject, group, progress); } return progresses.get(subject, group); }
private ActionCheckpoint parseBySplitter(final LineReader reader, final Splitter splitter) throws IOException { final Table<String, String, ConsumerGroupProgress> progresses = HashBasedTable.create(); while (true) { final String subjectLine = reader.readLine(); if (Strings.isNullOrEmpty(subjectLine)) { break; } final List<String> subjectParts = splitter.splitToList(subjectLine); final String subject = subjectParts.get(0); final int groupCount = Integer.parseInt(subjectParts.get(1)); for (int i = 0; i < groupCount; i++) { final String groupLine = reader.readLine(); final List<String> groupParts = splitter.splitToList(groupLine); final String group = groupParts.get(0); final long maxPulledMessageSequence = Long.parseLong(groupParts.get(1)); final int consumerCount = Integer.parseInt(groupParts.get(2)); final ConsumerGroupProgress progress = new ConsumerGroupProgress(subject, group, false, maxPulledMessageSequence, new HashMap<>(consumerCount)); progresses.put(subject, group, progress); final Map<String, ConsumerProgress> consumers = progress.getConsumers(); for (int j = 0; j < consumerCount; j++) { final String consumerLine = reader.readLine(); final List<String> consumerParts = splitter.splitToList(consumerLine); final String consumerId = consumerParts.get(0); final long maxAckedPullLogSequence = Long.parseLong(consumerParts.get(1)); consumers.put(consumerId, new ConsumerProgress(subject, group, consumerId, -1, maxAckedPullLogSequence)); } } } return new ActionCheckpoint(true, -1, progresses); }
final int consumerCount = Integer.parseInt(groupParts.get(3)); final ConsumerGroupProgress progress = new ConsumerGroupProgress(subject, group, broadcast, maxPulledMessageSequence, new HashMap<>(consumerCount)); progresses.put(subject, group, progress);
private ActionCheckpoint duplicateActionCheckpoint() { actionCheckpointGuard.lock(); try { final Table<String, String, ConsumerGroupProgress> progresses = HashBasedTable.create(); for (final ConsumerGroupProgress progress : actionCheckpoint.getProgresses().values()) { final Map<String, ConsumerProgress> consumers = progress.getConsumers(); if (consumers == null) { continue; } final Map<String, ConsumerProgress> consumersCopy = new HashMap<>(); for (final ConsumerProgress consumer : consumers.values()) { consumersCopy.put(consumer.getConsumerId(), new ConsumerProgress(consumer)); } final String subject = progress.getSubject(); final String group = progress.getGroup(); progresses.put(subject, group, new ConsumerGroupProgress(subject, group, progress.isBroadcast(), progress.getPull(), consumersCopy)); } final long offset = actionCheckpoint.getOffset(); return new ActionCheckpoint(offset, progresses); } finally { actionCheckpointGuard.unlock(); } }