Java Code Examples for org.springframework.jms.listener.MessageListenerContainer#stop()

The following examples show how to use org.springframework.jms.listener.MessageListenerContainer#stop() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JmsListenerEndpointRegistry.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public void stop(Runnable callback) {
	Collection<MessageListenerContainer> listenerContainers = getListenerContainers();
	AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback);
	for (MessageListenerContainer listenerContainer : listenerContainers) {
		listenerContainer.stop(aggregatingCallback);
	}
}
 
Example 2
Source File: JmsListenerEndpointRegistry.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public void stop(Runnable callback) {
	Collection<MessageListenerContainer> listenerContainers = getListenerContainers();
	AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback);
	for (MessageListenerContainer listenerContainer : listenerContainers) {
		listenerContainer.stop(aggregatingCallback);
	}
}
 
Example 3
Source File: JmsListenerEndpointRegistry.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public void stop(Runnable callback) {
	Collection<MessageListenerContainer> listenerContainers = getListenerContainers();
	AggregatingCallback aggregatingCallback = new AggregatingCallback(listenerContainers.size(), callback);
	for (MessageListenerContainer listenerContainer : listenerContainers) {
		listenerContainer.stop(aggregatingCallback);
	}
}
 
Example 4
Source File: JmsChannelModelProcessor.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void unregisterChannelModel(ChannelModel channelModel, String tenantId, EventRepositoryService eventRepositoryService) {
    String endpointId = getEndpointId(channelModel,tenantId);
    // currently it is not possible to unregister a listener container
    // In order not to do a lot of the logic that Spring does we are manually accessing the containers to remove them
    // see https://github.com/spring-projects/spring-framework/issues/24228
    MessageListenerContainer listenerContainer = endpointRegistry.getListenerContainer(endpointId);
    if (listenerContainer != null) {
        listenerContainer.stop();
    }

    if (listenerContainer instanceof DisposableBean) {
        try {
            ((DisposableBean) listenerContainer).destroy();
        } catch (Exception e) {
            throw new RuntimeException("Failed to destroy listener container", e);
        }
    }

    Field listenerContainersField = ReflectionUtils.findField(endpointRegistry.getClass(), "listenerContainers");
    if (listenerContainersField != null) {
        listenerContainersField.setAccessible(true);
        @SuppressWarnings("unchecked")
        Map<String, MessageListenerContainer> listenerContainers = (Map<String, MessageListenerContainer>) ReflectionUtils.getField(listenerContainersField, endpointRegistry);
        if (listenerContainers != null) {
            listenerContainers.remove(endpointId);
        }
    } else {
        throw new IllegalStateException("Endpoint registry " + endpointRegistry + " does not have listenerContainers field");
    }
}
 
Example 5
Source File: SearchIndexUpdateJmsMessageListener.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
 */
@Scheduled(fixedDelay = 60000)
public void controlSearchIndexUpdateJmsMessageListener()
{
    try
    {
        // Get the configuration setting.
        Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED));

        // Get the registry bean.
        JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext()
            .getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);

        // Get the search index update JMS message listener container.
        MessageListenerContainer jmsMessageListenerContainer =
            registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SEARCH_INDEX_UPDATE_QUEUE);

        // Get the current JMS message listener status and the configuration value.
        LOGGER.debug("controlSearchIndexUpdateJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}",
            ConfigurationValue.SEARCH_INDEX_UPDATE_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());

        // Apply the relative action if needed.
        if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Stopping the search index update JMS message listener ...");
            jmsMessageListenerContainer.stop();
            LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Done");
        }
        else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Starting the search index update JMS message listener ...");
            jmsMessageListenerContainer.start();
            LOGGER.info("controlSearchIndexUpdateJmsMessageListener(): Done");
        }
    }
    catch (Exception e)
    {
        LOGGER.error("controlSearchIndexUpdateJmsMessageListener(): Failed to control the search index update Jms message listener service.", e);
    }
}
 
Example 6
Source File: HerdJmsMessageListener.java    From herd with Apache License 2.0 5 votes vote down vote up
/**
 * Periodically check the configuration and apply the action to the herd JMS message listener service, if needed.
 */
@Scheduled(fixedDelay = 60000)
public void controlHerdJmsMessageListener()
{
    try
    {
        // Get the configuration setting.
        Boolean jmsMessageListenerEnabled = Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.JMS_LISTENER_ENABLED));

        // Get the registry bean.
        JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext()
            .getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);

        // Get the herd JMS message listener container.
        MessageListenerContainer jmsMessageListenerContainer = registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING);

        // Get the current JMS message listener status and the configuration value.
        LOGGER.debug("controlHerdJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}", ConfigurationValue.JMS_LISTENER_ENABLED.getKey(),
            jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());

        // Apply the relative action if needed.
        if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlHerdJmsMessageListener(): Stopping the herd JMS message listener ...");
            jmsMessageListenerContainer.stop();
            LOGGER.info("controlHerdJmsMessageListener(): Done");
        }
        else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlHerdJmsMessageListener(): Starting the herd JMS message listener ...");
            jmsMessageListenerContainer.start();
            LOGGER.info("controlHerdJmsMessageListener(): Done");
        }
    }
    catch (Exception e)
    {
        LOGGER.error("controlHerdJmsMessageListener(): Failed to control the herd Jms message listener service.", e);
    }
}
 
Example 7
Source File: JmsListenerEndpointRegistry.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public void stop() {
	for (MessageListenerContainer listenerContainer : getListenerContainers()) {
		listenerContainer.stop();
	}
}
 
Example 8
Source File: JmsListenerEndpointRegistry.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public void stop() {
	for (MessageListenerContainer listenerContainer : getListenerContainers()) {
		listenerContainer.stop();
	}
}
 
Example 9
Source File: JmsListenerEndpointRegistry.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public void stop() {
	for (MessageListenerContainer listenerContainer : getListenerContainers()) {
		listenerContainer.stop();
	}
}
 
Example 10
Source File: SampleDataJmsMessageListener.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
 */
@Scheduled(fixedDelay = 60000)
public void controlSampleDataJmsMessageListener()
{
    try
    {
        // Get the configuration setting.
        Boolean jmsMessageListenerEnabled =
            Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED));

        // Get the registry bean.
        JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext()
            .getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);

        // Get the sample data JMS message listener container.
        MessageListenerContainer jmsMessageListenerContainer =
            registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE);

        // Get the current JMS message listener status and the configuration value.
        LOGGER.debug("controlStoragePolicyProcessorJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}",
            ConfigurationValue.SAMPLE_DATA_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());

        // Apply the relative action if needed.
        if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlSampleDataJmsMessageListener(): Stopping the sample data JMS message listener ...");
            jmsMessageListenerContainer.stop();
            LOGGER.info("controlSampleDataJmsMessageListener(): Done");
        }
        else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlSampleDataJmsMessageListener(): Starting the sample data JMS message listener ...");
            jmsMessageListenerContainer.start();
            LOGGER.info("controlSampleDataJmsMessageListener(): Done");
        }
    }
    catch (Exception e)
    {
        LOGGER.error("controlSampleDataJmsMessageListener(): Failed to control the sample data Jms message listener service.", e);
    }
}
 
Example 11
Source File: StoragePolicyProcessorJmsMessageListener.java    From herd with Apache License 2.0 4 votes vote down vote up
/**
 * Periodically check the configuration and apply the action to the storage policy processor JMS message listener service, if needed.
 */
@Scheduled(fixedDelay = 60000)
public void controlStoragePolicyProcessorJmsMessageListener()
{
    try
    {
        // Get the configuration setting.
        Boolean jmsMessageListenerEnabled =
            Boolean.valueOf(configurationHelper.getProperty(ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED));

        // Get the registry bean.
        JmsListenerEndpointRegistry registry = ApplicationContextHolder.getApplicationContext()
            .getBean("org.springframework.jms.config.internalJmsListenerEndpointRegistry", JmsListenerEndpointRegistry.class);

        // Get the storage policy processor JMS message listener container.
        MessageListenerContainer jmsMessageListenerContainer =
            registry.getListenerContainer(HerdJmsDestinationResolver.SQS_DESTINATION_STORAGE_POLICY_SELECTOR_JOB_SQS_QUEUE);

        // Get the current JMS message listener status and the configuration value.
        LOGGER.debug("controlStoragePolicyProcessorJmsMessageListener(): {}={} jmsMessageListenerContainer.isRunning()={}",
            ConfigurationValue.STORAGE_POLICY_PROCESSOR_JMS_LISTENER_ENABLED.getKey(), jmsMessageListenerEnabled, jmsMessageListenerContainer.isRunning());

        // Apply the relative action if needed.
        if (!jmsMessageListenerEnabled && jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Stopping the storage policy processor JMS message listener ...");
            jmsMessageListenerContainer.stop();
            LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Done");
        }
        else if (jmsMessageListenerEnabled && !jmsMessageListenerContainer.isRunning())
        {
            LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Starting the storage policy processor JMS message listener ...");
            jmsMessageListenerContainer.start();
            LOGGER.info("controlStoragePolicyProcessorJmsMessageListener(): Done");
        }
    }
    catch (Exception e)
    {
        LOGGER.error("controlStoragePolicyProcessorJmsMessageListener(): Failed to control the storage policy processor Jms message listener service.", e);
    }
}