Search in sources :

Example 1 with ScheduledJobInfo

use of org.apache.sling.event.jobs.ScheduledJobInfo in project sling by apache.

the class WebConsolePlugin method doGet.

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res) throws ServletException, IOException {
    final String msg = req.getParameter("message");
    final PrintWriter pw = res.getWriter();
    pw.println("<form method='POST' name='eventingcmd'>" + "<input type='hidden' name='action' value=''/>" + "<input type='hidden' name='queue' value=''/>" + "</form>");
    pw.println("<script type='text/javascript'>");
    pw.println("function eventingsubmit(action, queue) {" + " document.forms['eventingcmd'].action.value = action;" + " document.forms['eventingcmd'].queue.value = queue;" + " document.forms['eventingcmd'].submit();" + "} </script>");
    pw.printf("<p class='statline ui-state-highlight'>Apache Sling Job Handling%s%n</p>", msg != null ? " : " + ResponseUtil.escapeXml(msg) : "");
    pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
    pw.println("<span style='float: left; margin-left: 1em'>Apache Sling Job Handling: Overall Statistics</span>");
    this.printForm(pw, null, "Reset Stats", "reset");
    pw.println("</div>");
    pw.println("<table class='nicetable'><tbody>");
    String topics = this.jobConsumerManager.getTopics();
    if (topics == null) {
        topics = "";
    } else {
        final String[] allTopics = topics.split(",");
        final StringBuilder sb = new StringBuilder();
        boolean first = true;
        for (final String t : allTopics) {
            if (first) {
                first = false;
            } else {
                sb.append("<br/>");
            }
            sb.append(ResponseUtil.escapeXml(t));
        }
        topics = sb.toString();
    }
    Statistics s = this.jobManager.getStatistics();
    pw.printf("<tr><td>Start Time</td><td>%s</td></tr>", formatDate(s.getStartTime()));
    pw.printf("<tr><td>Local topic consumers: </td><td>%s</td></tr>", topics);
    pw.printf("<tr><td>Last Activated</td><td>%s</td></tr>", formatDate(s.getLastActivatedJobTime()));
    pw.printf("<tr><td>Last Finished</td><td>%s</td></tr>", formatDate(s.getLastFinishedJobTime()));
    pw.printf("<tr><td>Queued Jobs</td><td>%s</td></tr>", s.getNumberOfQueuedJobs());
    pw.printf("<tr><td>Active Jobs</td><td>%s</td></tr>", s.getNumberOfActiveJobs());
    pw.printf("<tr><td>Jobs</td><td>%s</td></tr>", s.getNumberOfJobs());
    pw.printf("<tr><td>Finished Jobs</td><td>%s</td></tr>", s.getNumberOfFinishedJobs());
    pw.printf("<tr><td>Failed Jobs</td><td>%s</td></tr>", s.getNumberOfFailedJobs());
    pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td></tr>", s.getNumberOfCancelledJobs());
    pw.printf("<tr><td>Processed Jobs</td><td>%s</td></tr>", s.getNumberOfProcessedJobs());
    pw.printf("<tr><td>Average Processing Time</td><td>%s</td></tr>", formatTime(s.getAverageProcessingTime()));
    pw.printf("<tr><td>Average Waiting Time</td><td>%s</td></tr>", formatTime(s.getAverageWaitingTime()));
    pw.println("</tbody></table>");
    pw.println("<br/>");
    pw.println("<table class='nicetable'><tbody>");
    pw.println("<tr><th colspan='2'>Topology Capabilities</th></tr>");
    final TopologyCapabilities cap = this.configuration.getTopologyCapabilities();
    if (cap == null) {
        pw.print("<tr><td colspan='2'>No topology information available !</td></tr>");
    } else {
        final Map<String, List<InstanceDescription>> instanceCaps = cap.getInstanceCapabilities();
        for (final Map.Entry<String, List<InstanceDescription>> entry : instanceCaps.entrySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final InstanceDescription id : entry.getValue()) {
                if (sb.length() > 0) {
                    sb.append("<br/>");
                }
                if (id.isLocal()) {
                    sb.append("<b>local</b>");
                } else {
                    sb.append(ResponseUtil.escapeXml(id.getSlingId()));
                }
            }
            pw.printf("<tr><td>%s</td><td>%s</td></tr>", ResponseUtil.escapeXml(entry.getKey()), sb.toString());
        }
    }
    pw.println("</tbody></table>");
    pw.println("<br/>");
    pw.println("<p class='statline'>Scheduled Jobs</p>");
    pw.println("<table class='nicetable'><tbody>");
    final Collection<ScheduledJobInfo> infos = this.jobManager.getScheduledJobs();
    if (infos.size() == 0) {
        pw.print("<tr><td colspan='5'>No jobs currently scheduled.</td></tr>");
    } else {
        pw.println("<tr><th>Schedule</th><th>Job Topic</th><th>Schedules</th></tr>");
        int index = 1;
        for (final ScheduledJobInfo info : infos) {
            pw.printf("<tr><td><b>%s</b></td><td>%s</td><td>", String.valueOf(index), ResponseUtil.escapeXml(info.getJobTopic()));
            boolean first = true;
            for (final ScheduleInfo si : info.getSchedules()) {
                if (!first) {
                    pw.print("<br/>");
                }
                first = false;
                switch(si.getType()) {
                    case YEARLY:
                        pw.printf("YEARLY %s %s : %s:%s", si.getMonthOfYear(), si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case MONTHLY:
                        pw.printf("MONTHLY %s : %s:%s", si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case WEEKLY:
                        pw.printf("WEEKLY %s : %s:%s", si.getDayOfWeek(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case DAILY:
                        pw.printf("DAILY %s:%s", si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case HOURLY:
                        pw.printf("HOURLY %s", si.getMinuteOfHour());
                        break;
                    case CRON:
                        pw.printf("CRON %s", ResponseUtil.escapeXml(si.getExpression()));
                        break;
                    default:
                        pw.printf("AT %s", si.getAt());
                }
            }
            pw.print("</td></tr>");
            index++;
        }
    }
    pw.println("</tbody></table>");
    pw.println("<br/>");
    boolean isEmpty = true;
    for (final Queue q : this.jobManager.getQueues()) {
        isEmpty = false;
        final String queueName = q.getName();
        pw.println("<div class='ui-widget-header ui-corner-top buttonGroup'>");
        pw.printf("<span style='float: left; margin-left: 1em'>Active JobQueue: %s %s</span>", ResponseUtil.escapeXml(queueName), q.isSuspended() ? "(SUSPENDED)" : "");
        this.printForm(pw, queueName, "Reset Stats", "reset");
        if (q.isSuspended()) {
            this.printForm(pw, queueName, "Resume", "resume");
        } else {
            this.printForm(pw, queueName, "Suspend", "suspend");
        }
        this.printForm(pw, queueName, "Test", "test");
        this.printForm(pw, queueName, "Drop All", "dropall");
        pw.println("</div>");
        pw.println("<table class='nicetable'><tbody>");
        s = q.getStatistics();
        final QueueConfiguration c = q.getConfiguration();
        pw.println("<tr><th colspan='2'>Statistics</th><th colspan='2'>Configuration</th></tr>");
        pw.printf("<tr><td>Start Time</td><td>%s</td><td>Type</td><td>%s</td></tr>", formatDate(s.getStartTime()), formatType(c.getType()));
        pw.printf("<tr><td>Last Activated</td><td>%s</td><td>Topics</td><td>%s</td></tr>", formatDate(s.getLastActivatedJobTime()), formatArray(c.getTopics()));
        pw.printf("<tr><td>Last Finished</td><td>%s</td><td>Max Parallel</td><td>%s</td></tr>", formatDate(s.getLastFinishedJobTime()), c.getMaxParallel());
        pw.printf("<tr><td>Queued Jobs</td><td>%s</td><td>Max Retries</td><td>%s</td></tr>", s.getNumberOfQueuedJobs(), c.getMaxRetries());
        pw.printf("<tr><td>Active Jobs</td><td>%s</td><td>Retry Delay</td><td>%s ms</td></tr>", s.getNumberOfActiveJobs(), c.getRetryDelayInMs());
        pw.printf("<tr><td>Jobs</td><td>%s</td><td>Priority</td><td>%s</td></tr>", s.getNumberOfJobs(), c.getThreadPriority());
        pw.printf("<tr><td>Finished Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfFinishedJobs());
        pw.printf("<tr><td>Failed Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfFailedJobs());
        pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfCancelledJobs());
        pw.printf("<tr><td>Processed Jobs</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", s.getNumberOfProcessedJobs());
        pw.printf("<tr><td>Average Processing Time</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageProcessingTime()));
        pw.printf("<tr><td>Average Waiting Time</td><td>%s</td><td colspan='2'>&nbsp</td></tr>", formatTime(s.getAverageWaitingTime()));
        pw.printf("<tr><td>Status Info</td><td colspan='3'>%s</td></tr>", ResponseUtil.escapeXml(q.getStateInfo()));
        pw.println("</tbody></table>");
        pw.println("<br/>");
    }
    if (isEmpty) {
        pw.println("<p>No active queues.</p>");
        pw.println("<br/>");
    }
    for (final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
        pw.println("<table class='nicetable'><tbody>");
        pw.printf("<tr><th colspan='2'>Topic Statistics: %s</th></tr>", ResponseUtil.escapeXml(ts.getTopic()));
        pw.printf("<tr><td>Last Activated</td><td>%s</td></tr>", formatDate(ts.getLastActivatedJobTime()));
        pw.printf("<tr><td>Last Finished</td><td>%s</td></tr>", formatDate(ts.getLastFinishedJobTime()));
        pw.printf("<tr><td>Finished Jobs</td><td>%s</td></tr>", ts.getNumberOfFinishedJobs());
        pw.printf("<tr><td>Failed Jobs</td><td>%s</td></tr>", ts.getNumberOfFailedJobs());
        pw.printf("<tr><td>Cancelled Jobs</td><td>%s</td></tr>", ts.getNumberOfCancelledJobs());
        pw.printf("<tr><td>Processed Jobs</td><td>%s</td></tr>", ts.getNumberOfProcessedJobs());
        pw.printf("<tr><td>Average Processing Time</td><td>%s</td></tr>", formatTime(ts.getAverageProcessingTime()));
        pw.printf("<tr><td>Average Waiting Time</td><td>%s</td></tr>", formatTime(ts.getAverageWaitingTime()));
        pw.println("</tbody></table>");
        pw.println("<br/>");
    }
    pw.println("<p class='statline'>Apache Sling Job Handling - Job Queue Configurations</p>");
    this.printQueueConfiguration(req, pw, this.configuration.getQueueConfigurationManager().getMainQueueConfiguration());
    final InternalQueueConfiguration[] configs = this.configuration.getQueueConfigurationManager().getConfigurations();
    for (final InternalQueueConfiguration c : configs) {
        this.printQueueConfiguration(req, pw, c);
    }
}
Also used : TopologyCapabilities(org.apache.sling.event.impl.jobs.config.TopologyCapabilities) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) Statistics(org.apache.sling.event.jobs.Statistics) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) List(java.util.List) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) Queue(org.apache.sling.event.jobs.Queue) PrintWriter(java.io.PrintWriter)

Example 2 with ScheduledJobInfo

use of org.apache.sling.event.jobs.ScheduledJobInfo in project sling by apache.

the class JobSchedulerImpl method addScheduledJob.

/**
     * Add a scheduled job
     * @param topic The job topic
     * @param properties The job properties
     * @param scheduleName The schedule name
     * @param isSuspended Whether it is suspended
     * @param scheduleInfos The scheduling information
     * @param errors Optional list to contain potential errors
     * @return A new job info or {@code null}
     */
public ScheduledJobInfo addScheduledJob(final String topic, final Map<String, Object> properties, final String scheduleName, final boolean isSuspended, final List<ScheduleInfoImpl> scheduleInfos, final List<String> errors) {
    final List<String> msgs = new ArrayList<>();
    if (scheduleName == null || scheduleName.length() == 0) {
        msgs.add("Schedule name not specified");
    }
    final String errorMessage = Utility.checkJob(topic, properties);
    if (errorMessage != null) {
        msgs.add(errorMessage);
    }
    if (scheduleInfos.size() == 0) {
        msgs.add("No schedule defined for " + scheduleName);
    }
    for (final ScheduleInfoImpl info : scheduleInfos) {
        info.check(msgs);
    }
    if (msgs.size() == 0) {
        try {
            final ScheduledJobInfo info = this.scheduledJobHandler.addOrUpdateJob(topic, properties, scheduleName, isSuspended, scheduleInfos);
            if (info != null) {
                return info;
            }
            msgs.add("Unable to persist scheduled job.");
        } catch (final PersistenceException pe) {
            msgs.add("Unable to persist scheduled job: " + scheduleName);
            logger.warn("Unable to persist scheduled job", pe);
        }
    } else {
        for (final String msg : msgs) {
            logger.warn(msg);
        }
    }
    if (errors != null) {
        errors.addAll(msgs);
    }
    return null;
}
Also used : ScheduleInfoImpl(org.apache.sling.event.impl.support.ScheduleInfoImpl) ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) ArrayList(java.util.ArrayList) PersistenceException(org.apache.sling.api.resource.PersistenceException)

Example 3 with ScheduledJobInfo

use of org.apache.sling.event.jobs.ScheduledJobInfo in project sling by apache.

the class SchedulingTest method testScheduling.

@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testScheduling() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    this.registerJobConsumer(TOPIC, new JobConsumer() {

        @Override
        public JobResult process(final Job job) {
            if (job.getTopic().equals(TOPIC)) {
                counter.incrementAndGet();
            }
            return JobResult.OK;
        }
    });
    // we schedule three jobs
    final ScheduledJobInfo info1 = this.getJobManager().createJob(TOPIC).schedule().hourly(5).add();
    assertNotNull(info1);
    final ScheduledJobInfo info2 = this.getJobManager().createJob(TOPIC).schedule().daily(10, 5).add();
    assertNotNull(info2);
    final ScheduledJobInfo info3 = this.getJobManager().createJob(TOPIC).schedule().weekly(3, 19, 12).add();
    assertNotNull(info3);
    // scheduled jobs
    assertEquals(3, this.getJobManager().getScheduledJobs().size());
    info3.unschedule();
    // scheduled jobs
    assertEquals(2, this.getJobManager().getScheduledJobs().size());
    info1.unschedule();
    // scheduled jobs
    assertEquals(1, this.getJobManager().getScheduledJobs().size());
    info2.unschedule();
    // scheduled jobs
    assertEquals(0, this.getJobManager().getScheduledJobs().size());
}
Also used : ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobConsumer(org.apache.sling.event.jobs.consumer.JobConsumer) Job(org.apache.sling.event.jobs.Job) Test(org.junit.Test)

Example 4 with ScheduledJobInfo

use of org.apache.sling.event.jobs.ScheduledJobInfo in project sling by apache.

the class InventoryPlugin method printText.

private void printText(final PrintWriter pw) {
    pw.println("Apache Sling Job Handling");
    pw.println("-------------------------");
    String topics = this.jobConsumerManager.getTopics();
    if (topics == null) {
        topics = "";
    }
    Statistics s = this.jobManager.getStatistics();
    pw.println("Overall Statistics");
    pw.printf("Start Time : %s%n", formatDate(s.getStartTime()));
    pw.printf("Local topic consumers: %s%n", topics);
    pw.printf("Last Activated : %s%n", formatDate(s.getLastActivatedJobTime()));
    pw.printf("Last Finished : %s%n", formatDate(s.getLastFinishedJobTime()));
    pw.printf("Queued Jobs : %s%n", s.getNumberOfQueuedJobs());
    pw.printf("Active Jobs : %s%n", s.getNumberOfActiveJobs());
    pw.printf("Jobs : %s%n", s.getNumberOfJobs());
    pw.printf("Finished Jobs : %s%n", s.getNumberOfFinishedJobs());
    pw.printf("Failed Jobs : %s%n", s.getNumberOfFailedJobs());
    pw.printf("Cancelled Jobs : %s%n", s.getNumberOfCancelledJobs());
    pw.printf("Processed Jobs : %s%n", s.getNumberOfProcessedJobs());
    pw.printf("Average Processing Time : %s%n", formatTime(s.getAverageProcessingTime()));
    pw.printf("Average Waiting Time : %s%n", formatTime(s.getAverageWaitingTime()));
    pw.println();
    pw.println("Topology Capabilities");
    final TopologyCapabilities cap = this.configuration.getTopologyCapabilities();
    if (cap == null) {
        pw.print("No topology information available !");
    } else {
        final Map<String, List<InstanceDescription>> instanceCaps = cap.getInstanceCapabilities();
        for (final Map.Entry<String, List<InstanceDescription>> entry : instanceCaps.entrySet()) {
            final StringBuilder sb = new StringBuilder();
            for (final InstanceDescription id : entry.getValue()) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                if (id.isLocal()) {
                    sb.append("local");
                } else {
                    sb.append(id.getSlingId());
                }
            }
            pw.printf("%s : %s%n", entry.getKey(), sb.toString());
        }
    }
    pw.println();
    pw.println("Scheduled Jobs");
    final Collection<ScheduledJobInfo> infos = this.jobManager.getScheduledJobs();
    if (infos.size() == 0) {
        pw.print("No jobs currently scheduled");
    } else {
        for (final ScheduledJobInfo info : infos) {
            pw.println("Schedule");
            pw.printf("Job Topic< : %s%n", info.getJobTopic());
            pw.print("Schedules : ");
            boolean first = true;
            for (final ScheduleInfo si : info.getSchedules()) {
                if (!first) {
                    pw.print(", ");
                }
                first = false;
                switch(si.getType()) {
                    case YEARLY:
                        pw.printf("YEARLY %s %s : %s:%s", si.getMonthOfYear(), si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case MONTHLY:
                        pw.printf("MONTHLY %s : %s:%s", si.getDayOfMonth(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case WEEKLY:
                        pw.printf("WEEKLY %s : %s:%s", si.getDayOfWeek(), si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case DAILY:
                        pw.printf("DAILY %s:%s", si.getHourOfDay(), si.getMinuteOfHour());
                        break;
                    case HOURLY:
                        pw.printf("HOURLY %s", si.getMinuteOfHour());
                        break;
                    case CRON:
                        pw.printf("CRON %s", si.getExpression());
                        break;
                    default:
                        pw.printf("AT %s", si.getAt());
                }
            }
            pw.println();
            pw.println();
        }
    }
    pw.println();
    boolean isEmpty = true;
    for (final Queue q : this.jobManager.getQueues()) {
        isEmpty = false;
        pw.printf("Active JobQueue: %s %s%n", q.getName(), q.isSuspended() ? "(SUSPENDED)" : "");
        s = q.getStatistics();
        final QueueConfiguration c = q.getConfiguration();
        pw.println("Statistics");
        pw.printf("Start Time : %s%n", formatDate(s.getStartTime()));
        pw.printf("Last Activated : %s%n", formatDate(s.getLastActivatedJobTime()));
        pw.printf("Last Finished : %s%n", formatDate(s.getLastFinishedJobTime()));
        pw.printf("Queued Jobs : %s%n", s.getNumberOfQueuedJobs());
        pw.printf("Active Jobs : %s%n", s.getNumberOfActiveJobs());
        pw.printf("Jobs : %s%n", s.getNumberOfJobs());
        pw.printf("Finished Jobs : %s%n", s.getNumberOfFinishedJobs());
        pw.printf("Failed Jobs : %s%n", s.getNumberOfFailedJobs());
        pw.printf("Cancelled Jobs : %s%n", s.getNumberOfCancelledJobs());
        pw.printf("Processed Jobs : %s%n", s.getNumberOfProcessedJobs());
        pw.printf("Average Processing Time : %s%n", formatTime(s.getAverageProcessingTime()));
        pw.printf("Average Waiting Time : %s%n", formatTime(s.getAverageWaitingTime()));
        pw.printf("Status Info : %s%n", q.getStateInfo());
        pw.println("Configuration");
        pw.printf("Type : %s%n", formatType(c.getType()));
        pw.printf("Topics : %s%n", formatArrayAsText(c.getTopics()));
        pw.printf("Max Parallel : %s%n", c.getMaxParallel());
        pw.printf("Max Retries : %s%n", c.getMaxRetries());
        pw.printf("Retry Delay : %s ms%n", c.getRetryDelayInMs());
        pw.printf("Priority : %s%n", c.getThreadPriority());
        pw.println();
    }
    if (isEmpty) {
        pw.println("No active queues.");
        pw.println();
    }
    for (final TopicStatistics ts : this.jobManager.getTopicStatistics()) {
        pw.printf("Topic Statistics - %s%n", ts.getTopic());
        pw.printf("Last Activated : %s%n", formatDate(ts.getLastActivatedJobTime()));
        pw.printf("Last Finished : %s%n", formatDate(ts.getLastFinishedJobTime()));
        pw.printf("Finished Jobs : %s%n", ts.getNumberOfFinishedJobs());
        pw.printf("Failed Jobs : %s%n", ts.getNumberOfFailedJobs());
        pw.printf("Cancelled Jobs : %s%n", ts.getNumberOfCancelledJobs());
        pw.printf("Processed Jobs : %s%n", ts.getNumberOfProcessedJobs());
        pw.printf("Average Processing Time : %s%n", formatTime(ts.getAverageProcessingTime()));
        pw.printf("Average Waiting Time : %s%n", formatTime(ts.getAverageWaitingTime()));
        pw.println();
    }
    pw.println("Apache Sling Job Handling - Job Queue Configurations");
    pw.println("----------------------------------------------------");
    this.printQueueConfiguration(pw, this.configuration.getQueueConfigurationManager().getMainQueueConfiguration());
    final InternalQueueConfiguration[] configs = this.configuration.getQueueConfigurationManager().getConfigurations();
    for (final InternalQueueConfiguration c : configs) {
        this.printQueueConfiguration(pw, c);
    }
}
Also used : TopologyCapabilities(org.apache.sling.event.impl.jobs.config.TopologyCapabilities) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) Statistics(org.apache.sling.event.jobs.Statistics) TopicStatistics(org.apache.sling.event.jobs.TopicStatistics) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) QueueConfiguration(org.apache.sling.event.jobs.QueueConfiguration) InternalQueueConfiguration(org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration) ArrayList(java.util.ArrayList) List(java.util.List) InstanceDescription(org.apache.sling.discovery.InstanceDescription) Map(java.util.Map) Queue(org.apache.sling.event.jobs.Queue)

Example 5 with ScheduledJobInfo

use of org.apache.sling.event.jobs.ScheduledJobInfo in project sling by apache.

the class TimedJobsTest method testTimedJob.

@Test(timeout = DEFAULT_TEST_TIMEOUT)
public void testTimedJob() throws Exception {
    final AtomicInteger counter = new AtomicInteger();
    this.registerJobConsumer(TOPIC, new JobConsumer() {

        @Override
        public JobResult process(final Job job) {
            if (job.getTopic().equals(TOPIC)) {
                counter.incrementAndGet();
            }
            return JobResult.OK;
        }
    });
    final Date d = new Date();
    // run in 3 seconds
    d.setTime(System.currentTimeMillis() + 3000);
    // create scheduled job
    final ScheduledJobInfo info = this.getJobManager().createJob(TOPIC).schedule().at(d).add();
    assertNotNull(info);
    while (counter.get() == 0) {
        this.sleep(1000);
    }
    // job is not scheduled anymore
    assertEquals(0, this.getJobManager().getScheduledJobs().size());
    info.unschedule();
}
Also used : ScheduledJobInfo(org.apache.sling.event.jobs.ScheduledJobInfo) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) JobConsumer(org.apache.sling.event.jobs.consumer.JobConsumer) Job(org.apache.sling.event.jobs.Job) Date(java.util.Date) Test(org.junit.Test)

Aggregations

ScheduledJobInfo (org.apache.sling.event.jobs.ScheduledJobInfo)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 InstanceDescription (org.apache.sling.discovery.InstanceDescription)2 InternalQueueConfiguration (org.apache.sling.event.impl.jobs.config.InternalQueueConfiguration)2 TopologyCapabilities (org.apache.sling.event.impl.jobs.config.TopologyCapabilities)2 Job (org.apache.sling.event.jobs.Job)2 Queue (org.apache.sling.event.jobs.Queue)2 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)2 ScheduleInfo (org.apache.sling.event.jobs.ScheduleInfo)2 Statistics (org.apache.sling.event.jobs.Statistics)2 TopicStatistics (org.apache.sling.event.jobs.TopicStatistics)2 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)2 Test (org.junit.Test)2 PrintWriter (java.io.PrintWriter)1 Date (java.util.Date)1 PersistenceException (org.apache.sling.api.resource.PersistenceException)1 ScheduleInfoImpl (org.apache.sling.event.impl.support.ScheduleInfoImpl)1