Search in sources :

Example 1 with DistributionRequestState

use of org.apache.sling.distribution.DistributionRequestState in project sling by apache.

the class QueueingDistributionPackageProcessor method scheduleImportPackage.

private Collection<SimpleDistributionResponse> scheduleImportPackage(DistributionPackage distributionPackage, String callingUser, String requestId, long startTime) {
    Collection<SimpleDistributionResponse> distributionResponses = new LinkedList<SimpleDistributionResponse>();
    // dispatch the distribution package to one or more queues
    try {
        // add metadata to the package
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_USER, callingUser);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_ID, requestId);
        distributionPackage.getInfo().put(DistributionPackageUtils.PACKAGE_INFO_PROPERTY_REQUEST_START_TIME, startTime);
        // put the package in the queue
        Iterable<DistributionQueueItemStatus> states = scheduleQueueStrategy.add(distributionPackage, queueProvider);
        for (DistributionQueueItemStatus state : states) {
            DistributionRequestState requestState = getRequestStateFromQueueState(state.getItemState());
            distributionResponses.add(new SimpleDistributionResponse(requestState, state.getItemState().toString()));
        }
        distributionEventFactory.generatePackageEvent(DistributionEventTopics.AGENT_PACKAGE_QUEUED, DistributionComponentKind.AGENT, agentName, distributionPackage.getInfo());
    } catch (DistributionException e) {
        log.error("an error happened during dispatching items to the queue(s)", e);
        distributionResponses.add(new SimpleDistributionResponse(DistributionRequestState.DROPPED, e.toString()));
    }
    return distributionResponses;
}
Also used : DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) SimpleDistributionResponse(org.apache.sling.distribution.impl.SimpleDistributionResponse) DistributionRequestState(org.apache.sling.distribution.DistributionRequestState) DistributionException(org.apache.sling.distribution.common.DistributionException) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 DistributionRequestState (org.apache.sling.distribution.DistributionRequestState)1 DistributionException (org.apache.sling.distribution.common.DistributionException)1 SimpleDistributionResponse (org.apache.sling.distribution.impl.SimpleDistributionResponse)1 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)1