karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject [karaf] branch karaf-4.1.x updated: Fix karaf scheduler interface abstraction leak on exceptions
Date Wed, 22 Nov 2017 15:00:50 GMT
This is an automated email from the ASF dual-hosted git repository.

jbonofre pushed a commit to branch karaf-4.1.x
in repository https://gitbox.apache.org/repos/asf/karaf.git


The following commit(s) were added to refs/heads/karaf-4.1.x by this push:
     new af03285  Fix karaf scheduler interface abstraction leak on exceptions
af03285 is described below

commit af032857a7c7ea787a74453461406000fda478d3
Author: Ciprian Ciubotariu <cheepeero@gmx.net>
AuthorDate: Thu Jul 27 20:13:32 2017 +0300

    Fix karaf scheduler interface abstraction leak on exceptions
    
    Wrap quartz SchedulerException in SchedulerError instead of using the
    private exception class in the scheduler API.
---
 .../java/org/apache/karaf/scheduler/Scheduler.java |  8 ++---
 .../org/apache/karaf/scheduler/SchedulerError.java | 35 ++++++++++++++++++++++
 .../karaf/scheduler/core/QuartzScheduler.java      | 35 ++++++++++++++--------
 3 files changed, 60 insertions(+), 18 deletions(-)

diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/Scheduler.java b/scheduler/src/main/java/org/apache/karaf/scheduler/Scheduler.java
index 90bd766..dda0b0e 100644
--- a/scheduler/src/main/java/org/apache/karaf/scheduler/Scheduler.java
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/Scheduler.java
@@ -20,8 +20,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
-import org.quartz.SchedulerException;
-
 /**
  * A scheduler to schedule time/cron based jobs.
  * A job is an object that is executed/fired by the scheduler. The object
@@ -74,7 +72,7 @@ public interface Scheduler {
      *
      * @param job The job to execute (either {@link Job} or {@link Runnable}).
      * @param options Required options defining how to schedule the job.
-     * @throws SchedulerException if the job can't be scheduled.
+     * @throws SchedulerError if the job can't be scheduled.
      * @throws IllegalArgumentException If the preconditions are not met.
      * @see #NOW()
      * @see #NOW(int, long)
@@ -82,7 +80,7 @@ public interface Scheduler {
      * @see #AT(Date, int, long)
      * @see #EXPR(String)
      */
-    void schedule(Object job, ScheduleOptions options) throws IllegalArgumentException, SchedulerException;
+    void schedule(Object job, ScheduleOptions options) throws IllegalArgumentException, SchedulerError;
 
     /**
      * Remove a scheduled job by name.
@@ -92,7 +90,7 @@ public interface Scheduler {
      */
     boolean unschedule(String jobName);
 
-    Map<Object, ScheduleOptions> getJobs() throws SchedulerException;
+    Map<Object, ScheduleOptions> getJobs() throws SchedulerError;
 
     /**
      * Create a schedule options to fire a job immediately and only once.
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerError.java b/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerError.java
new file mode 100644
index 0000000..49705c1
--- /dev/null
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/SchedulerError.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2017 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.scheduler;
+
+public class SchedulerError extends Exception {
+
+    public SchedulerError() {
+    }
+
+    public SchedulerError(String msg) {
+        super(msg);
+    }
+
+    public SchedulerError(Throwable cause) {
+        super(cause);
+    }
+
+    public SchedulerError(String msg, Throwable cause) {
+        super(msg, cause);
+    }
+
+}
diff --git a/scheduler/src/main/java/org/apache/karaf/scheduler/core/QuartzScheduler.java
b/scheduler/src/main/java/org/apache/karaf/scheduler/core/QuartzScheduler.java
index 6b7309e..f02fcfc 100644
--- a/scheduler/src/main/java/org/apache/karaf/scheduler/core/QuartzScheduler.java
+++ b/scheduler/src/main/java/org/apache/karaf/scheduler/core/QuartzScheduler.java
@@ -25,6 +25,7 @@ import java.util.UUID;
 import org.apache.karaf.scheduler.Job;
 import org.apache.karaf.scheduler.ScheduleOptions;
 import org.apache.karaf.scheduler.Scheduler;
+import org.apache.karaf.scheduler.SchedulerError;
 import org.quartz.JobBuilder;
 import org.quartz.JobDataMap;
 import org.quartz.JobDetail;
@@ -205,7 +206,7 @@ public class QuartzScheduler implements Scheduler {
      * @throws SchedulerException if the job can't be scheduled
      * @throws IllegalArgumentException If the preconditions are not met
      */
-    public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException,
SchedulerException {
+    public void schedule(final Object job, final ScheduleOptions options) throws IllegalArgumentException,
SchedulerError {
         this.checkJob(job);
 
         if ( !(options instanceof InternalScheduleOptions)) {
@@ -251,7 +252,11 @@ public class QuartzScheduler implements Scheduler {
         final JobDetail detail = this.createJobDetail(name, jobDataMap, opts.canRunConcurrently);
 
         this.logger.debug("Scheduling job {} with name {} and trigger {}", job, name, trigger);
-        s.scheduleJob(detail, trigger);
+        try {
+            s.scheduleJob(detail, trigger);
+        } catch (SchedulerException ex) {
+            throw new SchedulerError(ex);
+        }
     }
 
     /**
@@ -276,20 +281,24 @@ public class QuartzScheduler implements Scheduler {
     }
 
     @Override
-    public Map<Object, ScheduleOptions> getJobs() throws SchedulerException {
-        Map<Object, ScheduleOptions> jobs = new HashMap<>();
-        org.quartz.Scheduler s = this.scheduler;
-        if (s != null) {
-            for (String group : s.getJobGroupNames()) {
-                for (JobKey key : s.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
-                    JobDetail detail = s.getJobDetail(key);
-                    ScheduleOptions options = (ScheduleOptions) detail.getJobDataMap().get(DATA_MAP_OPTIONS);
-                    Object job = detail.getJobDataMap().get(DATA_MAP_OBJECT);
-                    jobs.put(job, options);
+    public Map<Object, ScheduleOptions> getJobs() throws SchedulerError {
+        try {
+            Map<Object, ScheduleOptions> jobs = new HashMap<>();
+            org.quartz.Scheduler s = this.scheduler;
+            if (s != null) {
+                for (String group : s.getJobGroupNames()) {
+                    for (JobKey key : s.getJobKeys(GroupMatcher.jobGroupEquals(group))) {
+                        JobDetail detail = s.getJobDetail(key);
+                        ScheduleOptions options = (ScheduleOptions) detail.getJobDataMap().get(DATA_MAP_OPTIONS);
+                        Object job = detail.getJobDataMap().get(DATA_MAP_OBJECT);
+                        jobs.put(job, options);
+                    }
                 }
             }
+            return jobs;
+        } catch (SchedulerException ex) {
+            throw new SchedulerError(ex);
         }
-        return jobs;
     }
 
 }

-- 
To stop receiving notification emails like this one, please contact
['"commits@karaf.apache.org" <commits@karaf.apache.org>'].

Mime
View raw message