karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbono...@apache.org
Subject svn commit: r1544523 - in /karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core: BundlesMBean.java internal/Bundles.java
Date Fri, 22 Nov 2013 13:09:29 GMT
Author: jbonofre
Date: Fri Nov 22 13:09:29 2013
New Revision: 1544523

URL: http://svn.apache.org/r1544523
Log:
[KARAF-2264] Wrap the exceptions in MBeanException in BundlesMBean

Modified:
    karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java
    karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/Bundles.java

Modified: karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java?rev=1544523&r1=1544522&r2=1544523&view=diff
==============================================================================
--- karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java (original)
+++ karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/BundlesMBean.java Fri
Nov 22 13:09:29 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.karaf.bundle.core;
 
+import javax.management.MBeanException;
 import javax.management.openmbean.TabularData;
 
 /**
@@ -23,30 +24,30 @@ import javax.management.openmbean.Tabula
  */
 public interface BundlesMBean {
 
-    TabularData getBundles() throws Exception;
+    TabularData getBundles() throws MBeanException;
 
-    int getStartLevel(String bundleId) throws Exception;
-    void setStartLevel(String bundleId, int bundleStartLevel) throws Exception;
+    int getStartLevel(String bundleId) throws MBeanException;
+    void setStartLevel(String bundleId, int bundleStartLevel) throws MBeanException;
 
-    void refresh() throws Exception;
-    void refresh(String bundleId) throws Exception;
+    void refresh() throws MBeanException;
+    void refresh(String bundleId) throws MBeanException;
 
-    void update(String bundleId) throws Exception;
-    void update(String bundleId, String location) throws Exception;
+    void update(String bundleId) throws MBeanException;
+    void update(String bundleId, String location) throws MBeanException;
 
-    void resolve() throws Exception;
-    void resolve(String bundleId) throws Exception;
+    void resolve() throws MBeanException;
+    void resolve(String bundleId) throws MBeanException;
 
-    void restart(String bundleId) throws Exception;
+    void restart(String bundleId) throws MBeanException;
 
-    long install(String url) throws Exception;
-    long install(String url, boolean start) throws Exception;
+    long install(String url) throws MBeanException;
+    long install(String url, boolean start) throws MBeanException;
 
-    void start(String bundleId) throws Exception;
+    void start(String bundleId) throws MBeanException;
 
-    void stop(String bundleId) throws Exception;
+    void stop(String bundleId) throws MBeanException;
 
-    void uninstall(String bundleId) throws Exception;
+    void uninstall(String bundleId) throws MBeanException;
     
     String getDiag(long bundleId);
 

Modified: karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/Bundles.java
URL: http://svn.apache.org/viewvc/karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/Bundles.java?rev=1544523&r1=1544522&r2=1544523&view=diff
==============================================================================
--- karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/Bundles.java
(original)
+++ karaf/trunk/bundle/core/src/main/java/org/apache/karaf/bundle/core/internal/Bundles.java
Fri Nov 22 13:09:29 2013
@@ -21,6 +21,7 @@ import java.net.URL;
 import java.util.Collections;
 import java.util.List;
 
+import javax.management.MBeanException;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
 import javax.management.openmbean.CompositeData;
@@ -56,53 +57,65 @@ public class Bundles extends StandardMBe
         this.bundleContext = bundleContext;
         this.bundleService = bundleService;
     }
-    
+
     private List<Bundle> selectBundles(String id) throws Exception {
         List<String> ids = Collections.singletonList(id);
-        return this.bundleService.selectBundles(ids , false);
+        return this.bundleService.selectBundles(ids, false);
     }
 
-    public TabularData getBundles() throws Exception {
-        CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle",
-                new String[]{"ID", "Name", "Version", "Start Level", "State"},
-                new String[]{"ID of the Bundle", "Name of the Bundle", "Version of the Bundle",
"Start Level of the Bundle", "Current State of the Bundle"},
-                new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING, SimpleType.INTEGER,
SimpleType.STRING});
-        TabularType tableType = new TabularType("Bundles", "Tables of all Bundles", bundleType,
new String[]{"ID"});
-        TabularData table = new TabularDataSupport(tableType);
-
-        Bundle[] bundles = bundleContext.getBundles();
-
-        for (int i = 0; i < bundles.length; i++) {
-            try {
-                Bundle bundle = bundles[i];
-                BundleInfo info = bundleService.getInfo(bundle);
-                String bundleStateString = info.getState().toString();
-                CompositeData data = new CompositeDataSupport(bundleType,
-                        new String[]{"ID", "Name", "Version", "Start Level", "State"},
-                        new Object[]{info.getBundleId(), info.getSymbolicName(), info.getVersion(),
info.getStartLevel(), bundleStateString});
-                table.put(data);
-            } catch (Exception e) {
-                LOG.error(e.getMessage(), e);
+    public TabularData getBundles() throws MBeanException {
+        try {
+            CompositeType bundleType = new CompositeType("Bundle", "OSGi Bundle",
+                    new String[]{"ID", "Name", "Version", "Start Level", "State"},
+                    new String[]{"ID of the Bundle", "Name of the Bundle", "Version of the
Bundle", "Start Level of the Bundle", "Current State of the Bundle"},
+                    new OpenType[]{SimpleType.LONG, SimpleType.STRING, SimpleType.STRING,
SimpleType.INTEGER, SimpleType.STRING});
+            TabularType tableType = new TabularType("Bundles", "Tables of all Bundles", bundleType,
new String[]{"ID"});
+            TabularData table = new TabularDataSupport(tableType);
+
+            Bundle[] bundles = bundleContext.getBundles();
+
+            for (int i = 0; i < bundles.length; i++) {
+                try {
+                    Bundle bundle = bundles[i];
+                    BundleInfo info = bundleService.getInfo(bundle);
+                    String bundleStateString = info.getState().toString();
+                    CompositeData data = new CompositeDataSupport(bundleType,
+                            new String[]{"ID", "Name", "Version", "Start Level", "State"},
+                            new Object[]{info.getBundleId(), info.getSymbolicName(), info.getVersion(),
info.getStartLevel(), bundleStateString});
+                    table.put(data);
+                } catch (Exception e) {
+                    LOG.error(e.getMessage(), e);
+                }
             }
+            return table;
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        return table;
     }
 
-    public int getStartLevel(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public int getStartLevel(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        if (bundles.size() != 1) {
-            throw new IllegalArgumentException("Provided bundle Id doesn't return any bundle
or more than one bundle selected");
-        }
+            if (bundles.size() != 1) {
+                throw new IllegalArgumentException("Provided bundle Id doesn't return any
bundle or more than one bundle selected");
+            }
 
-        return getBundleStartLevel(bundles.get(0)).getStartLevel();
+            return getBundleStartLevel(bundles.get(0)).getStartLevel();
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
-    public void setStartLevel(String bundleId, int bundleStartLevel) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void setStartLevel(String bundleId, int bundleStartLevel) throws MBeanException
{
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        for (Bundle bundle : bundles) {
-            getBundleStartLevel(bundle).setStartLevel(bundleStartLevel);
+            for (Bundle bundle : bundles) {
+                getBundleStartLevel(bundle).setStartLevel(bundleStartLevel);
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
     }
 
@@ -110,93 +123,124 @@ public class Bundles extends StandardMBe
         return bundle.adapt(BundleStartLevel.class);
     }
 
-    public void refresh() throws Exception {
+    public void refresh() throws MBeanException {
         getFrameworkWiring().refreshBundles(null);
     }
 
-    public void refresh(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
-        getFrameworkWiring().refreshBundles(bundles);
+    public void refresh(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
+            getFrameworkWiring().refreshBundles(bundles);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
-    public void update(String bundleId) throws Exception {
+    public void update(String bundleId) throws MBeanException {
         update(bundleId, null);
     }
 
-    public void update(String bundleId, String location) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void update(String bundleId, String location) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
+
+            if (location == null) {
+                for (Bundle bundle : bundles) {
+                    bundle.update();
+                }
+                return;
+            }
 
-        if (location == null) {
-            for (Bundle bundle : bundles) {
-                bundle.update();
+            if (bundles.size() != 1) {
+                throw new IllegalArgumentException("Provided bundle Id doesn't return any
bundle or more than one bundle selected");
             }
-            return;
-        }
 
-        if (bundles.size() != 1) {
-            throw new IllegalArgumentException("Provided bundle Id doesn't return any bundle
or more than one bundle selected");
+            InputStream is = new URL(location).openStream();
+            bundles.get(0).update(is);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-
-        InputStream is = new URL(location).openStream();
-        bundles.get(0).update(is);
     }
 
-    public void resolve() throws Exception {
+    public void resolve() throws MBeanException {
         getFrameworkWiring().resolveBundles(null);
     }
 
-    public void resolve(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
-        getFrameworkWiring().resolveBundles(bundles);
+    public void resolve(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
+            getFrameworkWiring().resolveBundles(bundles);
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
+        }
     }
 
     private FrameworkWiring getFrameworkWiring() {
         return getBundleContext().getBundle(0).adapt(FrameworkWiring.class);
     }
 
-    public void restart(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void restart(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        for (Bundle bundle : bundles) {
-            bundle.stop();
-            bundle.start();
+            for (Bundle bundle : bundles) {
+                bundle.stop();
+                bundle.start();
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-
     }
 
-    public long install(String url) throws Exception {
+    public long install(String url) throws MBeanException {
         return install(url, false);
     }
 
-    public long install(String url, boolean start) throws Exception {
-        Bundle bundle = bundleContext.installBundle(url, null);
-        if (start) {
-            bundle.start();
+    public long install(String url, boolean start) throws MBeanException {
+        try {
+            Bundle bundle = bundleContext.installBundle(url, null);
+            if (start) {
+                bundle.start();
+            }
+            return bundle.getBundleId();
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
-        return bundle.getBundleId();
     }
 
-    public void start(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void start(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        for (Bundle bundle : bundles) {
-            bundle.start();
+            for (Bundle bundle : bundles) {
+                bundle.start();
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
     }
 
-    public void stop(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void stop(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        for (Bundle bundle : bundles) {
-            bundle.stop();
+            for (Bundle bundle : bundles) {
+                bundle.stop();
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
     }
 
-    public void uninstall(String bundleId) throws Exception {
-        List<Bundle> bundles = selectBundles(bundleId);
+    public void uninstall(String bundleId) throws MBeanException {
+        try {
+            List<Bundle> bundles = selectBundles(bundleId);
 
-        for (Bundle bundle : bundles) {
-            bundle.uninstall();
+            for (Bundle bundle : bundles) {
+                bundle.uninstall();
+            }
+        } catch (Exception e) {
+            throw new MBeanException(null, e.getMessage());
         }
     }
 



Mime
View raw message