camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject [1/2] camel git commit: CAMEL-8826 Added timezone parameter to CronSchedulerRoutePolicy
Date Wed, 03 Jun 2015 15:04:51 GMT
Repository: camel
Updated Branches:
  refs/heads/master 10fd60a8c -> a704d0331


CAMEL-8826 Added  timezone parameter to CronSchedulerRoutePolicy


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a704d033
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a704d033
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a704d033

Branch: refs/heads/master
Commit: a704d0331b99a334bc450590ecc556dbdcf04247
Parents: adfbaf6
Author: Willem Jiang <willem.jiang@gmail.com>
Authored: Wed Jun 3 23:03:39 2015 +0800
Committer: Willem Jiang <willem.jiang@gmail.com>
Committed: Wed Jun 3 23:03:48 2015 +0800

----------------------------------------------------------------------
 .../quartz2/CronScheduledRoutePolicy.java       | 46 ++++++++++++--------
 1 file changed, 28 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a704d033/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/CronScheduledRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/CronScheduledRoutePolicy.java
b/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/CronScheduledRoutePolicy.java
index 2271628..eb7978a 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/CronScheduledRoutePolicy.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/routepolicy/quartz2/CronScheduledRoutePolicy.java
@@ -16,13 +16,13 @@
  */
 package org.apache.camel.routepolicy.quartz2;
 
+import java.util.TimeZone;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.Route;
 import org.apache.camel.component.quartz2.QuartzComponent;
 import org.apache.camel.util.ObjectHelper;
 import org.quartz.CronScheduleBuilder;
-import org.quartz.CronTrigger;
 import org.quartz.Trigger;
 import org.quartz.TriggerBuilder;
 
@@ -31,6 +31,8 @@ public class CronScheduledRoutePolicy extends ScheduledRoutePolicy implements
Sc
     private String routeStopTime;
     private String routeSuspendTime;
     private String routeResumeTime;
+    private String timeZoneString;
+    private TimeZone timeZone;
     
     public void onInit(Route route) {
         try {
@@ -78,28 +80,27 @@ public class CronScheduledRoutePolicy extends ScheduledRoutePolicy implements
Sc
 
     @Override
     protected Trigger createTrigger(Action action, Route route) throws Exception {
-        CronTrigger trigger = null;
-
+        Trigger  trigger = null;
+        
+        CronScheduleBuilder scheduleBuilder = null;
         if (action == Action.START) {
-            trigger = TriggerBuilder.newTrigger()
-                    .withIdentity(TRIGGER_START + route.getId(), TRIGGER_GROUP + route.getId())
-                    .withSchedule(CronScheduleBuilder.cronSchedule(getRouteStartTime()))
-                    .build();
+            scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStartTime());
         } else if (action == Action.STOP) {
-            trigger = TriggerBuilder.newTrigger()
-                    .withIdentity(TRIGGER_STOP + route.getId(), TRIGGER_GROUP + route.getId())
-                    .withSchedule(CronScheduleBuilder.cronSchedule(getRouteStopTime()))
-                    .build();
+            scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteStopTime());
         } else if (action == Action.SUSPEND) {
-            trigger = TriggerBuilder.newTrigger()
-                    .withIdentity(TRIGGER_SUSPEND + route.getId(), TRIGGER_GROUP + route.getId())
-                    .withSchedule(CronScheduleBuilder.cronSchedule(getRouteSuspendTime()))
-                    .build();
+            scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteSuspendTime());
         } else if (action == Action.RESUME) {
+            scheduleBuilder = CronScheduleBuilder.cronSchedule(getRouteResumeTime());
+        }
+        
+        if (scheduleBuilder != null) {
+            if (timeZone != null) {
+                scheduleBuilder.inTimeZone(timeZone);
+            }
             trigger = TriggerBuilder.newTrigger()
-                    .withIdentity(TRIGGER_RESUME + route.getId(), TRIGGER_GROUP + route.getId())
-                    .withSchedule(CronScheduleBuilder.cronSchedule(getRouteResumeTime()))
-                    .build();
+                .withIdentity(TRIGGER_START + route.getId(), TRIGGER_GROUP + route.getId())
+                .withSchedule(scheduleBuilder)
+                .build();
         }
         
         return trigger;
@@ -135,6 +136,15 @@ public class CronScheduledRoutePolicy extends ScheduledRoutePolicy implements
Sc
 
     public String getRouteResumeTime() {
         return routeResumeTime;
+    }
+    
+    public String getTimeZone() {
+        return timeZoneString;
+    }
+
+    public void setTimeZone(String timeZone) {
+        this.timeZoneString = timeZone;
+        this.timeZone = TimeZone.getTimeZone(timeZone);
     }    
 
 }


Mime
View raw message