Example usage for org.springframework.jms.listener DefaultMessageListenerContainer getCacheLevel

List of usage examples for org.springframework.jms.listener DefaultMessageListenerContainer getCacheLevel

Introduction

In this page you can find the example usage for org.springframework.jms.listener DefaultMessageListenerContainer getCacheLevel.

Prototype

public int getCacheLevel() 

Source Link

Document

Return the level of caching that this listener container is allowed to apply.

Usage

From source file:org.springframework.integration.jms.SubscribableJmsChannelTests.java

/**
 * Blocks until the listener container has subscribed; if the container does not support
 * this test, or the caching mode is incompatible, true is returned. Otherwise blocks
 * until timeout milliseconds have passed, or the consumer has registered.
 * @see DefaultMessageListenerContainer#isRegisteredWithDestination()
 * @param timeout Timeout in milliseconds.
 * @return True if a subscriber has connected or the container/attributes does not support
 * the test. False if a valid container does not have a registered consumer within
 * timeout milliseconds.//  w  w w .j a  v a 2s . c  o m
 */
private static boolean waitUntilRegisteredWithDestination(SubscribableJmsChannel channel, long timeout) {
    AbstractMessageListenerContainer container = (AbstractMessageListenerContainer) new DirectFieldAccessor(
            channel).getPropertyValue("container");
    if (container instanceof DefaultMessageListenerContainer) {
        DefaultMessageListenerContainer listenerContainer = (DefaultMessageListenerContainer) container;
        if (listenerContainer.getCacheLevel() != DefaultMessageListenerContainer.CACHE_CONSUMER) {
            return true;
        }
        while (timeout > 0) {
            if (listenerContainer.isRegisteredWithDestination()) {
                return true;
            }
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            }
            timeout -= 100;
        }
        return false;
    }
    return true;
}