You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by me...@apache.org on 2006/12/26 18:29:35 UTC

svn commit: r490338 - /incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java

Author: meerajk
Date: Tue Dec 26 09:29:34 2006
New Revision: 490338

URL: http://svn.apache.org/viewvc?view=rev&rev=490338
Log:
First working version of startup and shutdown.

Modified:
    incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java

Modified: incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java?view=diff&rev=490338&r1=490337&r2=490338
==============================================================================
--- incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java (original)
+++ incubator/tuscany/java/sca/runtime/standalone/server.shutdown/src/main/java/org/apache/tuscany/standalone/server/ShutdownServer.java Tue Dec 26 09:29:34 2006
@@ -18,6 +18,14 @@
  */
 package org.apache.tuscany.standalone.server;
 
+import java.io.IOException;
+
+import javax.management.JMException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.remote.JMXServiceURL;
+import javax.management.remote.rmi.RMIConnector;
+
 /**
  * 
  * @version $Rev$ $Date$
@@ -25,11 +33,75 @@
  */
 public class ShutdownServer {
     
+    /** Tuscany admin host. */
+    private static final String ADMIN_HOST_PROPERTY = "tuscany.adminHost";
+    
+    /** Tuscany admin port. */
+    private static final String ADMIN_PORT_PROPERTY = "tuscany.adminPort";
+    
+    /** Default host. */
+    private static final String DEFAULT_ADMIN_HOST = "localhost";
+    
+    /** Default port. */
+    private static final int DEFAULT_ADMIN_PORT = 1099;
+    
+    /** Host. */
+    private String host = DEFAULT_ADMIN_HOST;
+    
+    /** Port. */
+    private int port = DEFAULT_ADMIN_PORT;
+    
     /**
      * 
      * @param args Commandline arguments.
      */
-    public static void main(String[] args) {
+    public static void main(String[] args) throws Exception {
+        
+        ShutdownServer shutdownServer = new ShutdownServer();
+        shutdownServer.shutdown();
+        
+    }
+    
+    /**
+     * Initializes the host and the port.
+     *
+     */
+    private ShutdownServer() {
+        
+        if(System.getProperty(ADMIN_HOST_PROPERTY) != null) {
+            host = System.getProperty(ADMIN_HOST_PROPERTY);
+        }
+        
+        if(System.getProperty(ADMIN_PORT_PROPERTY) != null) {
+            port = Integer.parseInt(System.getProperty(ADMIN_PORT_PROPERTY));
+        }
+        
+    }
+    
+    /**
+     * Shuts down the server.
+     * @throws IOException 
+     * @throws JMException
+     *
+     */
+    private void shutdown() throws IOException, JMException {
+        
+        RMIConnector rmiConnector = null;
+        
+        try {
+            
+            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://" + host + ":" + port + "/server");
+            rmiConnector = new RMIConnector(url, null);
+            rmiConnector.connect();
+            
+            MBeanServerConnection con = rmiConnector.getMBeanServerConnection();
+            con.invoke(new ObjectName("tuscany:name=tuscanyServer"), "shutdown", null, null);
+            
+        } finally {
+            if(rmiConnector != null) {
+                rmiConnector.close();
+            }
+        }
         
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org