Package org.apache.sling.event.jobs

Examples of org.apache.sling.event.jobs.Job


            jobManager.addJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            cb.block();

            assertEquals(1, jobManager.findJobs(JobManager.QueryType.ALL, TOPIC, -1, (Map<String, Object>[])null).size());
            // job is currently waiting, therefore cancel fails
            final Job e1 = jobManager.getJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            assertNotNull(e1);
            cb2.block(); // and continue job

            sleep(200);

            // the job is now in the queue again
            final Job e2 = jobManager.getJob(TOPIC, Collections.singletonMap("id", (Object)"myid2"));
            assertNotNull(e2);
            assertTrue(jobManager.removeJobById(e2.getId()));
            assertEquals(0, jobManager.findJobs(JobManager.QueryType.ALL, TOPIC, -1, (Map<String, Object>[])null).size());
            final Collection<Job> col = jobManager.findJobs(JobManager.QueryType.HISTORY, TOPIC, -1, (Map<String, Object>[])null);
            try {
                assertEquals(1, col.size());
            } finally {
View Full Code Here


                        return JobResult.OK;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            final Job j = jobManager.addJob(TOPIC, null);
            cb.block();

            assertNotNull(jobManager.getJob(TOPIC, null));

            cb2.block(); // and continue job

            jobManager.removeJobById(j.getId());
        } finally {
            jcReg.unregister();
        }
    }
View Full Code Here

                        return JobResult.FAILED;
                    }
                });
        try {
            final JobManager jobManager = this.getJobManager();
            final Job job = jobManager.addJob(TOPIC, null);

            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();
            // the job is retried after two seconds, so we wait again
            assertTrue("No event received in the given time.", cb.block(5));
            cb.reset();
            // the job is retried after two seconds, so we wait again
            assertTrue("No event received in the given time.", cb.block(5));
            // we have reached the retry so we expect to not get an event
            cb.reset();
            assertFalse("Unexpected event received in the given time.", cb.block(5));
            assertEquals("Unexpected number of retries", 3, retryCountList.size());

            jobManager.removeJobById(job.getId());
        } finally {
            jcReg.unregister();
        }
    }
View Full Code Here

    public boolean add(@Nonnull ReplicationQueueItem item) {
        boolean result = true;
        try {
            Map<String, Object> properties = JobHandlingUtils.createFullProperties(item);

            Job job = jobManager.createJob(topic).properties(properties).add();
            log.info("job {} added", job.getId());
        } catch (Exception e) {
            log.error("could not add an item to the queue", e);
            result = false;
        }
        return result;
View Full Code Here

    public ReplicationQueueItemState getStatus(@Nonnull ReplicationQueueItem replicationPackage)
            throws ReplicationQueueException {
        ReplicationQueueItemState itemStatus = new ReplicationQueueItemState();
        try {
            Map<String, Object> properties = JobHandlingUtils.createIdProperties(replicationPackage.getId());
            Job job = jobManager.getJob(topic, properties);
            if (job != null) {
                itemStatus.setAttempts(job.getRetryCount());
                itemStatus.setItemState(ItemState.valueOf(job.getJobState().toString()));
                itemStatus.setEntered(job.getCreated());
                log.info("status of job {} is {}", job.getId(), job.getJobState());
            } else {
                itemStatus.setItemState(ItemState.DROPPED);
            }
        } catch (Exception e) {
            throw new ReplicationQueueException("unable to retrieve the queue status", e);
View Full Code Here

        }
        return itemStatus;
    }

    public ReplicationQueueItem getHead() {
        Job firstItem = getFirstJob();
        if (firstItem != null) {
            return JobHandlingUtils.getPackage(firstItem);
        } else {
            return null;
        }
View Full Code Here

    private Job getFirstJob() {
        log.info("getting first item in the queue");

        Collection<Job> jobs = getJobs(1);
        if (jobs.size() > 0) {
            Job firstItem = jobs.toArray(new Job[jobs.size()])[0];
            log.info("first item in the queue is {}, retried {} times", firstItem.getId(), firstItem.getRetryCount());
            return firstItem;
        }
        return null;
    }
View Full Code Here

        return null;
    }

    private Job getJob(String itemId) {
        Map<String, Object> properties = JobHandlingUtils.createIdProperties(itemId);
        Job job = jobManager.getJob(topic, properties);

        if (job == null) {
            log.warn("item with id {} cannot be found", itemId);
        }
View Full Code Here

        return items;
    }

    public void remove(@Nonnull String id) {
        Job job = getJob(id);

        if (job != null) {
            boolean removed = jobManager.removeJobById(job.getId());
            log.info("item with id {} removed from the queue: {}", id, removed);
        }
    }
View Full Code Here

    public void testJobWithSuccessfulAgent() throws Exception {
        ReplicationQueueProcessor queueProcessor = mock(ReplicationQueueProcessor.class);
        when(queueProcessor.process(anyString(), any(ReplicationQueueItem.class))).thenReturn(true);

        ReplicationAgentJobConsumer replicationAgentJobConsumer = new ReplicationAgentJobConsumer(queueProcessor);
        Job job = mock(Job.class);
        JobConsumer.JobResult jobResult = replicationAgentJobConsumer.process(job);
        assertEquals(JobConsumer.JobResult.OK, jobResult);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.event.jobs.Job

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.