You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2014/08/07 10:01:21 UTC

git commit: [KARAF-2996] Improve shutdown sleep time management

Repository: karaf
Updated Branches:
  refs/heads/master 130609b06 -> ec3344c4c


[KARAF-2996] Improve shutdown sleep time management


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

Branch: refs/heads/master
Commit: ec3344c4c87d7b64a3750ac8019e2439d4341028
Parents: 130609b
Author: Jean-Baptiste Onofré <jb...@apache.org>
Authored: Thu Aug 7 09:59:54 2014 +0200
Committer: Jean-Baptiste Onofré <jb...@apache.org>
Committed: Thu Aug 7 09:59:54 2014 +0200

----------------------------------------------------------------------
 .../src/main/webapp/users-guide/start-stop.conf |  4 +--
 .../apache/karaf/system/commands/Shutdown.java  |  5 ++--
 .../system/internal/SystemServiceImpl.java      | 31 +++++++++++++-------
 3 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/ec3344c4/manual/src/main/webapp/users-guide/start-stop.conf
----------------------------------------------------------------------
diff --git a/manual/src/main/webapp/users-guide/start-stop.conf b/manual/src/main/webapp/users-guide/start-stop.conf
index 15fdb82..f40b0da 100644
--- a/manual/src/main/webapp/users-guide/start-stop.conf
+++ b/manual/src/main/webapp/users-guide/start-stop.conf
@@ -313,7 +313,7 @@ You can also use directly {{halt}} which is an alias to {{shutdown -f -h}}.
 The {{shutdown}} command accepts a time argument. With this argument, you can define when you want to shutdown the Apache Karaf container.
 
 The time argument can have different formats. First, it can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm is the minute of the hour
-(in two digits). Second, it can be in the format +m, in which m is the number of minutes to wait. The word {{now}} is an alias for +0.
+(in two digits). Second, it can be in the format m (or +m), in which m is the number of minutes to wait. The word {{now}} is an alias for 0.
 
 For instance, the following command will shutdown Apache Karaf at 10:35am:
 
@@ -324,7 +324,7 @@ karaf@root()> system:shutdown 10:35
 Another example to shutdown Apache Karaf in 10 minutes:
 
 {code}
-karaf@root()> system:shutdown +10
+karaf@root()> system:shutdown 10
 {code}
 
 Like for other commands, you can find details on the {{shutdown}} command man page:

http://git-wip-us.apache.org/repos/asf/karaf/blob/ec3344c4/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java
----------------------------------------------------------------------
diff --git a/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java b/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java
index b8b4b41..8d79379 100644
--- a/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java
+++ b/system/src/main/java/org/apache/karaf/system/commands/Shutdown.java
@@ -47,11 +47,10 @@ public class Shutdown implements Action {
     @Option(name = "-cc", aliases = {"--clean-cache", "-cc"}, description = "Force a clean restart by deleting the cache directory")
     private boolean cleanCache;
 
-
     @Argument(name = "time", index = 0, description = "Shutdown after a specified delay. The time argument can have different" +
             " formats. First, it can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits) and mm" +
-            " is the minute of the hour (in two digits). Second, it can be in the format +m, in which m is the number of minutes" +
-            " to wait. The word now is an alias for +0.", required = false, multiValued = false)
+            " is the minute of the hour (in two digits). Second, it can be in the format m (or +m), in which m is the number of minutes" +
+            " to wait. The word now is an alias for 0 (or +0).", required = false, multiValued = false)
     String time;
 
     @Reference

http://git-wip-us.apache.org/repos/asf/karaf/blob/ec3344c4/system/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
----------------------------------------------------------------------
diff --git a/system/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java b/system/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
index 55e2a17..927244b 100644
--- a/system/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
+++ b/system/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java
@@ -123,26 +123,35 @@ public class SystemServiceImpl implements SystemService {
         long sleep = 0;
         if (time != null) {
             if (!time.equals("now")) {
-                if (time.startsWith("+")) {
-                    // delay in number of minutes provided
-                    time = time.substring(1);
-                    try {
-                        sleep = Long.parseLong(time) * 60 * 1000;
-                    } catch (Exception e) {
-                        throw new IllegalArgumentException("Time " + time + " is not valid");
-                    }
-                } else {
+                if (time.contains(":")) {
                     // try to parse the date in hh:mm
                     String[] strings = time.split(":");
                     if (strings.length != 2) {
-                        throw new IllegalArgumentException("Time " + time + " is not valid");
+                        throw new IllegalArgumentException("Time " + time + " is not valid (not in hour:minute format)");
+                    }
+                    int hour = Integer.parseInt(strings[0]);
+                    int minute = Integer.parseInt(strings[1]);
+                    if (hour < 0 || hour > 23) {
+                        throw new IllegalArgumentException("Time " + time + " is not valid (hour " + hour + " is not between 0 and 23)");
+                    }
+                    if (minute < 0 || minute > 59) {
+                        throw new IllegalArgumentException("Time " + time + " is not valid (minute " + minute + " is not between 0 and 59)");
                     }
                     GregorianCalendar currentDate = new GregorianCalendar();
-                    GregorianCalendar shutdownDate = new GregorianCalendar(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE), Integer.parseInt(strings[0]), Integer.parseInt(strings[1]));
+                    GregorianCalendar shutdownDate = new GregorianCalendar(currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DAY_OF_MONTH), Integer.parseInt(strings[0]), Integer.parseInt(strings[1]));
                     if (shutdownDate.before(currentDate)) {
                         shutdownDate.set(Calendar.DATE, shutdownDate.get(Calendar.DATE) + 1);
                     }
                     sleep = shutdownDate.getTimeInMillis() - currentDate.getTimeInMillis();
+                } else {
+                    if (time.startsWith("+")) {
+                        time = time.substring(1);
+                    }
+                    try {
+                        sleep = Long.parseLong(time) * 60 * 1000;
+                    } catch (Exception e) {
+                        throw new IllegalArgumentException("Time " + time + " is not valid");
+                    }
                 }
             }
         }