Search in sources :

Example 1 with MessageListenerContainer

use of org.springframework.jms.listener.MessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerEndpointRegistry method createListenerContainer.

/**
	 * Create and start a new container using the specified factory.
	 */
protected MessageListenerContainer createListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory) {
    MessageListenerContainer listenerContainer = factory.createListenerContainer(endpoint);
    if (listenerContainer instanceof InitializingBean) {
        try {
            ((InitializingBean) listenerContainer).afterPropertiesSet();
        } catch (Exception ex) {
            throw new BeanInitializationException("Failed to initialize message listener container", ex);
        }
    }
    int containerPhase = listenerContainer.getPhase();
    if (containerPhase < Integer.MAX_VALUE) {
        // a custom phase value
        if (this.phase < Integer.MAX_VALUE && this.phase != containerPhase) {
            throw new IllegalStateException("Encountered phase mismatch between container factory definitions: " + this.phase + " vs " + containerPhase);
        }
        this.phase = listenerContainer.getPhase();
    }
    return listenerContainer;
}
Also used : BeanInitializationException(org.springframework.beans.factory.BeanInitializationException) InitializingBean(org.springframework.beans.factory.InitializingBean) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) BeanInitializationException(org.springframework.beans.factory.BeanInitializationException)

Example 2 with MessageListenerContainer

use of org.springframework.jms.listener.MessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerEndpointTests method setupMessageContainerUnsupportedContainer.

@Test
public void setupMessageContainerUnsupportedContainer() {
    MessageListenerContainer container = mock(MessageListenerContainer.class);
    SimpleJmsListenerEndpoint endpoint = new SimpleJmsListenerEndpoint();
    endpoint.setMessageListener(new MessageListenerAdapter());
    thrown.expect(IllegalArgumentException.class);
    endpoint.setupListenerContainer(container);
}
Also used : MessageListenerAdapter(org.springframework.jms.listener.adapter.MessageListenerAdapter) DefaultMessageListenerContainer(org.springframework.jms.listener.DefaultMessageListenerContainer) MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer) SimpleMessageListenerContainer(org.springframework.jms.listener.SimpleMessageListenerContainer) Test(org.junit.Test)

Example 3 with MessageListenerContainer

use of org.springframework.jms.listener.MessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerEndpointRegistry method registerListenerContainer.

/**
	 * Create a message listener container for the given {@link JmsListenerEndpoint}.
	 * <p>This create the necessary infrastructure to honor that endpoint
	 * with regards to its configuration.
	 * <p>The {@code startImmediately} flag determines if the container should be
	 * started immediately.
	 * @param endpoint the endpoint to add
	 * @param factory the listener factory to use
	 * @param startImmediately start the container immediately if necessary
	 * @see #getListenerContainers()
	 * @see #getListenerContainer(String)
	 */
public void registerListenerContainer(JmsListenerEndpoint endpoint, JmsListenerContainerFactory<?> factory, boolean startImmediately) {
    Assert.notNull(endpoint, "Endpoint must not be null");
    Assert.notNull(factory, "Factory must not be null");
    String id = endpoint.getId();
    Assert.notNull(id, "Endpoint id must not be null");
    synchronized (this.listenerContainers) {
        if (this.listenerContainers.containsKey(id)) {
            throw new IllegalStateException("Another endpoint is already registered with id '" + id + "'");
        }
        MessageListenerContainer container = createListenerContainer(endpoint, factory);
        this.listenerContainers.put(id, container);
        if (startImmediately) {
            startIfNecessary(container);
        }
    }
}
Also used : MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer)

Example 4 with MessageListenerContainer

use of org.springframework.jms.listener.MessageListenerContainer in project spring-framework by spring-projects.

the class JmsListenerEndpointRegistry method stop.

@Override
public void stop(Runnable callback) {
    Collection<MessageListenerContainer> listenerContainers = getListenerContainers();
    AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback);
    for (MessageListenerContainer listenerContainer : listenerContainers) {
        listenerContainer.stop(aggregatingCallback);
    }
}
Also used : MessageListenerContainer(org.springframework.jms.listener.MessageListenerContainer)

Aggregations

MessageListenerContainer (org.springframework.jms.listener.MessageListenerContainer)4 Test (org.junit.Test)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 InitializingBean (org.springframework.beans.factory.InitializingBean)1 DefaultMessageListenerContainer (org.springframework.jms.listener.DefaultMessageListenerContainer)1 SimpleMessageListenerContainer (org.springframework.jms.listener.SimpleMessageListenerContainer)1 MessageListenerAdapter (org.springframework.jms.listener.adapter.MessageListenerAdapter)1