karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1538910 - in /karaf/trunk/system/core/src/main: java/org/apache/karaf/system/management/SystemMBean.java java/org/apache/karaf/system/management/internal/System.java resources/OSGI-INF/blueprint/system-core.xml
Date Tue, 05 Nov 2013 09:18:53 GMT
Author: jbonofre
Date: Tue Nov  5 09:18:53 2013
New Revision: 1538910

URL: http://svn.apache.org/r1538910
Log:
[KARAF-2474] Add operations related to system properties in the SystemMBean

Modified:
    karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
    karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
    karaf/trunk/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml

Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java?rev=1538910&r1=1538909&r2=1538910&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
(original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/SystemMBean.java
Tue Nov  5 09:18:53 2013
@@ -16,19 +16,73 @@
  */
 package org.apache.karaf.system.management;
 
+import java.util.Map;
+
 /**
  * Describe the system MBean.
  */
 public interface SystemMBean {
 
+    /**
+     * Stop the Karaf instance
+     *
+     * @throws Exception
+     */
     void halt() throws Exception;
+
+    /**
+     * Stop the Karaf instance at a given time.
+     *
+     * @param time the time when to stop the Karaf instance.
+     * @throws Exception
+     */
     void halt(String time) throws Exception;
+
+    /**
+     * Reboot the Karaf instance.
+     *
+     * @throws Exception
+     */
     void reboot() throws Exception;
+
+    /**
+     * Reboot the Karaf instance at a given time.
+     *
+     * @param time the time when to reboot the Karaf instance.
+     * @throws Exception
+     */
     void reboot(String time) throws Exception;
+
+    /**
+     * Reboot the Karaf instance at a given time and clean the cache.
+     *
+     * @param time the time when to reboot the Karaf instance.
+     * @throws Exception
+     */
     void rebootCleanCache(String time) throws Exception;
+
+    /**
+     * Reboot the Karaf instance at a given time and clean all working files.
+     *
+     * @param time the time when to reboot the Karaf instance.
+     * @throws Exception
+     */
     void rebootCleanAll(String time) throws Exception;
 
+    /**
+     * Set the system bundle start level.
+     *
+     * @param startLevel the new system bundle start level.
+     * @throws Exception
+     */
     void setStartLevel(int startLevel) throws Exception;
+
+    /**
+     * Get the current system bundle start level.
+     *
+     * @return the current system bundle start level.
+     * @throws Exception
+     */
     int getStartLevel() throws Exception;
 
     /**
@@ -73,4 +127,30 @@ public interface SystemMBean {
      */
     String getVersion();
 
+    /**
+     * Get all system properties.
+     *
+     * @param unset if true, display the OSGi properties even if they are not defined (with
"undef" value).
+     * @param dumpToFile if true, dump the properties into a file in the data folder.
+     * @return the list of system properties.
+     */
+    Map<String, String> getProperties(boolean unset, boolean dumpToFile) throws Exception;
+
+    /**
+     * Get the value of a given system property.
+     *
+     * @param key the system property key.
+     * @return the system property value.
+     */
+    String getProperty(String key);
+
+    /**
+     * Set the value of a system property.
+     *
+     * @param key the system property key.
+     * @param value the new system property value.
+     * @param persistent if true, persist the new value to the etc/system.properties file.
+     */
+    void setProperty(String key, String value, boolean persistent);
+
 }

Modified: karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java?rev=1538910&r1=1538909&r2=1538910&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
(original)
+++ karaf/trunk/system/core/src/main/java/org/apache/karaf/system/management/internal/System.java
Tue Nov  5 09:18:53 2013
@@ -19,9 +19,15 @@ package org.apache.karaf.system.manageme
 import org.apache.karaf.system.FrameworkType;
 import org.apache.karaf.system.SystemService;
 import org.apache.karaf.system.management.SystemMBean;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
 
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
+import java.io.File;
+import java.io.PrintStream;
+import java.text.SimpleDateFormat;
+import java.util.*;
 
 /**
  * System MBean implementation.
@@ -29,6 +35,11 @@ import javax.management.StandardMBean;
 public class System extends StandardMBean implements SystemMBean {
 
     private SystemService systemService;
+    private BundleContext bundleContext;
+
+    public void setBundleContext(BundleContext bundleContext) {
+        this.bundleContext = bundleContext;
+    }
 
     public System() throws NotCompliantMBeanException {
         super(SystemMBean.class);
@@ -107,4 +118,105 @@ public class System extends StandardMBea
         return this.systemService.getVersion();
     }
 
+    @Override
+    public Map<String, String> getProperties(boolean unset, boolean dumpToFile) throws
Exception {
+        Map<String, String> result = new HashMap<String, String>();
+
+        Properties props = (Properties) java.lang.System.getProperties().clone();
+
+        String def = null;
+        if (unset) {
+            def = "unset";
+        }
+
+        setProperty(props, Constants.FRAMEWORK_BEGINNING_STARTLEVEL, def);
+        setProperty(props, Constants.FRAMEWORK_BOOTDELEGATION, def);
+        setProperty(props, Constants.FRAMEWORK_BUNDLE_PARENT, def);
+        setProperty(props, Constants.FRAMEWORK_BUNDLE_PARENT_APP, def);
+        setProperty(props, Constants.FRAMEWORK_BUNDLE_PARENT_BOOT, def);
+        setProperty(props, Constants.FRAMEWORK_BUNDLE_PARENT_EXT, def);
+        setProperty(props, Constants.FRAMEWORK_BUNDLE_PARENT_FRAMEWORK, def);
+        setProperty(props, Constants.FRAMEWORK_EXECPERMISSION, def);
+        setProperty(props, Constants.FRAMEWORK_EXECUTIONENVIRONMENT, def);
+        setProperty(props, Constants.FRAMEWORK_LANGUAGE, def);
+        setProperty(props, Constants.FRAMEWORK_LIBRARY_EXTENSIONS, def);
+        setProperty(props, Constants.FRAMEWORK_OS_NAME, def);
+        setProperty(props, Constants.FRAMEWORK_OS_VERSION, def);
+        setProperty(props, Constants.FRAMEWORK_PROCESSOR, def);
+        setProperty(props, Constants.FRAMEWORK_SECURITY, def);
+        setProperty(props, Constants.FRAMEWORK_SECURITY_OSGI, def);
+        setProperty(props, Constants.FRAMEWORK_STORAGE, def);
+        setProperty(props, Constants.FRAMEWORK_STORAGE_CLEAN_ONFIRSTINIT, def);
+        setProperty(props, Constants.FRAMEWORK_SYSTEMPACKAGES, def);
+        setProperty(props, Constants.FRAMEWORK_SYSTEMPACKAGES_EXTRA, def);
+        setProperty(props, Constants.FRAMEWORK_VENDOR, def);
+        setProperty(props, Constants.FRAMEWORK_VERSION, def);
+        setProperty(props, Constants.FRAMEWORK_WINDOWSYSTEM, def);
+
+        setProperty(props, Constants.SUPPORTS_BOOTCLASSPATH_EXTENSION, def);
+        setProperty(props, Constants.SUPPORTS_FRAMEWORK_EXTENSION, def);
+        setProperty(props, Constants.SUPPORTS_FRAMEWORK_FRAGMENT, def);
+        setProperty(props, Constants.SUPPORTS_FRAMEWORK_REQUIREBUNDLE, def);
+
+        if (dumpToFile) {
+            PrintStream ps = new PrintStream(new File(bundleContext.getProperty("karaf.data"),
"dump-properties-" + java.lang.System.currentTimeMillis() + ".properties"));
+            ps.println("#Dump of the System and OSGi properties with the command dev:dump-properties");
+            ps.println("#Dump execute at " + new SimpleDateFormat().format(new Date()));
+            printOrderedProperties(props, ps);
+            ps.flush();
+            ps.close();
+        } else {
+            printOrderedProperties(props, result);
+        }
+
+        return result;
+    }
+
+    private void printOrderedProperties(Properties props, PrintStream out) {
+        Set<Object> keys = props.keySet();
+        Vector<String> order = new Vector<String>(keys.size());
+        for (Iterator<Object> i = keys.iterator(); i.hasNext(); ) {
+            Object str = (Object) i.next();
+            order.add((String) str);
+        }
+        Collections.sort(order);
+        for (Iterator<String> i = order.iterator(); i.hasNext(); ) {
+            String key = (String) i.next();
+            out.println(key + "=" + props.getProperty(key));
+        }
+    }
+
+    private void printOrderedProperties(Properties props, Map<String, String> result)
{
+        Set<Object> keys = props.keySet();
+        Vector<String> order = new Vector<String>(keys.size());
+        for (Iterator<Object> i = keys.iterator(); i.hasNext(); ) {
+            Object str = (Object) i.next();
+            order.add((String) str);
+        }
+        Collections.sort(order);
+        for (Iterator<String> i = order.iterator(); i.hasNext(); ) {
+            String key = (String) i.next();
+            result.put(key, props.getProperty(key));
+        }
+    }
+
+    private void setProperty(Properties props, String key, String def) {
+        String val = bundleContext.getProperty(key);
+        if (val == null && def != null) {
+            props.setProperty(key, def);
+        } else if (val != null) {
+            props.setProperty(key, val);
+        }
+    }
+
+    @Override
+    public String getProperty(String key) {
+        return java.lang.System.getProperty(key);
+    }
+
+    @Override
+    public void setProperty(String key, String value, boolean persistent) {
+        systemService.setSystemProperty(key, value, persistent);
+    }
+
 }

Modified: karaf/trunk/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml
URL: http://svn.apache.org/viewvc/karaf/trunk/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml?rev=1538910&r1=1538909&r2=1538910&view=diff
==============================================================================
--- karaf/trunk/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml (original)
+++ karaf/trunk/system/core/src/main/resources/OSGI-INF/blueprint/system-core.xml Tue Nov
 5 09:18:53 2013
@@ -30,6 +30,7 @@
 
     <bean id="systemMBean" class="org.apache.karaf.system.management.internal.System">
         <property name="systemService" ref="systemService" />
+        <property name="bundleContext" ref="blueprintBundleContext"/>
     </bean>
 
     <service ref="systemMBean" auto-export="interfaces">



Mime
View raw message