Search in sources :

Example 1 with CachingDistributionQueue

use of org.apache.sling.distribution.queue.impl.CachingDistributionQueue in project sling by apache.

the class JobHandlingDistributionQueueProvider method getQueue.

@Nonnull
public DistributionQueue getQueue(@Nonnull String queueName) {
    String topic = JobHandlingDistributionQueue.DISTRIBUTION_QUEUE_TOPIC + '/' + prefix + "/" + queueName;
    boolean isActive = jobConsumer != null && (processingQueueNames == null || processingQueueNames.contains(queueName));
    DistributionQueue queue = new JobHandlingDistributionQueue(queueName, topic, jobManager, isActive, DistributionQueueType.ORDERED);
    queue = new CachingDistributionQueue(topic, queue);
    return queue;
}
Also used : CachingDistributionQueue(org.apache.sling.distribution.queue.impl.CachingDistributionQueue) CachingDistributionQueue(org.apache.sling.distribution.queue.impl.CachingDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Nonnull(javax.annotation.Nonnull)

Example 2 with CachingDistributionQueue

use of org.apache.sling.distribution.queue.impl.CachingDistributionQueue in project sling by apache.

the class JobHandlingDistributionQueueProvider method getQueue.

@Override
public DistributionQueue getQueue(@Nonnull String queueName, @Nonnull DistributionQueueType type) {
    String topic = JobHandlingDistributionQueue.DISTRIBUTION_QUEUE_TOPIC + '/' + type.name().toLowerCase() + '/' + prefix + "/" + queueName;
    boolean isActive = jobConsumer != null && (processingQueueNames == null || processingQueueNames.contains(queueName));
    try {
        if (configAdmin != null && jobManager.getQueue(queueName) == null && configAdmin.getConfiguration(queueName) == null) {
            Configuration config = configAdmin.createFactoryConfiguration(QueueConfiguration.class.getName(), null);
            Dictionary<String, Object> props = new Hashtable<String, Object>();
            props.put(ConfigurationConstants.PROP_NAME, queueName);
            props.put(ConfigurationConstants.PROP_TYPE, QueueConfiguration.Type.UNORDERED.name());
            props.put(ConfigurationConstants.PROP_TOPICS, new String[] { topic });
            props.put(ConfigurationConstants.PROP_RETRIES, -1);
            props.put(ConfigurationConstants.PROP_RETRY_DELAY, 2000L);
            props.put(ConfigurationConstants.PROP_KEEP_JOBS, true);
            props.put(ConfigurationConstants.PROP_PRIORITY, "MAX");
            config.update(props);
        }
    } catch (IOException e) {
        throw new RuntimeException("could not create config for queue " + queueName, e);
    }
    DistributionQueue queue = new JobHandlingDistributionQueue(queueName, topic, jobManager, isActive, type);
    queue = new CachingDistributionQueue(topic, queue);
    return queue;
}
Also used : CachingDistributionQueue(org.apache.sling.distribution.queue.impl.CachingDistributionQueue) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) Configuration(org.osgi.service.cm.Configuration) CachingDistributionQueue(org.apache.sling.distribution.queue.impl.CachingDistributionQueue) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Hashtable(java.util.Hashtable) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) IOException(java.io.IOException)

Aggregations

DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)2 CachingDistributionQueue (org.apache.sling.distribution.queue.impl.CachingDistributionQueue)2 IOException (java.io.IOException)1 Hashtable (java.util.Hashtable)1 Nonnull (javax.annotation.Nonnull)1 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)1 Configuration (org.osgi.service.cm.Configuration)1