[kune-commits] [Kune - Enhancement #70] Implement some kind of "/etc/init.d/kune reload" to reload configuration

Redmine Comunes noreply at ourproject.org
Fri Mar 8 21:02:04 CET 2013


Issue #70 has been updated by Pablo Ojanguren.

File jmx-in-action-1.png added


Implemented initial version following these steps: 

1) Create MBean interface for class to manage

KunePropertiesDefaultMBean

<pre>

package cc.kune.core.server.properties;

/**
 * MBean interface for JMX management of server properties
 *
 */
public interface KunePropertiesDefaultMBean {

	
	String reload();
	String getProperty(String key);
	void setProperty(String key, String value);
	
}

</pre>


2) Implement mbean interface new methods

KunePropertiesDefault

<pre>
diff --git a/src/main/java/cc/kune/core/server/properties/KunePropertiesDefault.java b/src/main/java/cc/kune/core/server/properties/KunePropertiesDefault.java
index aa8639f..ed79f6d 100644
--- a/src/main/java/cc/kune/core/server/properties/KunePropertiesDefault.java
+++ b/src/main/java/cc/kune/core/server/properties/KunePropertiesDefault.java
@@ -1,6 +1,6 @@
 /*
  *
- * Copyright (C) 2007-2012 The kune development team (see CREDITS for details)
+ * Copyright (C) 2007-2013 The kune development team (see CREDITS for details)
  * This file is part of kune.
  *
  * This program is free software: you can redistribute it and/or modify
@@ -35,7 +35,7 @@
 import com.google.inject.Singleton;
 
 @Singleton
-public class KunePropertiesDefault implements KuneProperties {
+public class KunePropertiesDefault implements KuneProperties, KunePropertiesDefaultMBean {
   public static final Log LOG = LogFactory.getLog(KunePropertiesDefault.class);
   private CompositeConfiguration config;
   private final String fileName;
@@ -124,4 +124,33 @@
     }
   }
 
+  @Override
+  public String reload() {
+	 
+	  String resultInfoStr = "OK";
+	  
+	  try {
+		  
+		  loadConfiguration();
+		  
+	  } catch (final ServerException e) {
+		  
+		  resultInfoStr = e.getMessage();
+	  }
+	 
+	  return resultInfoStr;
+  }
+
+  @Override
+  public String getProperty(String key) {
+	  
+	  return this.get(key);
+  }
+
+  @Override
+  public void setProperty(String key, String value) {
+	  
+	  this.setProperty(key, value);
+  }
+
 }
</pre>


3) Add mbean activation just after KuneProperties object is created 


DataSourceKunePersistModule

<pre>
diff --git a/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java b/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java
index 5b097bf..2ae371b 100644
--- a/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java
+++ b/src/main/java/cc/kune/core/server/persist/DataSourceKunePersistModule.java
@@ -21,8 +21,15 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.lang.management.ManagementFactory;
 import java.util.Properties;
 
+import javax.management.InstanceAlreadyExistsException;
+import javax.management.MBeanRegistrationException;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.NotCompliantMBeanException;
+import javax.management.ObjectName;
 import javax.persistence.EntityManager;
 
 import org.apache.commons.configuration.SystemConfiguration;
@@ -220,6 +227,33 @@
     final SystemConfiguration sysConf = new SystemConfiguration();
     kuneConfig = settedProperties != null ? settedProperties : sysConf.getString("kune.server.config");
     kuneProperties = new KunePropertiesDefault(kuneConfig);
+    
+    /* #70 Reload Configuration Properties via JMX */
+    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer(); 
+    ObjectName mbeanName = null;
+    try {
+    
+    	mbeanName = new ObjectName("cc.kune.mbeans:type=KuneProperties");
+	
+    } catch (MalformedObjectNameException e) {
+		e.printStackTrace();		
+	} catch (NullPointerException e) {		
+		e.printStackTrace();
+	} 
+    
+    try {
+	
+    	mbeanServer.registerMBean(kuneProperties, mbeanName);
+	
+    } catch (InstanceAlreadyExistsException e) {
+		e.printStackTrace();
+	} catch (MBeanRegistrationException e) {
+		e.printStackTrace();
+	} catch (NotCompliantMBeanException e) {
+		e.printStackTrace();
+	}
+    
+    
     log4Conf = sysConf.getString("log4j.configuration");
   }
 </pre>


4) Tested successfully using jconsole through local jetty-java process (see attached picture)

*Next steps*

* Remote access to JMX Mbeans hasn't been tested. Maybe jetty additional configuration is needed. (in progress)

* Regression test. Unknown  collateral effects when some properties are changed (e.g. db connection?)

* To change a property doesn't imply to system be aware of it. If some object has already read the property (e.g. on its constructor) won't get new value anyway. Maybe JMX event feature should be enabled for these classes.

* It only affects to server side of RPC server. How are changes populated to GWT client?



 



----------------------------------------
Enhancement #70: Implement some kind of "/etc/init.d/kune reload" to reload configuration
http://redmine.ourproject.org/issues/70#change-742

* Author: Vicente J. Ruiz Jurado
* Status: New
* Priority: Normal
* Assignee: Pablo Ojanguren
* Category: Server side
* Target version: 
* Resolution: 
* Tags: 
----------------------------------------
Related
http://ykyuen.wordpress.com/2010/07/26/jetty-stop-a-jetty-server-by-command/
http://wiki.eclipse.org/Jetty/Howto/Secure_Termination
http://irc.codehaus.org/display/JETTY/How+to+gracefully+shutdown
http://ptrthomas.wordpress.com/2009/01/24/how-to-start-and-stop-jetty-revisited/
http://eureka.ykyuen.info/2010/07/26/jetty-stop-a-jetty-server-by-command/



-- 
You have received this notification because you have either subscribed to it, or are involved in it.
To change your notification preferences, please click here: http://redmine.ourproject.org/my/account

-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://lists.ourproject.org/pipermail/kune-commits/attachments/20130308/96f73551/attachment.htm 


More information about the kune-commits mailing list