You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/11/25 11:14:53 UTC
svn commit: r1545206 - in
/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management:
ScrServiceMBean.java internal/ScrServiceMBeanImpl.java
Author: jbonofre
Date: Mon Nov 25 10:14:53 2013
New Revision: 1545206
URL: http://svn.apache.org/r1545206
Log:
[KARAF-2264] Wrap Exceptions as MBeanException
Modified:
karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java
karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
Modified: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java?rev=1545206&r1=1545205&r2=1545206&view=diff
==============================================================================
--- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java (original)
+++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/ScrServiceMBean.java Mon Nov 25 10:14:53 2013
@@ -16,6 +16,7 @@
*/
package org.apache.karaf.scr.management;
+import javax.management.MBeanException;
import javax.management.openmbean.TabularData;
/**
@@ -51,27 +52,26 @@ public interface ScrServiceMBean {
/**
* The item names in the CompositeData representing a component
*/
- String[] COMPONENT = { COMPONENT_ID, COMPONENT_NAME, COMPONENT_STATE,
- COMPONENT_PROPERTIES, COMPONENT_REFERENCES };
+ String[] COMPONENT = {COMPONENT_ID, COMPONENT_NAME, COMPONENT_STATE,
+ COMPONENT_PROPERTIES, COMPONENT_REFERENCES};
- String[] PROPERTY = { PROPERTY_KEY, PROPERTY_VALUE };
+ String[] PROPERTY = {PROPERTY_KEY, PROPERTY_VALUE};
- String[] REFERENCE = { REFERENCE_NAME, REFERENCE_SATISFIED, REFERENCE_CARDINALITY, REFERENCE_AVAILABILITY, REFERENCE_POLICY, REFERENCE_BOUND_SERVICES};
+ String[] REFERENCE = {REFERENCE_NAME, REFERENCE_SATISFIED, REFERENCE_CARDINALITY, REFERENCE_AVAILABILITY, REFERENCE_POLICY, REFERENCE_BOUND_SERVICES};
/**
* Displays a {@link TabularData} with all the component details.
+ *
* @return
- * @throws Exception
*/
- TabularData getComponents() throws Exception;
+ TabularData getComponents();
/**
* Presents a {@String} array of components currently registered with the SCR.
*
* @return String[]
- * @throws Exception
*/
- String[] listComponents() throws Exception;
+ String[] listComponents();
/**
* Verifies if the named component is currently in an ACTIVE state.
@@ -80,31 +80,28 @@ public interface ScrServiceMBean {
* @return true if ACTIVE, otherwise false
* @throws Exception
*/
- boolean isComponentActive(String componentName) throws Exception;
+ boolean isComponentActive(String componentName) throws MBeanException;
/**
* Returns the named components state
*
* @param componentName the components name
* @return
- * @throws Exception
*/
- int componentState(String componentName) throws Exception;
+ int componentState(String componentName);
/**
* Activates a component that is currently in a DISABLED state.
*
* @param componentName the components name
- * @throws Exception
*/
- void activateComponent(String componentName) throws Exception;
+ void activateComponent(String componentName);
/**
* Disables a component that is not in an ACTIVE state.
*
* @param componentName the components name
- * @throws Exception
*/
- void deactivateComponent(String componentName) throws Exception;
+ void deactivateComponent(String componentName);
}
Modified: karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java
URL: http://svn.apache.org/viewvc/karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java?rev=1545206&r1=1545205&r2=1545206&view=diff
==============================================================================
--- karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java (original)
+++ karaf/trunk/scr/management/src/main/java/org/apache/karaf/scr/management/internal/ScrServiceMBeanImpl.java Mon Nov 25 10:14:53 2013
@@ -21,10 +21,7 @@ import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
-import javax.management.MBeanServer;
-import javax.management.NotCompliantMBeanException;
-import javax.management.ObjectName;
-import javax.management.StandardMBean;
+import javax.management.*;
import javax.management.openmbean.TabularData;
import aQute.bnd.annotation.component.Activate;
@@ -43,15 +40,15 @@ import org.slf4j.LoggerFactory;
name = ScrServiceMBeanImpl.COMPONENT_NAME,
enabled = true,
immediate = true,
- properties = { "hidden.component=true" })
+ properties = {"hidden.component=true"})
public class ScrServiceMBeanImpl extends StandardMBean implements ScrServiceMBean {
-
+
public static final String OBJECT_NAME = "org.apache.karaf:type=scr,name=" + System.getProperty("karaf.name", "root");
public static final String COMPONENT_NAME = "ScrServiceMBean";
public static final String COMPONENT_LABEL = "Apache Karaf SCR Service MBean";
-
+
private static final Logger LOGGER = LoggerFactory.getLogger(ScrServiceMBeanImpl.class);
private MBeanServer mBeanServer;
@@ -61,8 +58,8 @@ public class ScrServiceMBeanImpl extends
private ReadWriteLock lock = new ReentrantReadWriteLock();
/**
- * Creates new Declarative Services mbean.
- *
+ * Creates new Declarative Services MBean.
+ *
* @throws NotCompliantMBeanException
*/
public ScrServiceMBeanImpl() throws NotCompliantMBeanException {
@@ -71,7 +68,7 @@ public class ScrServiceMBeanImpl extends
/**
* Service component activation call back. Called when all dependencies are satisfied.
- *
+ *
* @throws Exception
*/
@Activate
@@ -92,9 +89,9 @@ public class ScrServiceMBeanImpl extends
}
/**
- * Service component deactivation call back. Called after the component is in an active
+ * Service component deactivation call back. Called after the component is in an active
* state when any dependencies become unsatisfied.
- *
+ *
* @throws Exception
*/
@Deactivate
@@ -111,22 +108,16 @@ public class ScrServiceMBeanImpl extends
}
@Override
- public TabularData getComponents() throws Exception {
+ public TabularData getComponents() {
try {
- return JmxComponent.tableFrom(safe(scrService.getComponents()));
- }catch (Exception e) {
+ return JmxComponent.tableFrom(safe(scrService.getComponents()));
+ } catch (Exception e) {
e.printStackTrace(System.out);
return null;
}
}
- /*
- * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#listComponents()
- *
- * @return
- * @throws Exception
- */
- public String[] listComponents() throws Exception {
+ public String[] listComponents() {
Component[] components = safe(scrService.getComponents());
String[] componentNames = new String[components.length];
for (int i = 0; i < componentNames.length; i++) {
@@ -135,62 +126,40 @@ public class ScrServiceMBeanImpl extends
return componentNames;
}
- /*
- * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#isComponentActive(java.lang.String)
- *
- * @param componentName
- * @return
- * @throws Exception
- */
- public boolean isComponentActive(String componentName) throws Exception {
- return (componentState(componentName) == Component.STATE_ACTIVE)?true:false;
+ public boolean isComponentActive(String componentName) throws MBeanException {
+ try {
+ return (componentState(componentName) == Component.STATE_ACTIVE) ? true : false;
+ } catch (Exception e) {
+ throw new MBeanException(null, e.getMessage());
+ }
}
- /*
- * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#componentState(java.lang.String)
- *
- * @param componentName
- * @return
- * @throws Exception
- */
- public int componentState(String componentName) throws Exception {
+ public int componentState(String componentName) {
int state = -1;
final Component component = findComponent(componentName);
- if(component != null)
+ if (component != null)
state = component.getState();
else
LOGGER.warn("No component found for name: " + componentName);
return state;
}
- /*
- * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#activateComponent(java.lang.String)
- *
- * @param componentName
- * @throws Exception
- */
- public void activateComponent(String componentName) throws Exception {
+ public void activateComponent(String componentName) {
final Component component = findComponent(componentName);
- if(component != null)
+ if (component != null)
component.enable();
else
LOGGER.warn("No component found for name: " + componentName);
}
- /*
- * @see org.apache.karaf.management.mbeans.scr.ScrServiceMBean#deactiveateComponent(java.lang.String)
- *
- * @param componentName
- * @throws Exception
- */
- public void deactivateComponent(String componentName) throws Exception {
+ public void deactivateComponent(String componentName) {
final Component component = findComponent(componentName);
- if(component != null)
+ if (component != null)
component.disable();
else
LOGGER.warn("No component found for name: " + componentName);
}
-
+
private Component findComponent(String componentName) {
Component answer = null;
if (scrService.getComponents(componentName) != null) {
@@ -201,31 +170,25 @@ public class ScrServiceMBeanImpl extends
}
return answer;
}
-
- private Component[] safe( Component[] components ) {
+
+ private Component[] safe(Component[] components) {
return components == null ? new Component[0] : components;
}
- /**
- * @param mBeanServer the mBeanServer to set
- */
@Reference
- public void setmBeanServer(MBeanServer mBeanServer) {
- this.mBeanServer = mBeanServer;
- }
-
+ public void setmBeanServer(MBeanServer mBeanServer) {
+ this.mBeanServer = mBeanServer;
+ }
+
public void unsetmBeanServer(MBeanServer mBeanServer) {
this.mBeanServer = null;
}
- /**
- * @param scrService the scrService to set
- */
- @Reference
- public void setScrService(ScrService scrService) {
- this.scrService = scrService;
- }
-
+ @Reference
+ public void setScrService(ScrService scrService) {
+ this.scrService = scrService;
+ }
+
public void unsetScrService(ScrService scrService) {
this.scrService = null;
}