FELIX-2349: JMX notifications
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@952712 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/features/management/pom.xml b/karaf/features/management/pom.xml
index c5d8020..82da799 100644
--- a/karaf/features/management/pom.xml
+++ b/karaf/features/management/pom.xml
@@ -70,6 +70,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.felix.karaf</groupId>
+ <artifactId>org.apache.felix.karaf.management</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.springframework.osgi</groupId>
<artifactId>spring-osgi-core</artifactId>
<scope>test</scope>
diff --git a/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/FeaturesServiceMBeanImpl.java b/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
index c7b37b4..f7b49de 100644
--- a/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
+++ b/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/FeaturesServiceMBeanImpl.java
@@ -13,39 +13,40 @@
*/
package org.apache.felix.karaf.features.management.internal;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.net.URI;
+import javax.management.MBeanNotificationInfo;
import javax.management.MBeanRegistration;
import javax.management.MBeanServer;
+import javax.management.Notification;
import javax.management.NotificationBroadcasterSupport;
import javax.management.ObjectName;
-import javax.management.Notification;
+import javax.management.StandardEmitterMBean;
import javax.management.openmbean.TabularData;
+import org.apache.felix.karaf.features.Feature;
+import org.apache.felix.karaf.features.FeatureEvent;
+import org.apache.felix.karaf.features.FeaturesListener;
+import org.apache.felix.karaf.features.FeaturesService;
+import org.apache.felix.karaf.features.Repository;
+import org.apache.felix.karaf.features.RepositoryEvent;
import org.apache.felix.karaf.features.management.FeaturesServiceMBean;
import org.apache.felix.karaf.features.management.codec.JmxFeature;
import org.apache.felix.karaf.features.management.codec.JmxFeatureEvent;
import org.apache.felix.karaf.features.management.codec.JmxRepository;
import org.apache.felix.karaf.features.management.codec.JmxRepositoryEvent;
-import org.apache.felix.karaf.features.FeaturesListener;
-import org.apache.felix.karaf.features.FeatureEvent;
-import org.apache.felix.karaf.features.RepositoryEvent;
-import org.apache.felix.karaf.features.FeaturesService;
-import org.apache.felix.karaf.features.Feature;
-import org.apache.felix.karaf.features.Repository;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceRegistration;
/**
- *
+ * Implementation of {@link FeaturesServiceMBean}.
*/
-
-public class FeaturesServiceMBeanImpl extends NotificationBroadcasterSupport
- implements MBeanRegistration, FeaturesServiceMBean {
+public class FeaturesServiceMBeanImpl extends StandardEmitterMBean implements
+ MBeanRegistration, FeaturesServiceMBean {
private ServiceRegistration registration;
@@ -59,50 +60,31 @@
private FeaturesService featuresService;
- /*
- * (non-Javadoc)
- *
- * @see javax.management.MBeanRegistration#preRegister(javax.manamement.MBeanServer, javax.management.ObjectName)
- */
- public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
- objectName = name;
- this.server = server;
- return name;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
- */
- public void postRegister(Boolean registrationDone) {
- registration = bundleContext.registerService(
- FeaturesListener.class.getName(),
- getFeaturesListener(),
- new Hashtable());
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.management.MBeanRegistration#preDeregister()
- */
- public void preDeregister() throws Exception {
- registration.unregister();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see javax.management.MBeanRegistration#postDeregister()
- */
- public void postDeregister() {
+ public FeaturesServiceMBeanImpl() {
+ super(FeaturesServiceMBean.class, new NotificationBroadcasterSupport(
+ getBroadcastInfo()));
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.felix.karaf.features.management.FeaturesServiceMBean#getFeatures()
+ @Override
+ public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
+ objectName = name;
+ this.server = server;
+ return name;
+ }
+
+ @Override
+ public void postRegister(Boolean registrationDone) {
+ registration = bundleContext.registerService(FeaturesListener.class.getName(),
+ getFeaturesListener(), new Hashtable());
+ }
+
+ @Override
+ public void preDeregister() throws Exception {
+ registration.unregister();
+ }
+
+ /**
+ * {@inheritDoc}
*/
public TabularData getFeatures() throws Exception {
try {
@@ -120,10 +102,8 @@
}
}
- /*
- * (non-Javadoc)
- *
- * @see org.apache.felix.karaf.features.management.FeaturesServiceMBean#getRepositories()
+ /**
+ * {@inheritDoc}
*/
public TabularData getRepositories() throws Exception {
try {
@@ -191,4 +171,14 @@
};
}
+
+ private static MBeanNotificationInfo[] getBroadcastInfo() {
+ String type = Notification.class.getCanonicalName();
+ MBeanNotificationInfo info1 = new MBeanNotificationInfo(new String[] {FEATURE_EVENT_EVENT_TYPE},
+ type, "Some features notification");
+ MBeanNotificationInfo info2 = new MBeanNotificationInfo(new String[] {REPOSITORY_EVENT_EVENT_TYPE},
+ type, "Some repository notification");
+ return new MBeanNotificationInfo[] {info1, info2};
+ }
+
}
\ No newline at end of file
diff --git a/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java b/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
deleted file mode 100644
index 1dbac81..0000000
--- a/karaf/features/management/src/main/java/org/apache/felix/karaf/features/management/internal/MBeanRegistrer.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You 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.apache.felix.karaf.features.management.internal;
-
-import java.util.Map;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import javax.management.MBeanRegistrationException;
-import javax.management.InstanceNotFoundException;
-import javax.management.MalformedObjectNameException;
-import javax.management.NotCompliantMBeanException;
-import javax.management.InstanceAlreadyExistsException;
-import javax.management.JMException;
-
-public class MBeanRegistrer {
-
- private MBeanServer mbeanServer;
-
- private Map<Object, String> mbeans;
-
- public void setMbeans(Map<Object, String> mbeans) {
- this.mbeans = mbeans;
- }
-
- public void registerMBeanServer(MBeanServer mbeanServer) throws JMException {
- if (this.mbeanServer != mbeanServer) {
- unregisterMBeans();
- }
- this.mbeanServer = mbeanServer;
- registerMBeans();
- }
-
- public void unregisterMBeanServer(MBeanServer mbeanServer) throws JMException {
- unregisterMBeans();
- this.mbeanServer = null;
- }
-
- public void init() throws Exception {
- registerMBeans();
- }
-
- protected void registerMBeans() throws JMException {
- if (mbeanServer != null && mbeans != null) {
- for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
- String value = parseProperty(entry.getValue());
- mbeanServer.registerMBean(entry.getKey(), new ObjectName(value));
- }
- }
- }
-
- protected void unregisterMBeans() throws JMException {
- if (mbeanServer != null && mbeans != null) {
- for (Map.Entry<Object, String> entry : mbeans.entrySet()) {
- String value = parseProperty(entry.getValue());
- mbeanServer.unregisterMBean(new ObjectName(value));
- }
- }
- }
-
- protected String parseProperty(String raw) {
- if (raw.indexOf("${") > -1 && raw.indexOf("}", raw.indexOf("${")) > -1) {
- String var = raw.substring(raw.indexOf("${") + 2, raw.indexOf("}"));
- String val = System.getProperty(var);
- if (val != null) {
- raw = raw.replace("${" + var + "}", val);
- }
- }
- return raw;
- }
-}
diff --git a/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml b/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
index 0d0626b..b8b221f 100644
--- a/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
+++ b/karaf/features/management/src/main/resources/OSGI-INF/blueprint/features-management.xml
@@ -31,18 +31,11 @@
<property name="featuresService" ref="featuresService" />
</bean>
- <bean id="mbeanRegister" class="org.apache.felix.karaf.features.management.internal.MBeanRegistrer">
+ <bean id="mbeanRegister" class="org.apache.felix.karaf.management.MBeanRegistrer">
<property name="mbeans">
<map>
- <entry>
- <key>
- <bean class="javax.management.StandardMBean">
- <argument ref="mbeanImpl" />
- <argument value="org.apache.felix.karaf.features.management.FeaturesServiceMBean"/>
- </bean>
- </key>
- <value>org.apache.felix.karaf:type=features,name=${karaf.name}</value>
- </entry>
+ <entry value="org.apache.felix.karaf:type=features,name=${karaf.name}"
+ key-ref="mbeanImpl" />
</map>
</property>
</bean>