@Override public int drainTo(Collection<? super T> c) { return drainTo(c, Integer.MAX_VALUE); }
@Override public T element() { T item = peek(); if (item == null) { throw new NoSuchElementException(); } return item; }
protected ConsumerBase(PulsarClientImpl client, String topic, ConsumerConfigurationData<T> conf, int receiverQueueSize, ExecutorService listenerExecutor, CompletableFuture<Consumer<T>> subscribeFuture, Schema<T> schema, ConsumerInterceptors interceptors) { super(client, topic); this.maxReceiverQueueSize = receiverQueueSize; this.subscription = conf.getSubscriptionName(); this.conf = conf; this.consumerName = conf.getConsumerName() == null ? ConsumerName.generateRandomName() : conf.getConsumerName(); this.subscribeFuture = subscribeFuture; this.listener = conf.getMessageListener(); this.consumerEventListener = conf.getConsumerEventListener(); if (receiverQueueSize <= 1) { this.incomingMessages = Queues.newArrayBlockingQueue(1); } else { this.incomingMessages = new GrowableArrayBlockingQueue<>(); } this.listenerExecutor = listenerExecutor; this.pendingReceives = Queues.newConcurrentLinkedQueue(); this.schema = schema; this.interceptors = interceptors; }
@Override public boolean offer(T e) { // Queue is unbounded and it will never reject new items put(e); return true; }
@Override public T remove() { T item = poll(); if (item == null) { throw new NoSuchElementException(); } return item; }
@Override public boolean remove(Object o) { tailLock.lock(); headLock.lock(); try { int index = this.headIndex.value; int size = this.size; for (int i = 0; i < size; i++) { T item = data[index]; if (Objects.equals(item, o)) { remove(index); return true; } index = (index + 1) & (data.length - 1); } } finally { headLock.unlock(); tailLock.unlock(); } return false; }
@Override public void put(T e) { tailLock.lock(); boolean wasEmpty = false; try { if (SIZE_UPDATER.get(this) == data.length) { expandArray(); } data[tailIndex.value] = e; tailIndex.value = (tailIndex.value + 1) & (data.length - 1); if (SIZE_UPDATER.getAndIncrement(this) == 0) { wasEmpty = true; } } finally { tailLock.unlock(); } if (wasEmpty) { headLock.lock(); try { isNotEmpty.signal(); } finally { headLock.unlock(); } } }
RawConsumerImpl(PulsarClientImpl client, ConsumerConfigurationData<byte[]> conf, CompletableFuture<Consumer<byte[]>> consumerFuture) { super(client, conf.getSingleTopic(), conf, client.externalExecutorProvider().getExecutor(), TopicName.getPartitionIndex(conf.getSingleTopic()), consumerFuture, SubscriptionMode.Durable, MessageId.earliest, Schema.BYTES, null); incomingRawMessages = new GrowableArrayBlockingQueue<>(); pendingRawReceives = new ConcurrentLinkedQueue<>(); }
@Override public boolean offer(T e, long timeout, TimeUnit unit) { // Queue is unbounded and it will never reject new items put(e); return true; }
@Override public T remove() { T item = poll(); if (item == null) { throw new NoSuchElementException(); } return item; }
@Override public boolean remove(Object o) { tailLock.lock(); headLock.lock(); try { int index = this.headIndex.value; int size = this.size; for (int i = 0; i < size; i++) { T item = data[index]; if (Objects.equals(item, o)) { remove(index); return true; } index = (index + 1) & (data.length - 1); } } finally { headLock.unlock(); tailLock.unlock(); } return false; }
@Override public void put(T e) { tailLock.lock(); boolean wasEmpty = false; try { if (SIZE_UPDATER.get(this) == data.length) { expandArray(); } data[tailIndex.value] = e; tailIndex.value = (tailIndex.value + 1) & (data.length - 1); if (SIZE_UPDATER.getAndIncrement(this) == 0) { wasEmpty = true; } } finally { tailLock.unlock(); } if (wasEmpty) { headLock.lock(); try { isNotEmpty.signal(); } finally { headLock.unlock(); } } }
protected ConsumerBase(PulsarClientImpl client, String topic, ConsumerConfigurationData<T> conf, int receiverQueueSize, ExecutorService listenerExecutor, CompletableFuture<Consumer<T>> subscribeFuture, Schema<T> schema, ConsumerInterceptors interceptors) { super(client, topic); this.maxReceiverQueueSize = receiverQueueSize; this.subscription = conf.getSubscriptionName(); this.conf = conf; this.consumerName = conf.getConsumerName() == null ? ConsumerName.generateRandomName() : conf.getConsumerName(); this.subscribeFuture = subscribeFuture; this.listener = conf.getMessageListener(); this.consumerEventListener = conf.getConsumerEventListener(); if (receiverQueueSize <= 1) { this.incomingMessages = Queues.newArrayBlockingQueue(1); } else { this.incomingMessages = new GrowableArrayBlockingQueue<>(); } this.listenerExecutor = listenerExecutor; this.pendingReceives = Queues.newConcurrentLinkedQueue(); this.schema = schema; this.interceptors = interceptors; }
@Override public boolean add(T e) { put(e); return true; }
@Override public T element() { T item = peek(); if (item == null) { throw new NoSuchElementException(); } return item; }
@Override public int drainTo(Collection<? super T> c) { return drainTo(c, Integer.MAX_VALUE); }
@Override public boolean offer(T e) { // Queue is unbounded and it will never reject new items put(e); return true; }
@Override public boolean add(T e) { put(e); return true; }