use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class AsyncDeliveryDispatchingStrategy method add.
@Override
public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
if (!(distributionPackage instanceof SharedDistributionPackage) && deliveryMappings.size() > 1) {
throw new DistributionException("distribution package must be a shared package to be added in multiple queues");
}
String distributionPackageId = distributionPackage.getId();
List<DistributionQueueItemStatus> result = new LinkedList<DistributionQueueItemStatus>();
for (String referenceQueueName : deliveryMappings.keySet()) {
DistributionQueue queue = queueProvider.getQueue(referenceQueueName);
int MAX_QUEUE_ITEMS_THRESHOLD = 100;
if (queue.getStatus().getItemsCount() > MAX_QUEUE_ITEMS_THRESHOLD) {
// too many items in the queue, let's send actual packages and references separately
distributionPackage.getInfo().put("reference-required", true);
DistributionQueueItem item = getItem(distributionPackage);
// create and acquire reference package
ReferencePackage referencePackage = new ReferencePackage(distributionPackage);
DistributionPackageUtils.acquire(referencePackage, referenceQueueName);
// acquire actual package
String deliveryQueueName = deliveryMappings.get(referenceQueueName);
DistributionPackageUtils.acquire(distributionPackage, deliveryQueueName);
// add the actual package to the delivery queue
DistributionQueue deliveryQueue = queueProvider.getQueue(deliveryQueueName);
DistributionQueueEntry deliveryQueueEntry = deliveryQueue.add(item);
if (deliveryQueueEntry != null) {
DistributionQueueItemStatus status = deliveryQueueEntry.getStatus();
log.debug("item {} added to delivery queue: {}", item, status);
result.add(status);
} else {
DistributionPackageUtils.release(distributionPackage, deliveryQueueName);
log.error("cannot add package {} to delivery queue {}", distributionPackageId, deliveryQueueName);
result.add(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, deliveryQueue.getName()));
}
// add the reference package to the reference queue
DistributionQueue referenceQueue = queueProvider.getQueue(referenceQueueName);
DistributionQueueItem referenceQueueItem = getItem(referencePackage);
DistributionQueueEntry referenceQueueEntry = referenceQueue.add(referenceQueueItem);
if (referenceQueueEntry != null) {
DistributionQueueItemStatus status = referenceQueueEntry.getStatus();
log.debug("item {} added to reference queue: {}", referenceQueueItem, status);
} else {
DistributionPackageUtils.release(referencePackage, referenceQueueName);
log.error("cannot add package {} to reference queue {}", distributionPackageId, referenceQueueName);
result.add(new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, referenceQueue.getName()));
}
} else {
// normal queueing
DistributionQueueItem item = getItem(distributionPackage);
DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, queue.getName());
DistributionPackageUtils.acquire(distributionPackage, referenceQueueName);
DistributionQueueEntry queueEntry = queue.add(item);
if (queueEntry != null) {
status = queueEntry.getStatus();
log.debug("item {} added to queue: {}", item, status);
} else {
DistributionPackageUtils.release(distributionPackage, referenceQueueName);
log.error("cannot add package {} to queue {}", distributionPackageId, referenceQueueName);
}
result.add(status);
}
}
return result;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class ErrorQueueDispatchingStrategy method add.
@Override
public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
List<DistributionQueueItemStatus> result = new ArrayList<DistributionQueueItemStatus>();
String originQueue = DistributionPackageUtils.getQueueName(distributionPackage.getInfo());
if (!queueNames.contains(originQueue)) {
return result;
}
String errorQueueName = ERROR_PREFIX + originQueue;
DistributionQueue errorQueue = queueProvider.getQueue(errorQueueName);
DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, errorQueueName);
DistributionQueueItem queueItem = DistributionPackageUtils.toQueueItem(distributionPackage);
DistributionPackageUtils.acquire(distributionPackage, errorQueueName);
DistributionQueueEntry queueEntry = errorQueue.add(queueItem);
if (queueEntry != null) {
status = queueEntry.getStatus();
} else {
DistributionPackageUtils.releaseOrDelete(distributionPackage, errorQueueName);
log.error("cannot add package {} to queue {}", distributionPackage.getId(), errorQueueName);
}
result.add(status);
return result;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class MultipleQueueDispatchingStrategy method add.
public Iterable<DistributionQueueItemStatus> add(@Nonnull DistributionPackage distributionPackage, @Nonnull DistributionQueueProvider queueProvider) throws DistributionException {
if (!(distributionPackage instanceof SharedDistributionPackage) && queueNames.length > 1) {
throw new DistributionException("distribution package must be a shared package to be added in multiple queues");
}
DistributionQueueItem queueItem = getItem(distributionPackage);
List<DistributionQueueItemStatus> result = new ArrayList<DistributionQueueItemStatus>();
// first acquire the package for all queues
DistributionPackageUtils.acquire(distributionPackage, queueNames);
// second add the package to all queues
for (String queueName : queueNames) {
DistributionQueue queue = queueProvider.getQueue(queueName);
DistributionQueueItemStatus status = new DistributionQueueItemStatus(DistributionQueueItemState.ERROR, queue.getName());
DistributionQueueEntry queueEntry = queue.add(queueItem);
if (queueEntry != null) {
status = queueEntry.getStatus();
} else {
DistributionPackageUtils.release(distributionPackage, queueName);
log.error("cannot add package {} to queue {}", distributionPackage.getId(), queueName);
}
result.add(status);
}
return result;
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class JobHandlingDistributionQueue method getStatus.
@Override
@Nonnull
public DistributionQueueStatus getStatus() {
List<Job> jobs = getJobs(0, -1);
Job firstJob = jobs.size() > 0 ? jobs.get(0) : null;
DistributionQueueItem firstItem = firstJob != null ? JobHandlingUtils.getItem(firstJob) : null;
DistributionQueueItemStatus firstItemStatus = firstJob != null ? JobHandlingUtils.getStatus(firstJob) : null;
DistributionQueueState state = DistributionQueueUtils.calculateState(firstItem, firstItemStatus);
if (!isActive) {
state = DistributionQueueState.PASSIVE;
}
int itemsCount = jobs.size();
return new DistributionQueueStatus(itemsCount, state);
}
use of org.apache.sling.distribution.queue.DistributionQueueItemStatus in project sling by apache.
the class ExtendedDistributionServiceResourceProvider method getItemProperties.
private Map<String, Object> getItemProperties(DistributionQueueEntry entry) {
Map<String, Object> result = new HashMap<String, Object>();
if (entry != null) {
result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_ITEM_RESOURCE_TYPE);
DistributionQueueItem item = entry.getItem();
DistributionPackageInfo packageInfo = DistributionPackageUtils.fromQueueItem(item);
result.put("id", entry.getId());
result.put("size", item.getSize());
result.put("paths", packageInfo.getPaths());
result.put("action", packageInfo.getRequestType());
result.put("userid", packageInfo.get(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_USER, String.class));
DistributionQueueItemStatus status = entry.getStatus();
result.put("attempts", status.getAttempts());
result.put("time", status.getEntered().getTime());
result.put("state", status.getItemState().name());
}
return result;
}
Aggregations