Repository: karaf Updated Branches: refs/heads/karaf-3.0.x 032b79374 -> 4e2be7efd
[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/4e2be7ef Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/4e2be7ef Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/4e2be7ef Branch: refs/heads/karaf-3.0.x Commit: 4e2be7efd458cefd9cce7f4fd7b551d612c23a04 Parents: 032b793 Author: Jean-Baptiste Onofré <[email protected]> Authored: Thu Aug 7 09:59:54 2014 +0200 Committer: Jean-Baptiste Onofré <[email protected]> Committed: Thu Aug 7 10:07:00 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/4e2be7ef/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/4e2be7ef/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java ---------------------------------------------------------------------- diff --git a/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java b/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java index 1d167d9..0bd0c47 100644 --- a/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java +++ b/system/command/src/main/java/org/apache/karaf/system/commands/Shutdown.java @@ -43,11 +43,10 @@ public class Shutdown extends AbstractSystemAction { @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; protected Object doExecute() throws Exception { http://git-wip-us.apache.org/repos/asf/karaf/blob/4e2be7ef/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java ---------------------------------------------------------------------- diff --git a/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java b/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java index 8fa5a38..2a941a8 100644 --- a/system/core/src/main/java/org/apache/karaf/system/internal/SystemServiceImpl.java +++ b/system/core/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"); + } } } }
