/** * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown * @param message the message to offer. * @return true if offered. */ protected boolean doOffer(Message<?> message) { boolean offered = false; if (this.capacity == Integer.MAX_VALUE || this.size() < this.capacity) { this.messageGroupStore.addMessageToGroup(this.groupId, message); offered = true; this.messageStoreNotEmpty.signal(); } return offered; }
protected Collection<Message<?>> getMessages() { return this.messageGroupStore.getMessageGroup(this.groupId).getMessages(); }
@Override public int size() { return this.messageGroupStore.messageGroupSize(this.groupId); }
/** * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown * @return a message // TODO @Nullable */ protected Message<?> doPoll() { Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId); this.messageStoreNotFull.signal(); return message; }
@Override public int drainTo(Collection<? super Message<?>> collection, int maxElements) { Assert.notNull(collection, "'collection' must not be null"); int originalSize = collection.size(); ArrayList<Message<?>> list = new ArrayList<>(); final Lock lock = this.storeLock; try { lock.lockInterruptibly(); try { Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId); for (int i = 0; i < maxElements && message != null; i++) { list.add(message); message = this.messageGroupStore.pollMessageFromGroup(this.groupId); } this.messageStoreNotFull.signal(); } finally { lock.unlock(); } } catch (InterruptedException e) { this.logger.warn("Queue may not have drained completely since this operation was interrupted", e); Thread.currentThread().interrupt(); } collection.addAll(list); return collection.size() - originalSize; }
/** * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown * @return a message // TODO @Nullable */ protected Message<?> doPoll() { Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId); this.messageStoreNotFull.signal(); return message; }
protected Collection<Message<?>> getMessages() { return this.messageGroupStore.getMessageGroup(this.groupId).getMessages(); }
@Override public int size() { return this.messageGroupStore.messageGroupSize(this.groupId); }
/** * It is assumed that the 'storeLock' is being held by the caller, otherwise * IllegalMonitorStateException may be thrown * @param message the message to offer. * @return true if offered. */ protected boolean doOffer(Message<?> message) { boolean offered = false; if (this.capacity == Integer.MAX_VALUE || this.size() < this.capacity) { this.messageGroupStore.addMessageToGroup(this.groupId, message); offered = true; this.messageStoreNotEmpty.signal(); } return offered; }
@Override public int drainTo(Collection<? super Message<?>> collection, int maxElements) { Assert.notNull(collection, "'collection' must not be null"); int originalSize = collection.size(); ArrayList<Message<?>> list = new ArrayList<>(); final Lock lock = this.storeLock; try { lock.lockInterruptibly(); try { Message<?> message = this.messageGroupStore.pollMessageFromGroup(this.groupId); for (int i = 0; i < maxElements && message != null; i++) { list.add(message); message = this.messageGroupStore.pollMessageFromGroup(this.groupId); } this.messageStoreNotFull.signal(); } finally { lock.unlock(); } } catch (InterruptedException e) { this.logger.warn("Queue may not have drained completely since this operation was interrupted", e); Thread.currentThread().interrupt(); } collection.addAll(list); return collection.size() - originalSize; }