/** * @return a new list of all values (makes a copy) */ public List<V> values() { List<V> values = Lists.newArrayList(); forEach(value -> values.add(value)); return values; }
@Override public void run(Timeout t) throws Exception { Set<MessageId> messageIds = new HashSet<>(); writeLock.lock(); try { timePartitions.addLast(new ConcurrentOpenHashSet<>()); ConcurrentOpenHashSet<MessageId> headPartition = timePartitions.removeFirst(); if (!headPartition.isEmpty()) { log.warn("[{}] {} messages have timed-out", consumerBase, timePartitions.size()); headPartition.forEach(messageId -> { messageIds.add(messageId); messageIdPartitionMap.remove(messageId); }); } } finally { writeLock.unlock(); } if (messageIds.size() > 0) { consumerBase.redeliverUnacknowledgedMessages(messageIds); } timeout = client.timer().newTimeout(this, tickDurationInMs, TimeUnit.MILLISECONDS); } }, this.tickDurationInMs, TimeUnit.MILLISECONDS);
public boolean add(MessageId messageId) { writeLock.lock(); try { ConcurrentOpenHashSet<MessageId> partition = timePartitions.peekLast(); messageIdPartitionMap.put(messageId, partition); return partition.add(messageId); } finally { writeLock.unlock(); } }
public boolean remove(V value) { checkNotNull(value); long h = hash(value); return getSection(h).remove(value, (int) h); }
log.debug("Collect stats from {} producer handlers for topic {}", handlers.size(), topic); handlers.forEach(handler -> { nsStat.numberOfMsgPublished += handler.getAndResetNumMsgsSent(); nsStat.numberOfBytesPublished += handler.getAndResetNumBytesSent(); service.getConsumers().forEach((topic, handlers) -> { if (log.isDebugEnabled()) { log.debug("Collect stats from {} consumer handlers for topic {}", handlers.size(), topic); handlers.forEach(handler -> { nsStat.numberOfMsgDelivered += handler.getAndResetNumMsgsAcked(); nsStat.numberOfBytesDelivered += handler.getAndResetNumBytesDelivered();
public boolean addConsumer(ConsumerHandler consumer) { return topicConsumerMap .computeIfAbsent(consumer.getConsumer().getTopic(), topic -> new ConcurrentOpenHashSet<>()) .add(consumer); }
public boolean remove(MessageId messageId) { writeLock.lock(); try { boolean removed = false; ConcurrentOpenHashSet<MessageId> exist = messageIdPartitionMap.remove(messageId); if (exist != null) { removed = exist.remove(messageId); } return removed; } finally { writeLock.unlock(); } }
@Override public void run(Timeout t) throws Exception { if (isAckTimeout()) { log.warn("[{}] {} messages have timed-out", consumerBase, oldOpenSet.size()); Set<MessageId> messageIds = new HashSet<>(); oldOpenSet.forEach(messageIds::add); oldOpenSet.clear(); consumerBase.redeliverUnacknowledgedMessages(messageIds); } toggle(); timeout = client.timer().newTimeout(this, ackTimeoutMillis, TimeUnit.MILLISECONDS); } }, ackTimeoutMillis, TimeUnit.MILLISECONDS);
public void clear() { writeLock.lock(); try { messageIdPartitionMap.clear(); timePartitions.clear(); int blankPartitions = (int)Math.ceil((double)ackTimeoutMillis / tickDurationInMs); for (int i = 0; i < blankPartitions + 1; i++) { timePartitions.add(new ConcurrentOpenHashSet<>()); } } finally { writeLock.unlock(); } }
nsStats.producerCount += producers.size(); bundleStats.producerCount += producers.size(); topicStatsStream.startObject(topic); producers.forEach(producer -> { producer.updateRates(); PublisherStats publisherStats = producer.getStats(); topicStatsStream.writePair("producerCount", producers.size()); topicStatsStream.writePair("averageMsgSize", topicStats.averageMsgSize); topicStatsStream.writePair("msgRateIn", topicStats.aggMsgRateIn);
public boolean addProducer(ProducerHandler producer) { return topicProducerMap .computeIfAbsent(producer.getProducer().getTopic(), topic -> new ConcurrentOpenHashSet<>()) .add(producer); }
public int removeMessagesTill(MessageId msgId) { writeLock.lock(); try { int removed = 0; Iterator<MessageId> iterator = messageIdPartitionMap.keySet().iterator(); while (iterator.hasNext()) { MessageId messageId = iterator.next(); if (messageId.compareTo(msgId) <= 0) { ConcurrentOpenHashSet<MessageId> exist = messageIdPartitionMap.get(messageId); if (exist != null) { exist.remove(messageId); } iterator.remove(); removed ++; } } return removed; } finally { writeLock.unlock(); } }
timePartitions.add(new ConcurrentOpenHashSet<>());
private boolean isProducersExceeded() { Policies policies; try { policies = brokerService.pulsar().getConfigurationCache().policiesCache() .get(AdminResource.path(POLICIES, TopicName.get(topic).getNamespace())) .orElseGet(() -> new Policies()); } catch (Exception e) { policies = new Policies(); } final int maxProducers = policies.max_producers_per_topic > 0 ? policies.max_producers_per_topic : brokerService.pulsar().getConfiguration().getMaxProducersPerTopic(); if (maxProducers > 0 && maxProducers <= producers.size()) { return true; } return false; }
public boolean contains(V value) { checkNotNull(value); long h = hash(value); return getSection(h).contains(value, (int) h); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append('{'); final AtomicBoolean first = new AtomicBoolean(true); forEach(value -> { if (!first.getAndSet(false)) { sb.append(", "); } sb.append(value.toString()); }); sb.append('}'); return sb.toString(); }
nsStats.producerCount += producers.size(); bundleStats.producerCount += producers.size(); topicStatsStream.startObject(topic); producers.forEach(producer -> { producer.updateRates(); PublisherStats publisherStats = producer.getStats(); topicStatsStream.writePair("producerCount", producers.size()); topicStatsStream.writePair("averageMsgSize", topicStatsHelper.averageMsgSize); topicStatsStream.writePair("msgRateIn", topicStatsHelper.aggMsgRateIn);