#1607 - Add support for configuration events.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818822 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java
index e07e6d1..ecfbf7b 100644
--- a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/ConfigurationListener.java
@@ -22,11 +22,13 @@
import java.util.Dictionary;
import java.util.Hashtable;
+import org.apache.felix.webconsole.plugins.event.internal.converter.ConfigurationEventConverter;
import org.osgi.framework.*;
+import org.osgi.service.cm.ConfigurationEvent;
import org.osgi.service.cm.ManagedService;
-public class ConfigurationListener implements ManagedService
+public class ConfigurationListener implements ManagedService, org.osgi.service.cm.ConfigurationListener
{
private final PluginServlet plugin;
@@ -41,7 +43,8 @@
props.put( Constants.SERVICE_DESCRIPTION, "Event plugin for the Felix Web Console Configuration Receiver" );
props.put( Constants.SERVICE_PID, cl.pid );
- return context.registerService( ManagedService.class.getName(), cl, props );
+ return context.registerService( new String[] {ManagedService.class.getName(),
+ org.osgi.service.cm.ConfigurationListener.class.getName()}, cl, props );
}
@@ -50,9 +53,21 @@
this.plugin = plugin;
this.pid = plugin.getClass().getName();
}
+ //---------- ConfigurationListener
+ /**
+ * @see org.osgi.service.cm.ConfigurationListener#configurationEvent(org.osgi.service.cm.ConfigurationEvent)
+ */
+ public void configurationEvent(ConfigurationEvent event)
+ {
+ this.plugin.getCollector().add(ConfigurationEventConverter.getInfo(event));
+
+ }
//---------- ManagedService
+ /**
+ * @see org.osgi.service.cm.ManagedService#updated(java.util.Dictionary)
+ */
public void updated( Dictionary config )
{
plugin.updateConfiguration( config );
diff --git a/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ConfigurationEventConverter.java b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ConfigurationEventConverter.java
new file mode 100644
index 0000000..f79543f
--- /dev/null
+++ b/webconsole-plugins/event/src/main/java/org/apache/felix/webconsole/plugins/event/internal/converter/ConfigurationEventConverter.java
@@ -0,0 +1,58 @@
+/*
+ * 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.webconsole.plugins.event.internal.converter;
+
+import org.apache.felix.webconsole.plugins.event.internal.EventInfo;
+import org.osgi.service.cm.ConfigurationEvent;
+
+public class ConfigurationEventConverter {
+
+ public static final String TOPIC = ConfigurationEventConverter.class.getName().replace('.', '/');
+
+ public static EventInfo getInfo(final ConfigurationEvent event) {
+ if ( event == null )
+ {
+ return null;
+ }
+
+ final StringBuffer topic = new StringBuffer(TOPIC);
+ topic.append('/');
+ final StringBuffer buffer = new StringBuffer( "Configuration event: " );
+ buffer.append(event.getPid());
+ if ( event.getFactoryPid() != null )
+ {
+ buffer.append(" (factoryPid=");
+ buffer.append(event.getFactoryPid());
+ buffer.append(")");
+ }
+ switch ( event.getType() )
+ {
+ case ConfigurationEvent.CM_DELETED:
+ buffer.append( " deleted" );
+ topic.append( "CM_DELETED" );
+ break;
+ case ConfigurationEvent.CM_UPDATED:
+ buffer.append( " changed" );
+ topic.append( "CM_UPDATED" );
+ break;
+ default:
+ return null; // IGNORE
+ }
+
+ return new EventInfo(topic.toString(), buffer.toString(), "config");
+ }
+}