Search in sources :

Example 1 with TimeoutTask

use of org.apache.activemq.artemis.rest.util.TimeoutTask in project activemq-artemis by apache.

the class MessageServiceManager method start.

public void start() throws Exception {
    if (configuration == null || !configSet) {
        if (configResourcePath == null) {
            configuration = new MessageServiceConfiguration();
        } else {
            URL url = getClass().getClassLoader().getResource(configResourcePath);
            if (isOutsideOfClassloader(url)) {
                url = new URL(configResourcePath);
            }
            JAXBContext jaxb = JAXBContext.newInstance(MessageServiceConfiguration.class);
            Reader reader = new InputStreamReader(url.openStream());
            String xml = XMLUtil.readerToString(reader);
            xml = XMLUtil.replaceSystemProps(xml);
            configuration = (MessageServiceConfiguration) jaxb.createUnmarshaller().unmarshal(new StringReader(xml));
        }
    }
    if (threadPool == null)
        threadPool = Executors.newCachedThreadPool(ActiveMQThreadFactory.defaultThreadFactory());
    timeoutTaskInterval = configuration.getTimeoutTaskInterval();
    timeoutTask = new TimeoutTask(timeoutTaskInterval);
    threadPool.execute(timeoutTask);
    DestinationSettings defaultSettings = new DestinationSettings();
    defaultSettings.setConsumerSessionTimeoutSeconds(configuration.getConsumerSessionTimeoutSeconds());
    defaultSettings.setDuplicatesAllowed(configuration.isDupsOk());
    defaultSettings.setDurableSend(configuration.isDefaultDurableSend());
    ServerLocator consumerLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
    if (configuration.getConsumerWindowSize() != -1) {
        consumerLocator.setConsumerWindowSize(configuration.getConsumerWindowSize());
    }
    ActiveMQRestLogger.LOGGER.debug("Created ServerLocator: " + consumerLocator);
    consumerSessionFactory = consumerLocator.createSessionFactory();
    ActiveMQRestLogger.LOGGER.debug("Created ClientSessionFactory: " + consumerSessionFactory);
    ServerLocator defaultLocator = ActiveMQClient.createServerLocator(configuration.getUrl());
    ClientSessionFactory sessionFactory = defaultLocator.createSessionFactory();
    LinkStrategy linkStrategy;
    if (configuration.isUseLinkHeaders()) {
        linkStrategy = new LinkHeaderLinkStrategy();
    } else {
        linkStrategy = new CustomHeaderLinkStrategy();
    }
    queueManager.setServerLocator(defaultLocator);
    queueManager.setSessionFactory(sessionFactory);
    queueManager.setTimeoutTask(timeoutTask);
    queueManager.setConsumerServerLocator(consumerLocator);
    queueManager.setConsumerSessionFactory(consumerSessionFactory);
    queueManager.setDefaultSettings(defaultSettings);
    queueManager.setPushStoreFile(configuration.getQueuePushStoreDirectory());
    queueManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    queueManager.setLinkStrategy(linkStrategy);
    queueManager.setRegistry(registry);
    topicManager.setServerLocator(defaultLocator);
    topicManager.setSessionFactory(sessionFactory);
    topicManager.setTimeoutTask(timeoutTask);
    topicManager.setConsumerServerLocator(consumerLocator);
    topicManager.setConsumerSessionFactory(consumerSessionFactory);
    topicManager.setDefaultSettings(defaultSettings);
    topicManager.setPushStoreFile(configuration.getTopicPushStoreDirectory());
    topicManager.setProducerPoolSize(configuration.getProducerSessionPoolSize());
    queueManager.setProducerTimeToLive(configuration.getProducerTimeToLive());
    topicManager.setLinkStrategy(linkStrategy);
    topicManager.setRegistry(registry);
    queueManager.start();
    topicManager.start();
}
Also used : DestinationSettings(org.apache.activemq.artemis.rest.queue.DestinationSettings) CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) JAXBContext(javax.xml.bind.JAXBContext) URL(java.net.URL) TimeoutTask(org.apache.activemq.artemis.rest.util.TimeoutTask) CustomHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) LinkStrategy(org.apache.activemq.artemis.rest.util.LinkStrategy) StringReader(java.io.StringReader) LinkHeaderLinkStrategy(org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator)

Aggregations

InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 StringReader (java.io.StringReader)1 URL (java.net.URL)1 JAXBContext (javax.xml.bind.JAXBContext)1 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)1 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)1 DestinationSettings (org.apache.activemq.artemis.rest.queue.DestinationSettings)1 CustomHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.CustomHeaderLinkStrategy)1 LinkHeaderLinkStrategy (org.apache.activemq.artemis.rest.util.LinkHeaderLinkStrategy)1 LinkStrategy (org.apache.activemq.artemis.rest.util.LinkStrategy)1 TimeoutTask (org.apache.activemq.artemis.rest.util.TimeoutTask)1