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;
}
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());
}
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());
}
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;
}
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);
}
Aggregations