/*******************************************************************************
 *
 *    Copyright (C) 2015-2016 the BBoxDB project
 *  
 *    Licensed 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.bboxdb;

import java.util.HashMap;
import java.util.Map;

import javax.management.JMX;
import javax.management.MBeanServerConnection;
import javax.management.ObjectName;
import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL;

import org.bboxdb.jmx.JMXService;
import org.bboxdb.jmx.LifecycleMBean;

public class Shutdown {

	/**
	 * Call the JMX service to shutdown the application
	 * @param args
	 */
	public static void main(final String[] args) throws Exception {

		if(args.length != 2) {
			System.err.println("Usage: Shutdown <Port> <Password>");
			System.exit(-1);
		}
		
		final int jmxPort = Integer.parseInt(args[0]);
		final String password = args[1];
		
		// Set username and password
		final Map<String, String[]> env = new HashMap<>();
		final String[] credentials = {"controlRoleUser", password};
		env.put(JMXConnector.CREDENTIALS, credentials);
		        
	    // Connect to JMX
        System.out.println("Connecting to JMX shtutdown service.");
        final JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://:" + jmxPort + "/jmxrmi");
        
        final JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
        final MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        final ObjectName mbeanName = new ObjectName(JMXService.MBEAN_LIFECYCLE);
        final LifecycleMBean mbeanProxy = JMX.newMBeanProxy(mbsc, mbeanName, LifecycleMBean.class, true);

        mbeanProxy.shutdown();

        jmxc.close();
        System.out.println("Done.");
	}
}

@@ -1287,16 +1287,21 @@
 ication%0A
+%09 * %0A
 %09 * @par
@@ -1488,18 +1488,16 @@
 1);%0A%09%09%7D%0A
-%09%09
 %0A%09%09final
@@ -1573,18 +1573,16 @@
 rgs%5B1%5D;%0A
-%09%09
 %0A%09%09// Se
@@ -1690,16 +1690,17 @@
 ials = %7B
+ 
 %22control
@@ -1718,16 +1718,17 @@
 password
+ 
 %7D;%0A%09%09env
@@ -1776,24 +1776,11 @@
 s);%0A
+%0A
 %09%09
-        %0A%09    
 // C
@@ -1793,24 +1793,18 @@
  to JMX%0A
-        
+%09%09
 System.o
@@ -1855,24 +1855,18 @@
 ice.%22);%0A
-        
+%09%09
 final JM
@@ -1901,16 +1901,21 @@
 viceURL(
+%0A%09%09%09%09
 %22service
@@ -1968,25 +1968,11 @@
 %22);%0A
-        %0A        
+%0A%09%09
 fina
@@ -2032,24 +2032,18 @@
 , env);%0A
-        
+%09%09
 final MB
@@ -2103,24 +2103,18 @@
 ion();%0A%0A
-        
+%09%09
 final Ob
@@ -2178,24 +2178,18 @@
 CYCLE);%0A
-        
+%09%09
 final Li
@@ -2248,17 +2248,21 @@
 eanName,
- 
+%0A%09%09%09%09
 Lifecycl
@@ -2283,24 +2283,18 @@
 true);%0A%0A
-        
+%09%09
 mbeanPro
@@ -2309,24 +2309,18 @@
 own();%0A%0A
-        
+%09%09
 jmxc.clo
@@ -2329,16 +2329,10 @@
 ();%0A
-        
+%09%09
 Syst

Reformat source