Example usage for org.springframework.integration.util UUIDConverter getUUID

List of usage examples for org.springframework.integration.util UUIDConverter getUUID

Introduction

In this page you can find the example usage for org.springframework.integration.util UUIDConverter getUUID.

Prototype

public static UUID getUUID(Object input) 

Source Link

Document

Convenient utility to convert an object to a UUID.

Usage

From source file:org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.java

@Override
protected void handleMessageInternal(Message<?> message) throws Exception {
    Object correlationKey = correlationStrategy.getCorrelationKey(message);
    Assert.state(correlationKey != null,
            "Null correlation not allowed.  Maybe the CorrelationStrategy is failing?");

    if (logger.isDebugEnabled()) {
        logger.debug("Handling message with correlationKey [" + correlationKey + "]: " + message);
    }//from w  w w  .jav a2  s  . c  o  m

    // TODO: INT-1117 - make the lock global?
    Lock lock = this.lockRegistry.obtain(UUIDConverter.getUUID(correlationKey).toString());

    lock.lockInterruptibly();
    try {
        MessageGroup messageGroup = messageStore.getMessageGroup(correlationKey);
        if (this.sequenceAware) {
            messageGroup = new SequenceAwareMessageGroup(messageGroup);
        }

        if (!messageGroup.isComplete() && messageGroup.canAdd(message)) {
            if (logger.isTraceEnabled()) {
                logger.trace("Adding message to group [ " + messageGroup + "]");
            }
            messageGroup = this.store(correlationKey, message);

            if (releaseStrategy.canRelease(messageGroup)) {
                Collection<Message<?>> completedMessages = null;
                try {
                    completedMessages = this.completeGroup(message, correlationKey, messageGroup);
                } finally {
                    // Always clean up even if there was an exception
                    // processing messages
                    this.afterRelease(messageGroup, completedMessages);
                }
            }
        } else {
            discardChannel.send(message);
        }
    } finally {
        lock.unlock();
    }
}

From source file:org.springframework.integration.aggregator.AbstractCorrelatingMessageHandler.java

private void forceComplete(MessageGroup group) {

    Object correlationKey = group.getGroupId();
    // UUIDConverter is no-op if already converted
    Lock lock = this.lockRegistry.obtain(UUIDConverter.getUUID(correlationKey).toString());
    boolean removeGroup = true;
    try {/*from  w ww  .j av  a  2s  . co m*/
        lock.lockInterruptibly();
        try {
            /*
             * Refetch the group because it might have changed while we were waiting on
             * its lock. If the last modified timestamp changed, defer the completion
             * because the selection condition may have changed such that the group
             * would no longer be eligible.
             */
            MessageGroup groupNow = this.messageStore.getMessageGroup(group.getGroupId());
            long lastModifiedNow = groupNow.getLastModified();
            if (group.getLastModified() == lastModifiedNow) {
                if (groupNow.size() > 0) {
                    if (releaseStrategy.canRelease(groupNow)) {
                        this.completeGroup(correlationKey, groupNow);
                    } else {
                        this.expireGroup(correlationKey, groupNow);
                    }
                } else {
                    /*
                     * By default empty groups are removed on the same schedule as non-empty
                     * groups. A longer timeout for empty groups can be enabled by
                     * setting minimumTimeoutForEmptyGroups.
                     */
                    removeGroup = lastModifiedNow <= (System.currentTimeMillis()
                            - this.minimumTimeoutForEmptyGroups);
                    if (removeGroup && logger.isDebugEnabled()) {
                        logger.debug("Removing empty group: " + correlationKey);
                    }
                }
            } else {
                removeGroup = false;
                if (logger.isDebugEnabled()) {
                    logger.debug("Group expiry candidate (" + correlationKey
                            + ") has changed - it may be reconsidered for a future expiration");
                }
            }
        } finally {
            if (removeGroup) {
                this.remove(group);
            }
            lock.unlock();
        }
    } catch (InterruptedException ie) {
        Thread.currentThread().interrupt();
        throw new MessagingException("Thread was interrupted while trying to obtain lock");
    }
}

From source file:org.springframework.integration.jdbc.JdbcMessageStore.java

private String getKey(Object input) {
    return input == null ? null : UUIDConverter.getUUID(input).toString();
}

From source file:org.springframework.integration.jdbc.JdbcMessageStoreTests.java

@Test
@Transactional/*from ww w  . j a v  a  2 s.c  o  m*/
public void testRemoveMessageGroup() throws Exception {
    JdbcTemplate template = new JdbcTemplate(dataSource);
    template.afterPropertiesSet();
    String groupId = "X";

    Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
    messageStore.addMessageToGroup(groupId, message);
    messageStore.removeMessageGroup(groupId);
    MessageGroup group = messageStore.getMessageGroup(groupId);
    assertEquals(0, group.size());

    String uuidGroupId = UUIDConverter.getUUID(groupId).toString();
    assertTrue(
            template.queryForList("SELECT * from INT_GROUP_TO_MESSAGE where GROUP_KEY = '" + uuidGroupId + "'")
                    .size() == 0);
}

From source file:org.springframework.integration.jdbc.store.JdbcChannelMessageStore.java

/**
 * Helper method that converts the channel id to a UUID using
 * {@link UUIDConverter#getUUID(Object)}.
 *
 * @param input Parameter may be null/* w w  w.ja  v a2  s .c  o m*/
 * @return Returns null when the input is null otherwise the UUID as String.
 */
private String getKey(Object input) {
    return input == null ? null : UUIDConverter.getUUID(input).toString();
}