Search in sources :

Example 1 with DistributionQueueStatus

use of org.apache.sling.distribution.queue.DistributionQueueStatus in project sling by apache.

the class ExtendedDistributionServiceResourceProvider method getQueueProperties.

private Map<String, Object> getQueueProperties(DistributionAgent agent, SimplePathInfo queueInfo) {
    if (queueInfo.isRoot()) {
        Map<String, Object> result = new HashMap<String, Object>();
        List<String> nameList = new ArrayList<String>();
        for (String name : agent.getQueueNames()) {
            nameList.add(name);
        }
        result.put(ITEMS, nameList.toArray(new String[nameList.size()]));
        result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_LIST_RESOURCE_TYPE);
        return result;
    } else if (queueInfo.isMain()) {
        String queueName = queueInfo.getMainResourceName();
        Map<String, Object> result = new HashMap<String, Object>();
        DistributionQueue queue = agent.getQueue(queueName);
        if (queue != null) {
            DistributionQueueStatus queueStatus = queue.getStatus();
            result.put(SLING_RESOURCE_TYPE, DistributionResourceTypes.AGENT_QUEUE_RESOURCE_TYPE);
            result.put("state", queueStatus.getState().name());
            result.put("empty", queueStatus.isEmpty());
            result.put("itemsCount", queueStatus.getItemsCount());
            if (queueName.startsWith(ErrorQueueDispatchingStrategy.ERROR_PREFIX)) {
                String retryQueue = queueName.replace(ErrorQueueDispatchingStrategy.ERROR_PREFIX, "");
                result.put("retryQueue", retryQueue);
            }
            List<String> nameList = new ArrayList<String>();
            DistributionQueueEntry entry = queue.getHead();
            if (entry != null) {
                nameList.add(entry.getId());
            }
            result.put(ITEMS, nameList.toArray(new String[nameList.size()]));
            result.put(INTERNAL_ITEMS_ITERATOR, new QueueItemsIterator(queue));
            result.put(INTERNAL_ADAPTABLE, queue);
        }
        return result;
    } else if (queueInfo.isChild()) {
        String queueName = queueInfo.getMainResourceName();
        Map<String, Object> result = new HashMap<String, Object>();
        DistributionQueue queue = agent.getQueue(queueName);
        if (queue != null) {
            String itemId = queueInfo.getChildResourceName();
            DistributionQueueEntry entry = queue.getItem(itemId);
            result = getItemProperties(entry);
        }
        return result;
    }
    return null;
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DistributionQueueStatus

use of org.apache.sling.distribution.queue.DistributionQueueStatus in project sling by apache.

the class DistributionQueueMBeanTest method verifyMBeanExposedValuesWhenHeadIsNull.

@Test
public void verifyMBeanExposedValuesWhenHeadIsNull() {
    DistributionQueueStatus status = new DistributionQueueStatus(0, PAUSED);
    DistributionQueue distributionQueue = mock(DistributionQueue.class);
    when(distributionQueue.getName()).thenReturn("#distributionQueue");
    when(distributionQueue.getHead()).thenReturn(null);
    when(distributionQueue.getType()).thenReturn(ORDERED);
    when(distributionQueue.getStatus()).thenReturn(status);
    DistributionQueueMBean mBean = new DistributionQueueMBeanImpl(distributionQueue);
    assertEquals(distributionQueue.getName(), mBean.getName());
    assertEquals(distributionQueue.getType().name().toLowerCase(), mBean.getType());
    assertEquals(0, mBean.getSize());
    assertTrue(mBean.isEmpty());
    assertNull(mBean.getHeadId());
    assertEquals(-1, mBean.getHeadDequeuingAttempts());
    assertNull(mBean.getHeadStatus());
    assertNull(mBean.getHeadEnqueuingDate());
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Test(org.junit.Test)

Example 3 with DistributionQueueStatus

use of org.apache.sling.distribution.queue.DistributionQueueStatus in project sling by apache.

the class DistributionQueueMBeanTest method verifyMBeanExposedValuesWhenHeadIsNotNull.

@Test
public void verifyMBeanExposedValuesWhenHeadIsNotNull() {
    DistributionQueueStatus status = new DistributionQueueStatus(1, RUNNING);
    Calendar joined = Calendar.getInstance();
    DistributionQueueEntry entry = new DistributionQueueEntry("#entry", new DistributionQueueItem("#package", 1000L, new HashMap<String, Object>()), new DistributionQueueItemStatus(joined, QUEUED, 1, "#queue"));
    DistributionQueue distributionQueue = mock(DistributionQueue.class);
    when(distributionQueue.getName()).thenReturn("#distributionQueue");
    when(distributionQueue.getHead()).thenReturn(entry);
    when(distributionQueue.getType()).thenReturn(PARALLEL);
    when(distributionQueue.getStatus()).thenReturn(status);
    DistributionQueueMBean mBean = new DistributionQueueMBeanImpl(distributionQueue);
    assertEquals(distributionQueue.getName(), mBean.getName());
    assertEquals(distributionQueue.getType().name().toLowerCase(), mBean.getType());
    assertEquals(1, mBean.getSize());
    assertFalse(mBean.isEmpty());
    assertEquals("#entry", mBean.getHeadId());
    assertEquals(1, mBean.getHeadDequeuingAttempts());
    assertEquals(QUEUED.name().toLowerCase(), mBean.getHeadStatus());
    assertEquals(joined, mBean.getHeadEnqueuingDate());
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) DistributionQueueEntry(org.apache.sling.distribution.queue.DistributionQueueEntry) HashMap(java.util.HashMap) DistributionQueue(org.apache.sling.distribution.queue.DistributionQueue) Calendar(java.util.Calendar) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Test(org.junit.Test)

Example 4 with DistributionQueueStatus

use of org.apache.sling.distribution.queue.DistributionQueueStatus in project sling by apache.

the class CachingDistributionQueue method getStatus.

@Nonnull
@Override
public DistributionQueueStatus getStatus() {
    DistributionQueueStatus queueStatus = null;
    long now = System.currentTimeMillis();
    Long expiryDate = queueCacheExpiry.get(cacheKey);
    if (expiryDate != null && expiryDate < now) {
        queueCache.remove(cacheKey);
        queueCacheExpiry.remove(cacheKey);
    }
    queueStatus = queueCache.get(cacheKey);
    if (queueStatus != null) {
        return queueStatus;
    }
    queueStatus = wrappedQueue.getStatus();
    queueCache.put(cacheKey, queueStatus);
    queueCacheExpiry.put(cacheKey, System.currentTimeMillis() + EXPIRY_QUEUE_CACHE);
    return queueStatus;
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) Nonnull(javax.annotation.Nonnull)

Example 5 with DistributionQueueStatus

use of org.apache.sling.distribution.queue.DistributionQueueStatus 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);
}
Also used : DistributionQueueStatus(org.apache.sling.distribution.queue.DistributionQueueStatus) DistributionQueueItemStatus(org.apache.sling.distribution.queue.DistributionQueueItemStatus) Job(org.apache.sling.event.jobs.Job) DistributionQueueState(org.apache.sling.distribution.queue.DistributionQueueState) DistributionQueueItem(org.apache.sling.distribution.queue.DistributionQueueItem) Nonnull(javax.annotation.Nonnull)

Aggregations

DistributionQueueStatus (org.apache.sling.distribution.queue.DistributionQueueStatus)6 DistributionQueue (org.apache.sling.distribution.queue.DistributionQueue)4 HashMap (java.util.HashMap)3 DistributionQueueEntry (org.apache.sling.distribution.queue.DistributionQueueEntry)3 DistributionQueueItem (org.apache.sling.distribution.queue.DistributionQueueItem)3 DistributionQueueItemStatus (org.apache.sling.distribution.queue.DistributionQueueItemStatus)3 Test (org.junit.Test)3 Nonnull (javax.annotation.Nonnull)2 ArrayList (java.util.ArrayList)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Map (java.util.Map)1 DistributionPackageInfo (org.apache.sling.distribution.packaging.DistributionPackageInfo)1 SharedDistributionPackage (org.apache.sling.distribution.packaging.impl.SharedDistributionPackage)1 DistributionQueueProvider (org.apache.sling.distribution.queue.DistributionQueueProvider)1 DistributionQueueState (org.apache.sling.distribution.queue.DistributionQueueState)1 Job (org.apache.sling.event.jobs.Job)1