@Override public MessageGroup create(MessageGroupStore messageGroupStore, Object groupId) { if (GroupType.PERSISTENT.equals(this.type)) { return new PersistentMessageGroup(messageGroupStore, new SimpleMessageGroup(groupId)); } else { return create(messageGroupStore.getMessagesForGroup(groupId), groupId); } }
@Override public MessageGroup create(Collection<? extends Message<?>> messages, Object groupId, long timestamp, boolean complete) { return new SimpleMessageGroup(this.type.get(), messages, groupId, timestamp, complete, false); }
@Override public Message<?> getOneMessageFromGroup(Object groupId) { MessageGroupMetadata groupMetadata = getGroupMetadata(groupId); if (groupMetadata != null) { UUID messageId = groupMetadata.firstId(); if (messageId != null) { return getMessage(messageId); } } return null; }
private void processForceRelease(Object groupId, long timestamp, long lastModified) { MessageGroup messageGroup = this.messageStore.getMessageGroup(groupId); if (messageGroup.getTimestamp() == timestamp && messageGroup.getLastModified() == lastModified) { this.forceReleaseProcessor.processMessageGroup(messageGroup); } }
protected void remove(MessageGroup group) { Object correlationKey = group.getGroupId(); this.messageStore.removeMessageGroup(correlationKey); }
@Override public int messageGroupSize(Object groupId) { return getMessageGroup(groupId).size(); }
@Override public Collection<Message<?>> getMessagesForGroup(Object groupId) { return getMessageGroup(groupId).getMessages(); }
protected Collection<Message<?>> getMessages() { return this.messageGroupStore.getMessageGroup(this.groupId).getMessages(); }
public PriorityChannelSpec messageStore(PriorityCapableChannelMessageStore messageGroupStore, Object groupId) { this.messageGroupQueue = new MessageGroupQueue(messageGroupStore, groupId); this.messageGroupQueue.setPriority(true); return this; }
/** * Release the group if it has more messages than the threshold and has not previously been released. * It is possible that more messages than the threshold could be released, but only if multiple consumers * receive messages from the same group concurrently. */ @Override public boolean canRelease(MessageGroup group) { return group.size() >= this.threshold; }
/** * Create a channel based on the provided {@link PriorityCapableChannelMessageStore} * and group id for message store operations. * @param messageGroupStore the {@link PriorityCapableChannelMessageStore} to use. * @param groupId to group message for this channel in the message store. * @since 5.0 */ public PriorityChannel(PriorityCapableChannelMessageStore messageGroupStore, Object groupId) { this(new MessageGroupQueue(messageGroupStore, groupId)); }
@Override public Message<?> getOneMessageFromGroup(Object groupId) { return getMessageGroup(groupId).getOne(); }
@Override public MessageMetadata getMessageMetadata(UUID messageId) { Assert.notNull(messageId, "'messageId' must not be null"); Object object = doRetrieve(this.messagePrefix + messageId); if (object != null) { extractMessage(object); if (object instanceof MessageHolder) { return ((MessageHolder) object).getMessageMetadata(); } } return null; }
@Override public void destroy() throws Exception { if (this.expireOnDestroy) { if (this.isRunning()) { logger.info("Expiring all messages from message group store: " + this.messageGroupStore); this.messageGroupStore.expireMessageGroups(0); } else { logger.debug("'expireOnDestroy' is set to 'true' but the reaper is not currently running"); } } }
@Override public int messageGroupSize(Object groupId) { MessageGroupMetadata mgm = getGroupMetadata(groupId); if (mgm != null) { return mgm.size(); } else { return 0; } }
@Override public MessageGroupMetadata getGroupMetadata(Object groupId) { return new MessageGroupMetadata(getMessageGroup(groupId)); }
@Override public MessageGroup addMessageToGroup(Object groupId, Message<?> message) { addMessagesToGroup(groupId, message); return getMessageGroup(groupId); }
@Override public int remainingCapacity() { if (this.capacity == Integer.MAX_VALUE) { return Integer.MAX_VALUE; } return this.capacity - this.size(); }
@Override protected MessageGroupFactory getMessageGroupFactory() { if (this.lazyLoadMessageGroups) { return this.persistentMessageGroupFactory; } else { return super.getMessageGroupFactory(); } }
@Override public MessageGroup create(MessageGroupStore messageGroupStore, Object groupId, long timestamp, boolean complete) { if (GroupType.PERSISTENT.equals(this.type)) { SimpleMessageGroup original = new SimpleMessageGroup(Collections.emptyList(), groupId, timestamp, complete); return new PersistentMessageGroup(messageGroupStore, original); } else { return create(messageGroupStore.getMessagesForGroup(groupId), groupId, timestamp, complete); } }