Search in sources :

Example 1 with ScheduleInfo

use of org.apache.sling.event.jobs.ScheduleInfo 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 ScheduleInfo

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

the class JobSchedulerImpl method execute.

/**
     * @see org.apache.sling.commons.scheduler.Job#execute(org.apache.sling.commons.scheduler.JobContext)
     */
@Override
public void execute(final JobContext context) {
    if (!active.get()) {
        // not active anymore, simply return
        return;
    }
    final ScheduledJobInfoImpl info = (ScheduledJobInfoImpl) context.getConfiguration().get(PROPERTY_READ_JOB);
    if (info.isSuspended()) {
        return;
    }
    this.jobManager.addJob(info.getJobTopic(), info.getJobProperties());
    final int index = (Integer) context.getConfiguration().get(PROPERTY_SCHEDULE_INDEX);
    final Iterator<ScheduleInfo> iter = info.getSchedules().iterator();
    ScheduleInfo si = iter.next();
    for (int i = 0; i < index; i++) {
        si = iter.next();
    }
    // if scheduled once (DATE), remove from schedule
    if (si.getType() == ScheduleType.DATE) {
        if (index == 0 && info.getSchedules().size() == 1) {
            // remove
            this.scheduledJobHandler.remove(info);
        } else {
            // update schedule list
            final List<ScheduleInfo> infos = new ArrayList<>();
            for (final ScheduleInfo i : info.getSchedules()) {
                if (i != si) {
                    // no need to use equals
                    infos.add(i);
                }
            }
            info.update(infos);
            this.scheduledJobHandler.updateSchedule(info.getName(), infos);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo)

Example 3 with ScheduleInfo

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

the class ResourceHelper method cloneValueMap.

public static Map<String, Object> cloneValueMap(final ValueMap vm) throws InstantiationException {
    List<Exception> hasReadError = null;
    try {
        final Map<String, Object> result = new HashMap<>(vm);
        for (final Map.Entry<String, Object> entry : result.entrySet()) {
            if (entry.getKey().equals(PROPERTY_SCHEDULE_INFO)) {
                final String[] infoArray = vm.get(entry.getKey(), String[].class);
                if (infoArray == null || infoArray.length == 0) {
                    if (hasReadError == null) {
                        hasReadError = new ArrayList<>();
                    }
                    hasReadError.add(new Exception("Unable to deserialize property '" + entry.getKey() + "' : " + entry.getValue()));
                } else {
                    final List<ScheduleInfo> infos = new ArrayList<>();
                    for (final String i : infoArray) {
                        final ScheduleInfoImpl info = ScheduleInfoImpl.deserialize(i);
                        if (info != null) {
                            infos.add(info);
                        }
                    }
                    if (infos.size() < infoArray.length) {
                        if (hasReadError == null) {
                            hasReadError = new ArrayList<>();
                        }
                        hasReadError.add(new Exception("Unable to deserialize property '" + entry.getKey() + "' : " + Arrays.toString(infoArray)));
                    } else {
                        entry.setValue(infos);
                    }
                }
            }
            if (entry.getValue() instanceof InputStream) {
                final Object value = vm.get(entry.getKey(), Serializable.class);
                if (value != null) {
                    entry.setValue(value);
                } else {
                    if (hasReadError == null) {
                        hasReadError = new ArrayList<>();
                    }
                    // let's find out which class might be missing
                    ObjectInputStream ois = null;
                    try {
                        ois = new ObjectInputStream((InputStream) entry.getValue());
                        ois.readObject();
                        hasReadError.add(new Exception("Unable to deserialize property '" + entry.getKey() + "'"));
                    } catch (final ClassNotFoundException cnfe) {
                        hasReadError.add(new Exception("Unable to deserialize property '" + entry.getKey() + "'", cnfe));
                    } catch (final IOException ioe) {
                        hasReadError.add(new RuntimeException("Unable to deserialize property '" + entry.getKey() + "'", ioe));
                    } finally {
                        if (ois != null) {
                            try {
                                ois.close();
                            } catch (IOException ignore) {
                            // ignore
                            }
                        }
                    }
                }
            }
        }
        if (hasReadError != null) {
            result.put(PROPERTY_MARKER_READ_ERROR_LIST, hasReadError);
        }
        return result;
    } catch (final IllegalArgumentException iae) {
        // the JCR implementation might throw an IAE if something goes wrong
        throw (InstantiationException) new InstantiationException(iae.getMessage()).initCause(iae);
    }
}
Also used : HashMap(java.util.HashMap) ObjectInputStream(java.io.ObjectInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IOException(java.io.IOException) PersistenceException(org.apache.sling.api.resource.PersistenceException) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo) ValueMap(org.apache.sling.api.resource.ValueMap) HashMap(java.util.HashMap) Map(java.util.Map) ObjectInputStream(java.io.ObjectInputStream)

Example 4 with ScheduleInfo

use of org.apache.sling.event.jobs.ScheduleInfo 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 ScheduleInfo

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

the class JobSchedulerImpl method startScheduledJob.

/**
     * Start a scheduled job
     * @param info The scheduling info
     */
private void startScheduledJob(final ScheduledJobInfoImpl info) {
    if (this.active.get()) {
        if (!info.isSuspended()) {
            this.configuration.getAuditLogger().debug("SCHEDULED OK name={}, topic={}, properties={} : {}", new Object[] { info.getName(), info.getJobTopic(), info.getJobProperties() }, info.getSchedules());
            int index = 0;
            for (final ScheduleInfo si : info.getSchedules()) {
                final String name = info.getSchedulerJobId() + "-" + String.valueOf(index);
                ScheduleOptions options = null;
                switch(si.getType()) {
                    case DAILY:
                    case WEEKLY:
                    case HOURLY:
                    case MONTHLY:
                    case YEARLY:
                    case CRON:
                        options = this.scheduler.EXPR(((ScheduleInfoImpl) si).getCronExpression());
                        break;
                    case DATE:
                        options = this.scheduler.AT(((ScheduleInfoImpl) si).getNextScheduledExecution());
                        break;
                }
                // Create configuration for scheduled job
                final Map<String, Serializable> config = new HashMap<>();
                config.put(PROPERTY_READ_JOB, info);
                config.put(PROPERTY_SCHEDULE_INDEX, index);
                this.scheduler.schedule(this, options.name(name).config(config).canRunConcurrently(false));
                index++;
            }
        } else {
            this.configuration.getAuditLogger().debug("SCHEDULED SUSPENDED name={}, topic={}, properties={} : {}", new Object[] { info.getName(), info.getJobTopic(), info.getJobProperties(), info.getSchedules() });
        }
    }
}
Also used : Serializable(java.io.Serializable) ScheduleOptions(org.apache.sling.commons.scheduler.ScheduleOptions) ScheduleInfoImpl(org.apache.sling.event.impl.support.ScheduleInfoImpl) HashMap(java.util.HashMap) ScheduleInfo(org.apache.sling.event.jobs.ScheduleInfo)

Aggregations

ScheduleInfo (org.apache.sling.event.jobs.ScheduleInfo)6 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 HashMap (java.util.HashMap)2 List (java.util.List)2 PersistenceException (org.apache.sling.api.resource.PersistenceException)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 Queue (org.apache.sling.event.jobs.Queue)2 QueueConfiguration (org.apache.sling.event.jobs.QueueConfiguration)2 ScheduledJobInfo (org.apache.sling.event.jobs.ScheduledJobInfo)2 Statistics (org.apache.sling.event.jobs.Statistics)2 TopicStatistics (org.apache.sling.event.jobs.TopicStatistics)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ObjectInputStream (java.io.ObjectInputStream)1 PrintWriter (java.io.PrintWriter)1 Serializable (java.io.Serializable)1 Calendar (java.util.Calendar)1