Package org.apache.sling.replication.queue

Examples of org.apache.sling.replication.queue.ReplicationQueueItem


        List<ReplicationPackage> result = new ArrayList<ReplicationPackage>();
        try {
            log.info("getting item from queue {}", queueName);

            ReplicationQueue queue = agent.getQueue(queueName);
            ReplicationQueueItem info = queue.getHead();
            ReplicationPackage replicationPackage;
            if (info != null) {
                replicationPackage = packageBuilder.getPackage(resourceResolver, info.getId());
                queue.remove(info.getId());
                if (replicationPackage != null) {
                    result.add(replicationPackage);
                }
            }
View Full Code Here


    public static ReplicationQueueItem getPackage(final Job job) {
        ReplicationPackageInfo packageInfo = new SimpleReplicationPackageInfo();
        packageInfo.setOrigin((String) job.getProperty(ORIGIN));

        return new ReplicationQueueItem((String) job.getProperty(ID),
                (String[]) job.getProperty(PATHS),
                String.valueOf(job.getProperty(ACTION)),
                String.valueOf(job.getProperty(TYPE)), packageInfo);
    }
View Full Code Here

    }

    public JobResult process(Job job) {
        log.debug("processing job {}", job.getId());
        String queueName = JobHandlingUtils.getQueueName(job);
        ReplicationQueueItem info = JobHandlingUtils.getPackage(job);
        log.info("processing item {} in queue {}", info.getId(), queueName);
        boolean processingResult = queueProcessor.process(queueName, info);
        JobResult jobResult = processingResult ? JobResult.OK : JobResult.FAILED;
        log.info("item {} processed {} with result {}", new Object[]{info.getId(), jobResult, jobResult});
        return jobResult;
    }
View Full Code Here

        }
        return status;
    }

    public ReplicationQueueItem getHead() {
        ReplicationQueueItem element = queue.peek();
        if (element != null) {
            ReplicationQueueItemState replicationQueueItemStatus = statusMap.get(element);
            replicationQueueItemStatus.setAttempts(replicationQueueItemStatus.getAttempts() + 1);
        }
        return element;
View Full Code Here

        }
        return element;
    }

    public void removeHead() {
        ReplicationQueueItem element = queue.remove();
        statusMap.get(element).setSuccessful(true);
    }
View Full Code Here

    public Collection<ReplicationQueueItem> getItems() {
        return queue;
    }

    public void remove(@Nonnull String id) {
        ReplicationQueueItem toRemove = null;
        for (ReplicationQueueItem item : queue) {
            if (id.equals(item.getId())) {
                toRemove = item;
            }
        }
View Full Code Here

    public void run() {
        try {
            for (ReplicationQueue queue : queueProvider.getAllQueues()) {
                while (!queue.isEmpty()) {
                    // synchronized (queue) {
                    ReplicationQueueItem item = queue.getHead();
                    if (item != null) {
                        if (queueProcessor.process(queue.getName(), item)) {
                            queue.remove(item.getId());
                        } else {
                            log.warn("processing of item {} failed",
                                    Arrays.toString(item.getPaths()));

                        }
                    }
                    // }
                }
View Full Code Here

    public void testRunWithOneNonEmptyQueue() throws Exception {
        ReplicationQueueProvider queueProvider = mock(ReplicationQueueProvider.class);
        Collection<ReplicationQueue> queues = new LinkedList<ReplicationQueue>();
        ReplicationQueue queue = mock(ReplicationQueue.class);
        when(queue.isEmpty()).thenReturn(false).thenReturn(true);
        ReplicationQueueItem item = mock(ReplicationQueueItem.class);
        when(queue.getHead()).thenReturn(item);

        queues.add(queue);
        when(queueProvider.getAllQueues()).thenReturn(queues);
        ReplicationQueueProcessor queueProcessor = mock(ReplicationQueueProcessor.class);
View Full Code Here

public class SimpleReplicationQueueTest {

    @Test
    public void testPackageAddition() throws Exception {
        ReplicationQueue queue = new SimpleReplicationQueue("agentName", "default");
        ReplicationQueueItem pkg = mock(ReplicationQueueItem.class);
        assertTrue(queue.add(pkg));
        assertFalse(queue.isEmpty());
    }
View Full Code Here

    }

    @Test
    public void testPackageAdditionAndRemoval() throws Exception {
        ReplicationQueue queue = new SimpleReplicationQueue("agentName", "default");
        ReplicationQueueItem pkg = mock(ReplicationQueueItem.class);
        when(pkg.getId()).thenReturn("id");
        assertTrue(queue.add(pkg));
        assertFalse(queue.isEmpty());
        queue.remove(pkg.getId());
        assertTrue(queue.isEmpty());
        ReplicationQueueItemState status = queue.getStatus(pkg);
        assertNotNull(status);
        assertTrue(status.isSuccessful());
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.replication.queue.ReplicationQueueItem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.