geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r1414408 - in /geronimo/server/branches/3.0/framework/modules: geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/ geronimo-main/src/main/java/org/apache/geronimo/main/
Date Tue, 27 Nov 2012 21:42:37 GMT
Author: gawor
Date: Tue Nov 27 21:42:32 2012
New Revision: 1414408

URL: http://svn.apache.org/viewvc?rev=1414408&view=rev
Log:
GERONIMO-6417: Add support for launch listeners

Added:
    geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
  (with props)
    geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
  (with props)
Modified:
    geronimo/server/branches/3.0/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/DaemonCLI.java
    geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
    geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/DaemonCLI.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/DaemonCLI.java?rev=1414408&r1=1414407&r2=1414408&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/DaemonCLI.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-cli/src/main/java/org/apache/geronimo/cli/daemon/DaemonCLI.java
Tue Nov 27 21:42:32 2012
@@ -21,6 +21,7 @@ import java.util.Arrays;
 import org.apache.geronimo.cli.AbstractCLI;
 import org.apache.geronimo.cli.CLParser;
 import org.apache.geronimo.main.Bootstrapper;
+import org.apache.geronimo.main.ScriptLaunchListener;
 
 
 /**
@@ -49,6 +50,7 @@ public class DaemonCLI extends AbstractC
         boot.setStartBundles(Arrays.asList("org.apache.geronimo.framework/j2ee-system//car"));
         boot.setLog4jConfigFile("var/log/server-log4j.properties");
         boot.setCleanStorage( ((DaemonCLParser) parser).isCleanCache() );
+        boot.setLaunchListener(new ScriptLaunchListener("server"));
         return boot;
     }
 }

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java?rev=1414408&r1=1414407&r2=1414408&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/Bootstrapper.java
Tue Nov 27 21:42:32 2012
@@ -31,6 +31,7 @@ public class Bootstrapper extends Framew
     
     private boolean waitForStop = true;    
     private List<String> bundles;
+    private LaunchListener listener;
 
     public Bootstrapper() {
     }
@@ -43,20 +44,41 @@ public class Bootstrapper extends Framew
         this.bundles = bundles;
     }
         
+    public void setLaunchListener(LaunchListener listener) {
+        this.listener = listener;
+    }
+    
     public int execute(Object opaque) {
         try {
+            init();
+        } catch (Throwable e) {
+            System.err.println("Error initializing launcher: " + e);
+            return -1;
+        }
+        if (listener != null) {
+            listener.starting();
+        }
+        int errorCode = start(opaque);
+        if (listener != null) {
+            listener.stopped(errorCode);
+        }
+        return errorCode;
+    }
+    
+    private int start(Object opaque) {
+        try {
             launch();
         } catch (Throwable e) {
-            System.err.println("Error launching framework: " + e);
+            System.err.println("Error starting framework: " + e);
             destroy(false);
-            return -1;
+            return -2;
         }
                               
         Main geronimoMain = getMain();        
         if (geronimoMain == null) {
             System.err.println("Main not found");
             destroy(false);
-            return -1;
+            return -3;
         }
         
         ClassLoader oldTCCL = Thread.currentThread().getContextClassLoader();
@@ -65,6 +87,9 @@ public class Bootstrapper extends Framew
             Thread.currentThread().setContextClassLoader(newTCCL);
             int exitCode = geronimoMain.execute(opaque);
             if (exitCode == 0) {
+                if (listener != null) {
+                    listener.started();
+                }
                 if (waitForStop) {
                     // executing main could have installed some additional bundles 
                     // so check and try to start any unstarted bundles.
@@ -78,7 +103,7 @@ public class Bootstrapper extends Framew
         } catch (Throwable e) {
             System.err.println("Error in Main: " + e);
             destroy(false);
-            return -1;
+            return -4;
         } finally {
             Thread.currentThread().setContextClassLoader(oldTCCL);
         }

Modified: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java?rev=1414408&r1=1414407&r2=1414408&view=diff
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
(original)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/FrameworkLauncher.java
Tue Nov 27 21:42:32 2012
@@ -123,7 +123,7 @@ public class FrameworkLauncher {
         this.cleanStorage = cleanStorage;
     }
 
-    public void launch() throws Exception {
+    public void init() throws Exception {
         geronimoHome = Utils.getGeronimoHome();
         geronimoBase = Utils.getGeronimoBase(geronimoHome);
 
@@ -152,8 +152,6 @@ public class FrameworkLauncher {
         configJansiPath();
 
         setFrameworkStorage(configProps);
-        
-        
 
         if (cleanStorage) {
             configProps.setProperty(Constants.FRAMEWORK_STORAGE_CLEAN,
@@ -164,7 +162,9 @@ public class FrameworkLauncher {
            configProps.setProperty(Constants.FRAMEWORK_STORAGE_CLEAN,
                     Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT);
         }
-
+    }
+    
+    public void launch() throws Exception {
         Runtime.getRuntime().addShutdownHook(new Thread() {
             public void run() {
                 // wait up to 3 minutes for complete shutdown

Added: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java?rev=1414408&view=auto
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
(added)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
Tue Nov 27 21:42:32 2012
@@ -0,0 +1,27 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.main;
+
+public interface LaunchListener {
+    
+    void starting();
+    
+    void started();
+    
+    void stopped(int errorCode);
+    
+}

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/LaunchListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java?rev=1414408&view=auto
==============================================================================
--- geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
(added)
+++ geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
Tue Nov 27 21:42:32 2012
@@ -0,0 +1,75 @@
+/**
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You 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.geronimo.main;
+
+public class ScriptLaunchListener implements LaunchListener {
+
+    private final String propertyPrefix;
+    
+    public ScriptLaunchListener(String propertyPrefix) {
+        this.propertyPrefix = propertyPrefix;
+    }
+    
+    @Override
+    public void starting() {
+        String cmd = getOption("starting.cmd", null);
+        if (cmd != null) {
+            execute(cmd);
+        }
+    }
+
+    @Override
+    public void started() {
+        String cmd = getOption("started.cmd", null);
+        if (cmd != null) {
+            execute(cmd);
+        }
+    }
+
+    @Override
+    public void stopped(int errorCode) {
+        String cmd = getOption("stopped.cmd", null);
+        if (cmd != null) {
+            cmd = cmd + " " + errorCode;
+            execute(cmd);
+        }
+    }
+   
+    private String getOption(String type, String defaultValue) {
+        if (propertyPrefix == null) {
+            return System.getProperty(type, defaultValue);
+        } else {
+            return System.getProperty(propertyPrefix + "." + type, defaultValue);
+        }
+    }
+    
+    private void execute(String cmd) {
+        try {
+            Process process = Runtime.getRuntime().exec(cmd);
+            if (waitForCommand()) {
+                process.waitFor();
+            }
+        } catch (Exception e) {
+            System.err.println("Error executing command [" + cmd + "]");
+        }       
+    }
+    
+    private boolean waitForCommand() {
+        String value = getOption("cmd.waitFor", "false");
+        return Boolean.parseBoolean(value);
+    }
+}

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/branches/3.0/framework/modules/geronimo-main/src/main/java/org/apache/geronimo/main/ScriptLaunchListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message