### Eclipse Workspace Patch 1.0
#P petals-platform-3.1.1-tmp
Index: src/main/java/org/ow2/petals/distribution/platform/Main.java
===================================================================
--- src/main/java/org/ow2/petals/distribution/platform/Main.java	(revision 16565)
+++ src/main/java/org/ow2/petals/distribution/platform/Main.java	(working copy)
@@ -39,7 +39,13 @@
      */
     public static void main(String[] args) {
         AbstractLauncher launcher = new PlatformLauncher();
-        launcher.launch(args);
+        try {
+            launcher.init();
+            launcher.launch(args);
+        } catch (final Exception e) {
+            e.printStackTrace();
+            System.exit(-1);
+        }
     }
 
 }
Index: src/main/packaging/conf/server.properties
===================================================================
--- src/main/packaging/conf/server.properties	(revision 16565)
+++ src/main/packaging/conf/server.properties	(working copy)
@@ -51,6 +51,9 @@
 #It can be useful in production environment to unactivate this service.
 petals.autoloader=true
 
+# This property is used to set the timeout stopping Petals before to force the stop
+#petals.stop.timeout=15000
+
 # Alternate topology configuration file URL. This value must be a valid URL like :
 #  - http://localhost:8080/petals/topology.xml
 #  - file:///home/petals/config/topology.xml
#P petals-launcher-1.3.x-registry
Index: src/main/java/org/ow2/petals/launcher/PlatformLauncher.java
===================================================================
--- src/main/java/org/ow2/petals/launcher/PlatformLauncher.java	(revision 16565)
+++ src/main/java/org/ow2/petals/launcher/PlatformLauncher.java	(working copy)
@@ -22,25 +22,12 @@
 
 package org.ow2.petals.launcher;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.util.Properties;
-
 import javax.naming.ConfigurationException;
-import javax.xml.bind.JAXBException;
 
 import org.ow2.petals.jmx.JMXClient;
 import org.ow2.petals.jmx.exception.ConnectionErrorException;
-import org.ow2.petals.jmx.exception.PetalsAdminDoesNotExistException;
-import org.ow2.petals.jmx.exception.PetalsAdminServiceErrorException;
-import org.ow2.petals.topology.TopologyBuilder;
-import org.ow2.petals.topology.TopologyException;
 import org.ow2.petals.topology.TopologyHelper;
 import org.ow2.petals.topology.generated.Container;
-import org.ow2.petals.topology.generated.Topology;
 
 /**
  * This class is used to start and manage the Petals platform from command line
@@ -62,48 +49,16 @@
      * 
      * @see org.ow2.petals.launcher.AbstractLauncher#getPetalsJmxClient()
      */
-    protected synchronized JMXClient getJMXClient() throws IOException, JAXBException,
-            TopologyException, ConnectionErrorException, PetalsAdminDoesNotExistException,
-            PetalsAdminServiceErrorException, ConfigurationException {
+    protected synchronized JMXClient getJMXClient() throws ConfigurationException, ConnectionErrorException {
 
         if (this.jmxClient == null) {
-            // retrieve resources
-            URL serverPropsURL = this.getClass().getResource(SERVER_PROPS_FILE);
-            if (serverPropsURL == null) {
 
-                throw new IOException("Failed to reach the resource '" + SERVER_PROPS_FILE + "'");
-            }
-            File serverPropsFile = null;
-            try {
-                serverPropsFile = new File(serverPropsURL.toURI().normalize());
-            } catch (URISyntaxException e) {
-                // can not happen
-            }
-
-            URL topologyURL = this.getClass().getResource(TOPOLOGY_FILE);
-            if (topologyURL == null) {
-                throw new IOException("Failed to reach the resource '" + TOPOLOGY_FILE + "'");
-            }
-            File topologyFile = null;
-            try {
-                topologyFile = new File(topologyURL.toURI().normalize());
-            } catch (URISyntaxException e) {
-                // can not happen
-            }
-
-            // build the topology object
-            Topology topology = TopologyBuilder.createTopology(topologyFile);
-
-            // retrieve the server properties
-            Properties serverProperties = new Properties();
-            serverProperties.load(new FileInputStream(serverPropsFile));
-
-            String containerName = serverProperties.getProperty(PROPERTY_CONTAINER_NAME);
+            String containerName = this.serverProperties.getProperty(PROPERTY_CONTAINER_NAME);
             if (containerName == null) {
                 containerName = System.getProperty(PROPERTY_CONTAINER_NAME);
             }
 
-            Container localContainer = TopologyHelper.findContainer(containerName, topology);
+            Container localContainer = TopologyHelper.findContainer(containerName, this.topology);
 
             if (localContainer == null) {
                 throw new ConfigurationException(
Index: src/main/java/org/ow2/petals/launcher/util/SystemExitHook.java
===================================================================
--- src/main/java/org/ow2/petals/launcher/util/SystemExitHook.java	(revision 16565)
+++ src/main/java/org/ow2/petals/launcher/util/SystemExitHook.java	(working copy)
@@ -39,7 +39,7 @@
     /**
      * The timeout for stopping petals
      */
-    private static final long STOP_TIMEOUT = 15000;
+    private final long stopTimeout;
 
     private Locker locker;
 
@@ -85,10 +85,12 @@
      * @param petalsServer
      */
     public SystemExitHook(PetalsServer petalsServer, Locker locker,
-            PetalsStateListener petalsListener) {
+ PetalsStateListener petalsListener,
+            final long stopTimeout) {
         super();
         this.petalsStopThread = new PetalsStopThread(petalsServer, petalsListener);
         this.locker = locker;
+        this.stopTimeout = stopTimeout;
 
     }
 
@@ -104,7 +106,7 @@
             System.out.println("PEtALS is stopping...");
             this.petalsStopThread.start();
 
-            this.petalsStopThread.join(STOP_TIMEOUT);
+            this.petalsStopThread.join(this.stopTimeout);
 
             final Date date = new Date(System.currentTimeMillis());
 
Index: src/main/java/org/ow2/petals/launcher/AbstractLauncher.java
===================================================================
--- src/main/java/org/ow2/petals/launcher/AbstractLauncher.java	(revision 16565)
+++ src/main/java/org/ow2/petals/launcher/AbstractLauncher.java	(working copy)
@@ -23,11 +23,14 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
 import java.lang.reflect.InvocationTargetException;
+import java.net.URISyntaxException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Properties;
 
 import javax.naming.ConfigurationException;
 import javax.xml.bind.JAXBException;
@@ -43,7 +46,9 @@
 import org.ow2.petals.launcher.util.CommandReader;
 import org.ow2.petals.launcher.util.Locker;
 import org.ow2.petals.launcher.util.SystemExitHook;
+import org.ow2.petals.topology.TopologyBuilder;
 import org.ow2.petals.topology.TopologyException;
+import org.ow2.petals.topology.generated.Topology;
 
 /**
  * 
@@ -86,6 +91,26 @@
     protected JMXClient jmxClient;
 
     /**
+     * Server properties
+     */
+    protected Properties serverProperties = new Properties();
+
+    /**
+     * Topology
+     */
+    protected Topology topology;
+
+    /**
+     * The default timeout for stopping petals
+     */
+    private static final long DEFAULT_STOP_TIMEOUT = 15000;
+
+    /**
+     * The timeout for stopping petals
+     */
+    private long stopTimeout = DEFAULT_STOP_TIMEOUT;
+
+    /**
      * Default constructor
      */
     public AbstractLauncher() {
@@ -107,6 +132,47 @@
         System.out.println();
     }
 
+    public void init() throws IOException, TopologyException {
+
+        // retrieve the server properties
+        final InputStream isSrvProps = this.getClass().getResourceAsStream(SERVER_PROPS_FILE);
+        if (isSrvProps == null) {
+            throw new IOException("Failed to reach the resource '" + SERVER_PROPS_FILE + "'");
+        } else {
+            try {
+                this.serverProperties.load(isSrvProps);
+            } finally {
+                isSrvProps.close();
+            }
+        }
+
+        // Check the petals node shutdown timeout
+        final String stopTimoutStr = this.serverProperties.getProperty("petals.stop.timeout");
+        if (stopTimoutStr != null) {
+            try {
+                this.stopTimeout = Long.parseLong(stopTimoutStr);
+            } catch (final NumberFormatException e) {
+                // NOP: Use the default value
+            }
+        }
+
+        // build the topology object
+        final URL topologyURL = this.getClass().getResource(TOPOLOGY_FILE);
+        if (topologyURL == null) {
+            throw new IOException("Failed to reach the resource '" + TOPOLOGY_FILE + "'");
+        } else {
+            File topologyFile = null;
+            try {
+                topologyFile = new File(topologyURL.toURI().normalize());
+            } catch (URISyntaxException e) {
+                // can not happen
+            }
+
+            this.topology = TopologyBuilder.createTopology(topologyFile);
+        }
+
+    }
+
     /**
      * The main program
      * 
@@ -183,7 +249,7 @@
         this.petalsServer.addPetalsStateListener(this);
 
         // add a hook if a terminate signal is sent from the command line
-        this.systemExitHook = new SystemExitHook(this.petalsServer, this.locker, this);
+        this.systemExitHook = new SystemExitHook(this.petalsServer, this.locker, this, this.stopTimeout);
         Runtime.getRuntime().addShutdownHook(this.systemExitHook);
 
         this.petalsServer.init();
