public List<V> values() { List<V> values = Lists.newArrayList(); forEach((key, value) -> values.add(value)); return values; }
/** * @return a new list of all keys (makes a copy) */ public List<K> keys() { List<K> keys = Lists.newArrayList(); forEach((key, value) -> keys.add(key)); return keys; }
ledgerRetryMap.forEach((cursorName, ledgerId) -> { if (log.isDebugEnabled()) { log.debug("Cursor {} Ledger {} Trying to obtain MD from BkAdmin", cursorName, ledgerId);
/** * @return a new list of all keys (makes a copy) */ public List<K> keys() { List<K> keys = Lists.newArrayList(); forEach((key, value) -> keys.add(key)); return keys; }
public List<V> values() { List<V> values = Lists.newArrayList(); forEach((key, value) -> values.add(value)); return values; }
/** * Iterates over all loaded topics in the broker */ public void forEachTopic(Consumer<Topic> consumer) { topics.forEach((n, t) -> { Optional<Topic> topic = extractTopic(t); if (topic.isPresent()) { consumer.accept(topic.get()); } }); }
public int getNumberOfNamespaceBundles() { this.numberOfNamespaceBundles = 0; this.multiLayerTopicsMap.forEach((namespaceName, bundles) -> { this.numberOfNamespaceBundles += bundles.size(); }); return this.numberOfNamespaceBundles; }
private void generate() { metricsMap.forEach((key, replicationMetrics) -> { int splitPoint = key.lastIndexOf(SEPARATOR); add(key.substring(0, splitPoint), key.substring(splitPoint + 1), replicationMetrics); replicationMetrics.reset(); }); }
public CompletableFuture<Void> stopReplProducers() { List<CompletableFuture<Void>> closeFutures = Lists.newArrayList(); replicators.forEach((region, replicator) -> closeFutures.add(replicator.disconnect())); return FutureUtil.waitForAll(closeFutures); }
private synchronized CompletableFuture<Void> closeReplProducersIfNoBacklog() { List<CompletableFuture<Void>> closeFutures = Lists.newArrayList(); replicators.forEach((region, replicator) -> closeFutures.add(replicator.disconnect(true))); return FutureUtil.waitForAll(closeFutures); }
public CompletableFuture<Void> stopReplProducers() { List<CompletableFuture<Void>> closeFutures = Lists.newArrayList(); replicators.forEach((region, replicator) -> closeFutures.add(replicator.disconnect())); return FutureUtil.waitForAll(closeFutures); }
public PersistentTopicInternalStats getInternalStats() { PersistentTopicInternalStats stats = new PersistentTopicInternalStats(); stats.entriesAddedCounter = ENTRIES_ADDED_COUNTER_UPDATER.get(this); stats.cursors = Maps.newTreeMap(); subscriptions.forEach((name, subs) -> stats.cursors.put(name, new CursorStats())); replicators.forEach((name, subs) -> stats.cursors.put(name, new CursorStats())); return stats; }
@Override public void checkInactiveSubscriptions() { final long expirationTime = TimeUnit.MINUTES.toMillis(brokerService.pulsar().getConfiguration().getSubscriptionExpirationTimeMinutes()); if (expirationTime <= 0) return; subscriptions.forEach((subName, sub) -> { if (sub.dispatcher != null && sub.dispatcher.isConsumerConnected()) return; if (System.currentTimeMillis() - sub.cursor.getLastActive() > expirationTime) { sub.delete().thenAccept( v -> log.info("[{}][{}] The subscription was deleted due to expiration", topic, subName)); } }); }
@Override public void onUpdate(String path, Policies data, Stat stat) { final NamespaceName namespace = NamespaceName.get(NamespaceBundleFactory.getNamespaceFromPoliciesPath(path)); log.info("{} updating with {}", path, data); topics.forEach((name, topicFuture) -> { if (namespace.includes(TopicName.get(name))) { // If the topic is already created, immediately apply the updated policies, otherwise once the topic is // created it'll apply the policies update topicFuture.thenAccept(topic -> { if (log.isDebugEnabled()) { log.debug("Notifying topic that policies have changed: {}", name); } topic.ifPresent(t -> t.onPoliciesUpdate(data)); }); } }); }
public Map<String, ProxyTopicStat> getStat() { Map<String, ProxyTopicStat> statMap = Maps.newHashMap(); service().getProducers().forEach((topicName, handlers) -> { ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat()); handlers.forEach(handler -> topicStat.producerStats.add(new ProducerStats(handler))); statMap.put(topicName, topicStat); }); service().getConsumers().forEach((topicName, handlers) -> { ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat()); handlers.forEach(handler -> topicStat.consumerStats.add(new ConsumerStats(handler))); statMap.put(topicName, topicStat); }); service().getReaders().forEach((topicName, handlers) -> { ProxyTopicStat topicStat = statMap.computeIfAbsent(topicName, t -> new ProxyTopicStat()); handlers.forEach(handler -> topicStat.consumerStats.add(new ConsumerStats(handler))); statMap.put(topicName, topicStat); }); return statMap; } }
public void startReplProducers() { // read repl-cluster from policies to avoid restart of replicator which are in process of disconnect and close try { Policies policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())) .orElseThrow(() -> new KeeperException.NoNodeException()); if (policies.replication_clusters != null) { Set<String> configuredClusters = Sets.newTreeSet(policies.replication_clusters); replicators.forEach((region, replicator) -> { if (configuredClusters.contains(region)) { replicator.startProducer(); } }); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("[{}] Error getting policies while starting repl-producers {}", topic, e.getMessage()); } replicators.forEach((region, replicator) -> replicator.startProducer()); } }
@Override public CompletableFuture<Void> onPoliciesUpdate(Policies data) { if (log.isDebugEnabled()) { log.debug("[{}] isEncryptionRequired changes: {} -> {}", topic, isEncryptionRequired, data.encryption_required); } isEncryptionRequired = data.encryption_required; producers.forEach(producer -> { producer.checkPermissions(); producer.checkEncryption(); }); subscriptions.forEach((subName, sub) -> sub.getConsumers().forEach(Consumer::checkPermissions)); return checkReplicationAndRetryOnFailure(); }
@Override public void checkMessageExpiry() { TopicName name = TopicName.get(topic); Policies policies; try { policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, name.getNamespace())) .orElseThrow(() -> new KeeperException.NoNodeException()); if (policies.message_ttl_in_seconds != 0) { subscriptions.forEach((subName, sub) -> sub.expireMessages(policies.message_ttl_in_seconds)); replicators.forEach((region, replicator) -> ((PersistentReplicator)replicator).expireMessages(policies.message_ttl_in_seconds)); } } catch (Exception e) { if (log.isDebugEnabled()) { log.debug("[{}] Error getting policies", topic); } } }
private void blockDispatchersWithLargeUnAckMessages() { lock.readLock().lock(); try { forEachTopic(topic -> { topic.getSubscriptions().forEach((subName, persistentSubscription) -> { if (persistentSubscription.getDispatcher() instanceof PersistentDispatcherMultipleConsumers) { PersistentDispatcherMultipleConsumers dispatcher = (PersistentDispatcherMultipleConsumers) persistentSubscription .getDispatcher(); int dispatcherUnAckMsgs = dispatcher.getTotalUnackedMessages(); if (dispatcherUnAckMsgs > maxUnackedMsgsPerDispatcher) { log.info("[{}] Blocking dispatcher due to reached max broker limit {}", dispatcher.getName(), dispatcher.getTotalUnackedMessages()); dispatcher.blockDispatcherOnUnackedMsgs(); blockedDispatchers.add(dispatcher); } } }); }); } finally { lock.readLock().unlock(); } }
private void updateSubscriptionMessageDispatchRate() { this.pulsar().getExecutor().submit(() -> { // update message-rate for each topic subscription forEachTopic(topic -> { topic.getSubscriptions().forEach((subName, persistentSubscription) -> { if (persistentSubscription.getDispatcher() instanceof PersistentDispatcherMultipleConsumers) { ((PersistentDispatcherMultipleConsumers) persistentSubscription.getDispatcher()) .getDispatchRateLimiter().updateDispatchRate(); } else if (persistentSubscription .getDispatcher() instanceof PersistentDispatcherSingleActiveConsumer) { ((PersistentDispatcherSingleActiveConsumer) persistentSubscription.getDispatcher()) .getDispatchRateLimiter().updateDispatchRate(); } }); }); }); }