karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject [1/2] karaf-decanter git commit: [KARAF-4344] Migrating to DS
Date Thu, 18 Feb 2016 11:11:17 GMT
Repository: karaf-decanter
Updated Branches:
  refs/heads/master aa0685b1c -> 18e8b297d


http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
----------------------------------------------------------------------
diff --git a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
index 81f22b9..6453cd4 100644
--- a/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
+++ b/collector/file/src/main/java/org/apache/karaf/decanter/collector/file/DecanterTailerListener.java
@@ -16,18 +16,29 @@
  */
 package org.apache.karaf.decanter.collector.file;
 
-import org.apache.commons.io.input.TailerListenerAdapter;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
+import java.io.File;
 import java.net.InetAddress;
 import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
 
+import org.apache.commons.io.input.Tailer;
+import org.apache.commons.io.input.TailerListenerAdapter;
+import org.osgi.service.cm.ConfigurationException;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    name="org.apache.karaf.decanter.collector.file",
+    immediate = true
+)
 public class DecanterTailerListener extends TailerListenerAdapter {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(DecanterTailerListener.class);
@@ -35,20 +46,37 @@ public class DecanterTailerListener extends TailerListenerAdapter {
     private String type;
     private String path;
     private EventAdmin eventAdmin;
-    private Dictionary<String, Object> properties;
-
+    
     /**
-     * 
-     * @param type
-     * @param path
-     * @param eventAdmin
-     * @param properties additional properties provided by the user
+     * additional properties provided by the user
      */
-    public DecanterTailerListener(String type, String path, EventAdmin eventAdmin, Dictionary<String, Object> properties) {
+    private Dictionary<String, Object> properties;
+    private Tailer tailer;
+
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void activate(ComponentContext context) throws ConfigurationException {
+        properties = context.getProperties();
+        if (properties.get("type") == null) {
+            throw new ConfigurationException("type","type property is mandatory");
+        }
+        String type = (String) properties.get("type");
+        if (properties.get("path") == null) {
+            throw new ConfigurationException("path", "path property is mandatory");
+        }
+        String path = (String) properties.get("path");
+
+        LOGGER.debug("Starting tail on {}", path);
+        tailer = new Tailer(new File(path), this);
+        Thread thread = new Thread(tailer, "Log Tailer for " + path);
+        thread.start();
         this.type = type;
         this.path = path;
-        this.eventAdmin = eventAdmin;
-        this.properties = properties;
+    }
+    
+    @Deactivate
+    public void deactivate() {
+        tailer.stop();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/jmx/pom.xml
----------------------------------------------------------------------
diff --git a/collector/jmx/pom.xml b/collector/jmx/pom.xml
index 4c5eed5..7c159dc 100644
--- a/collector/jmx/pom.xml
+++ b/collector/jmx/pom.xml
@@ -40,7 +40,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.collector.jmx.Activator</Bundle-Activator>
                         <Private-Package>org.apache.karaf.decanter.collector.jmx</Private-Package>
                     </instructions>
                 </configuration>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/Activator.java
----------------------------------------------------------------------
diff --git a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/Activator.java b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/Activator.java
deleted file mode 100644
index 6169780..0000000
--- a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/Activator.java
+++ /dev/null
@@ -1,123 +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.karaf.decanter.collector.jmx;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.osgi.framework.*;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("rawtypes")
-public class Activator implements BundleActivator {
-
-    private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-
-    private ServiceTracker<EventAdmin, ServiceRegistration> tracker;
-
-    public void start(final BundleContext bundleContext) throws Exception {
-        tracker = new ServiceTracker<EventAdmin, ServiceRegistration>(bundleContext, EventAdmin.class, null) {
-
-            @Override
-            public ServiceRegistration<?> addingService(ServiceReference<EventAdmin> reference) {
-                EventAdmin eventAdmin = bundleContext.getService(reference);
-                ConfigManager configManager = new ConfigManager(eventAdmin, bundleContext);
-                Hashtable<String, Object> properties = new Hashtable<String, Object>();
-                properties.put(Constants.SERVICE_PID, "org.apache.karaf.decanter.collector.jmx");
-                return bundleContext.registerService(ManagedServiceFactory.class, configManager, properties);
-            }
-
-            @Override
-            public void removedService(ServiceReference<EventAdmin> reference, ServiceRegistration reg) {
-                reg.unregister();
-                super.removedService(reference, reg);
-            }
-            
-        };
-        tracker.open();
-    }
-
-    public void stop(BundleContext bundleContext) throws Exception {
-        tracker.close();
-    }
-
-    private final class ConfigManager implements ManagedServiceFactory {
-
-        private final Map<String, ServiceRegistration> registrations = new ConcurrentHashMap<String, ServiceRegistration>();
-
-        private EventAdmin eventAdmin;
-        private BundleContext bundleContext;
-
-        public ConfigManager(EventAdmin eventAdmin, BundleContext bundleContext) {
-            this.eventAdmin = eventAdmin;
-            this.bundleContext = bundleContext;
-        }
-
-        @Override
-        public String getName() {
-            return "Karaf Decanter JMX collector service factory";
-        }
-
-        @SuppressWarnings("unchecked")
-        @Override
-        public void updated(String pid, Dictionary properties) throws ConfigurationException {
-            LOGGER.debug("Updating JMX collector {}", pid);
-            ServiceRegistration registration = null;
-            try {
-                if (properties != null) {
-                    String type = getProperty(properties, "type", "jmx-local");
-                    String url = getProperty(properties, "url", "local");
-                    String username = getProperty(properties, "username", null);
-                    String password = getProperty(properties, "password", null);
-                    String objectName = getProperty(properties, "object.name", null);
-                    JmxCollector collector = new JmxCollector(type, url, username, password, objectName, eventAdmin, properties);
-                    Dictionary<String, String> serviceProperties = new Hashtable<String, String>();
-                    serviceProperties.put("decanter.collector.name", type);
-                    registration = bundleContext.registerService(Runnable.class, collector, serviceProperties);
-                }
-            } finally {
-                ServiceRegistration oldRegistration = (registration == null) ? registrations.remove(pid) : registrations.put(pid, registration);
-                if (oldRegistration != null) {
-                    LOGGER.debug("Unregistering Decanter JMX collector {}", pid);
-                    oldRegistration.unregister();
-                }
-            }
-        }
-
-        private String getProperty(Dictionary properties, String key, String defaultValue) {
-            return (properties.get(key) != null) ? (String) properties.get(key) : defaultValue;
-        }
-
-        @Override
-        public void deleted(String pid) {
-            LOGGER.debug("Deleting JMX collector {}", pid);
-            ServiceRegistration registration = registrations.remove(pid);
-            if (registration != null) {
-                registration.unregister();
-            }
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
----------------------------------------------------------------------
diff --git a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
index 2729658..5af10b4 100644
--- a/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
+++ b/collector/jmx/src/main/java/org/apache/karaf/decanter/collector/jmx/JmxCollector.java
@@ -26,6 +26,9 @@ import javax.management.remote.JMXConnector;
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
@@ -34,6 +37,11 @@ import org.slf4j.LoggerFactory;
 /**
  * Decanter JMX Pooling Collector
  */
+@Component(
+    name = "org.apache.karaf.decanter.collector.jmx",
+    immediate = true,
+    property = "decanter.collector.name=jmx"
+)
 public class JmxCollector implements Runnable {
     private final static Logger LOGGER = LoggerFactory.getLogger(JmxCollector.class);
 
@@ -43,16 +51,27 @@ public class JmxCollector implements Runnable {
     private String password;
     private String objectName;
     private EventAdmin eventAdmin;
-    private Dictionary<String, String> properties;
-
-    public JmxCollector(String type, String url, String username, String password, String objectName, EventAdmin eventAdmin, Dictionary<String, String> properties) {
+    private Dictionary<String, Object> properties;
+
+    @SuppressWarnings("unchecked")
+    public void activate(ComponentContext context) {
+        properties = context.getProperties();
+        String type = getProperty(properties, "type", "jmx-local");
+        String url = getProperty(properties, "url", "local");
+        String username = getProperty(properties, "username", null);
+        String password = getProperty(properties, "password", null);
+        String objectName = getProperty(properties, "object.name", null);
+        Dictionary<String, String> serviceProperties = new Hashtable<String, String>();
+        serviceProperties.put("decanter.collector.name", type);
         this.type = type;
         this.url = url;
         this.username = username;
         this.password = password;
-        this.eventAdmin = eventAdmin;
         this.objectName = objectName;
-        this.properties = properties;
+    }
+    
+    private String getProperty(Dictionary<String, Object> properties, String key, String defaultValue) {
+        return (properties.get(key) != null) ? (String) properties.get(key) : defaultValue;
     }
 
     @Override
@@ -135,4 +154,8 @@ public class JmxCollector implements Runnable {
         return name.getDomain().replace(".", "/").replace(" ", "_");
     }
 
+    @Reference
+    public void setEventAdmin(EventAdmin eventAdmin) {
+        this.eventAdmin = eventAdmin;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log/pom.xml
----------------------------------------------------------------------
diff --git a/collector/log/pom.xml b/collector/log/pom.xml
index 19abe0f..d169587 100644
--- a/collector/log/pom.xml
+++ b/collector/log/pom.xml
@@ -48,7 +48,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.collector.log.Activator</Bundle-Activator>
                         <Private-Package>org.apache.karaf.decanter.collector.log</Private-Package>
                     </instructions>
                 </configuration>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/Activator.java
----------------------------------------------------------------------
diff --git a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/Activator.java b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/Activator.java
deleted file mode 100644
index f1a581d..0000000
--- a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/Activator.java
+++ /dev/null
@@ -1,62 +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.karaf.decanter.collector.log;
-
-import java.util.Dictionary;
-import java.util.Properties;
-
-import org.ops4j.pax.logging.spi.PaxAppender;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-@SuppressWarnings("rawtypes")
-public class Activator implements BundleActivator {
-    private ServiceTracker<EventAdmin, ServiceRegistration> tracker;
-
-    public void start(final BundleContext bundleContext) {
-        tracker = new ServiceTracker<EventAdmin, ServiceRegistration>(bundleContext, EventAdmin.class, null) {
-
-            @SuppressWarnings("unchecked")
-            @Override
-            public ServiceRegistration<?> addingService(ServiceReference<EventAdmin> reference) {
-                Properties properties = new Properties();
-                properties.put("org.ops4j.pax.logging.appender.name", "DecanterLogCollectorAppender");
-                properties.put("name", "log");
-                EventAdmin eventAdmin = bundleContext.getService(reference);
-                LogAppender appender = new LogAppender(eventAdmin);
-                return bundleContext.registerService(PaxAppender.class , appender, (Dictionary) properties);
-            }
-
-            @Override
-            public void removedService(ServiceReference<EventAdmin> reference, ServiceRegistration reg) {
-                reg.unregister();
-                super.removedService(reference, reg);
-            }
-            
-        };
-        tracker.open();
-    }
-
-    public void stop(BundleContext bundleContext) {
-        tracker.close();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
----------------------------------------------------------------------
diff --git a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
index ab3a3f0..9fa8be8 100644
--- a/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
+++ b/collector/log/src/main/java/org/apache/karaf/decanter/collector/log/LogAppender.java
@@ -24,6 +24,8 @@ import org.apache.log4j.MDC;
 import org.ops4j.pax.logging.spi.PaxAppender;
 import org.ops4j.pax.logging.spi.PaxLocationInfo;
 import org.ops4j.pax.logging.spi.PaxLoggingEvent;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
@@ -32,16 +34,18 @@ import org.slf4j.LoggerFactory;
 /**
  * Decanter log collector, event driven implementing a PaxAppender
  */
+@Component(
+    name = "org.apache.karaf.decanter.collector.log",
+    property = {"org.ops4j.pax.logging.appender.name=DecanterLogCollectorAppender",
+              "name=log"},
+    immediate = true
+)
 public class LogAppender implements PaxAppender {
     private static final String MDC_IN_LOG_APPENDER = "inLogAppender";
     private final static String[] ignoredCategories = {"org.apache.karaf.decanter"};
     private final static Logger LOGGER = LoggerFactory.getLogger(LogAppender.class);
     private EventAdmin dispatcher;
     
-    public LogAppender(EventAdmin dispatcher) {
-        this.dispatcher = dispatcher;
-    }
-
     public void doAppend(PaxLoggingEvent event) {
         try {
             if (MDC.get(MDC_IN_LOG_APPENDER) != null) {
@@ -114,4 +118,8 @@ public class LogAppender implements PaxAppender {
         return false;
     }
 
+    @Reference
+    public void setDispatcher(EventAdmin dispatcher) {
+        this.dispatcher = dispatcher;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/pom.xml
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/pom.xml b/collector/log4j-socket/pom.xml
index 669edbf..3acf0be 100644
--- a/collector/log4j-socket/pom.xml
+++ b/collector/log4j-socket/pom.xml
@@ -67,12 +67,12 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.appender.log.socket.Activator</Bundle-Activator>
                         <Import-Package>
                             !com.ibm.uvm.tools,
                             *
                         </Import-Package>
                         <Private-Package>
+                            org.apache.karaf.decanter.collector.log.socket,
                             org.apache.log4j.spi,
                             org.apache.log4j.helpers,
                             org.apache.log4j.or,

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/Activator.java
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/Activator.java b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/Activator.java
deleted file mode 100644
index 1b5b316..0000000
--- a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/Activator.java
+++ /dev/null
@@ -1,105 +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.karaf.decanter.appender.log.socket;
-
-import java.io.IOException;
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("rawtypes")
-public class Activator implements BundleActivator {
-    private final static Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-    private ServiceTracker<EventAdmin, ServiceRegistration> tracker;
-
-    @Override
-    public void start(final BundleContext bundleContext) throws Exception {
-        tracker = new ServiceTracker<EventAdmin, ServiceRegistration>(bundleContext, EventAdmin.class, null) {
-
-            @Override
-            public ServiceRegistration<?> addingService(ServiceReference<EventAdmin> reference) {
-                EventAdmin eventAdmin = bundleContext.getService(reference);
-                ConfigManager configManager = new ConfigManager(eventAdmin);
-                Hashtable<String, Object> properties = new Hashtable<String, Object>();
-                properties.put(Constants.SERVICE_PID, "org.apache.karaf.decanter.collector.log.socket");
-                return bundleContext.registerService(ManagedService.class, configManager, properties);
-            }
-
-            @Override
-            public void removedService(ServiceReference<EventAdmin> reference, ServiceRegistration reg) {
-                reg.unregister();
-                super.removedService(reference, reg);
-            }
-            
-        };
-        tracker.open();
-    }
-    public void stop(BundleContext bundleContext) throws Exception {
-        tracker.close();
-    }
-
-    private final class ConfigManager implements ManagedService {
-        private EventAdmin eventAdmin;
-        private SocketCollector collector;
-
-        public ConfigManager(EventAdmin eventAdmin) {
-            this.eventAdmin = eventAdmin;
-        }
-
-        @Override
-        public void updated(Dictionary properties) throws ConfigurationException {
-            close();
-            try {
-                if (properties != null) {
-                    int port = Integer.parseInt(getProperty(properties, "port", "4560"));
-                    LOGGER.info("Starting Log4j Socket collector on port {}", port);
-                    collector = new SocketCollector(port, eventAdmin);
-                }
-            } catch (IOException e) {
-                throw new ConfigurationException(null, "Error creating SocketCollector", e); 
-            }
-        }
-
-        private String getProperty(Dictionary properties, String key, String defaultValue) {
-            return (properties.get(key) != null) ? (String) properties.get(key) : defaultValue;
-        }
-
-        private void close() {
-            if (collector != null) {
-                try {
-                    LOGGER.info("Stopping log socket collector.");
-                    collector.close();
-                } catch (IOException e) {
-                    LOGGER.warn("Error closing SocketCollector", e);
-                }
-                collector = null;
-            }
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/SocketCollector.java
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/SocketCollector.java b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/SocketCollector.java
deleted file mode 100644
index 54ee53c..0000000
--- a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/appender/log/socket/SocketCollector.java
+++ /dev/null
@@ -1,156 +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.karaf.decanter.appender.log.socket;
-
-import java.io.BufferedInputStream;
-import java.io.Closeable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.net.InetAddress;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.UnknownHostException;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.log4j.spi.LocationInfo;
-import org.apache.log4j.spi.LoggingEvent;
-import org.osgi.service.event.Event;
-import org.osgi.service.event.EventAdmin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class SocketCollector implements Closeable, Runnable {
-    private static final Logger LOGGER = LoggerFactory.getLogger(SocketCollector.class);
-    private ServerSocket serverSocket;
-    private EventAdmin eventAdmin;
-    private boolean open;
-    private ExecutorService executor;
-
-    public SocketCollector(int port, EventAdmin eventAdmin) throws IOException {
-        this.eventAdmin = eventAdmin;
-        this.serverSocket = new ServerSocket(port);
-        this.executor = Executors.newFixedThreadPool(1);
-        this.executor.execute(this);
-        this.open = true;
-    }
-
-    @Override
-    public void run() {
-        while (open) {
-            try (Socket socket = serverSocket.accept();
-                ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(socket
-                    .getInputStream()));) {
-                while (open) {
-                    try {
-                        Object event = ois.readObject();
-                        if (event instanceof LoggingEvent) {
-                            handleLog4j((LoggingEvent)event);
-                        }
-                    } catch (ClassNotFoundException e) {
-                        LOGGER.warn("Unable to deserialize event from " + socket.getInetAddress(), e);
-                    }
-                }
-            } catch (IOException e) {
-                LOGGER.warn("Exception receiving log.", e);
-            }
-        }
-    }
-
-    private void handleLog4j(LoggingEvent event) throws UnknownHostException {
-        Map<String, Object> data = new HashMap<>();
-        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
-        data.put("hostName", InetAddress.getLocalHost().getHostName());
-        data.put("timeStamp", event.getTimeStamp());
-        data.put("loggerClass", event.getFQNOfLoggerClass());
-        data.put("loggerName", event.getLoggerName());
-        data.put("threadName", event.getThreadName());
-        data.put("message", event.getMessage());
-        data.put("level", event.getLevel().toString());
-        data.put("renderedMessage", event.getRenderedMessage());
-        data.put("MDC", event.getProperties());
-        putLocation(data, event.getLocationInformation());
-        String[] throwableAr = event.getThrowableStrRep();
-        if (throwableAr != null) {
-            data.put("throwable", join(throwableAr));
-        }
-        sendEvent(event.getLoggerName(), data);
-    }
-
-    private void sendEvent(String loggerName, Map<String, Object> data) {
-        String topic = loggerName2Topic(loggerName);
-        data.put("type", "log");
-        String karafName = System.getProperty("karaf.name");
-        if (karafName != null) {
-            data.put("karafName", karafName);
-        }
-        Event event = new Event(topic, data);
-        eventAdmin.postEvent(event);
-    }
-
-    static String loggerName2Topic(String loggerName) {
-        StringBuilder out = new StringBuilder();
-        for (int c=0; c<loggerName.length(); c++) {
-            Character ch = loggerName.charAt(c);
-            if (Character.isDigit(ch) || Character.isLowerCase(ch) || Character.isUpperCase(ch)) {
-                out.append(ch);
-            } else if (ch == '.') {
-                out.append("/");
-            }
-        }
-        String outSt = out.toString();
-        while (outSt.length() > 1 && outSt.endsWith("/")) {
-            outSt = outSt.substring(0, outSt.length() - 1);
-        }
-        return "decanter/collect/log/" + outSt.replace(".", "/");
-    }
-    
-    private void putLocation(Map<String, Object> data, LocationInfo loc) {
-        data.put("loc.class", loc.getClassName());
-        data.put("loc.file", loc.getFileName());
-        data.put("loc.line", loc.getLineNumber());
-        data.put("loc.method", loc.getMethodName());
-    }
-
-    private Object join(String[] throwableAr) {
-        StringBuilder builder = new StringBuilder();
-        for (String line : throwableAr) {
-            builder.append(line).append("\n");
-        }
-        return builder.toString();
-    }
-
-    @Override
-    public void close() throws IOException {
-        try {
-            this.executor.shutdown();
-            try {
-                this.executor.awaitTermination(2, TimeUnit.SECONDS);
-            } catch (InterruptedException e) {
-                // Ignore
-            }
-            this.executor.shutdownNow();
-        } catch (Exception e) {
-            LOGGER.warn("Error shutting down Socket");
-        }
-        serverSocket.close();
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
new file mode 100644
index 0000000..5306136
--- /dev/null
+++ b/collector/log4j-socket/src/main/java/org/apache/karaf/decanter/collector/log/socket/SocketCollector.java
@@ -0,0 +1,178 @@
+/*
+ * 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.karaf.decanter.collector.log.socket;
+
+import java.io.BufferedInputStream;
+import java.io.Closeable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.net.InetAddress;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.UnknownHostException;
+import java.util.Dictionary;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.log4j.spi.LocationInfo;
+import org.apache.log4j.spi.LoggingEvent;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventAdmin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Component(
+    name = "org.apache.karaf.decanter.collector.log.socket",
+    immediate = true
+)
+public class SocketCollector implements Closeable, Runnable {
+    private static final Logger LOGGER = LoggerFactory.getLogger(SocketCollector.class);
+    private ServerSocket serverSocket;
+    private EventAdmin eventAdmin;
+    private boolean open;
+    private ExecutorService executor;
+
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void activate(ComponentContext context) throws IOException {
+        Dictionary<String, Object> properties = context.getProperties();
+        int port = Integer.parseInt(getProperty(properties, "port", "4560"));
+        LOGGER.info("Starting Log4j Socket collector on port {}", port);
+        this.serverSocket = new ServerSocket(port);
+        this.executor = Executors.newFixedThreadPool(1);
+        this.executor.execute(this);
+        this.open = true;
+    }
+    
+    private String getProperty(Dictionary<String, Object> properties, String key, String defaultValue) {
+        return (properties.get(key) != null) ? (String) properties.get(key) : defaultValue;
+    }
+
+    @Override
+    public void run() {
+        while (open) {
+            try (Socket socket = serverSocket.accept();
+                ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(socket
+                    .getInputStream()));) {
+                while (open) {
+                    try {
+                        Object event = ois.readObject();
+                        if (event instanceof LoggingEvent) {
+                            handleLog4j((LoggingEvent)event);
+                        }
+                    } catch (ClassNotFoundException e) {
+                        LOGGER.warn("Unable to deserialize event from " + socket.getInetAddress(), e);
+                    }
+                }
+            } catch (IOException e) {
+                LOGGER.warn("Exception receiving log.", e);
+            }
+        }
+    }
+
+    private void handleLog4j(LoggingEvent event) throws UnknownHostException {
+        Map<String, Object> data = new HashMap<>();
+        data.put("hostAddress", InetAddress.getLocalHost().getHostAddress());
+        data.put("hostName", InetAddress.getLocalHost().getHostName());
+        data.put("timeStamp", event.getTimeStamp());
+        data.put("loggerClass", event.getFQNOfLoggerClass());
+        data.put("loggerName", event.getLoggerName());
+        data.put("threadName", event.getThreadName());
+        data.put("message", event.getMessage());
+        data.put("level", event.getLevel().toString());
+        data.put("renderedMessage", event.getRenderedMessage());
+        data.put("MDC", event.getProperties());
+        putLocation(data, event.getLocationInformation());
+        String[] throwableAr = event.getThrowableStrRep();
+        if (throwableAr != null) {
+            data.put("throwable", join(throwableAr));
+        }
+        sendEvent(event.getLoggerName(), data);
+    }
+
+    private void sendEvent(String loggerName, Map<String, Object> data) {
+        String topic = loggerName2Topic(loggerName);
+        data.put("type", "log");
+        String karafName = System.getProperty("karaf.name");
+        if (karafName != null) {
+            data.put("karafName", karafName);
+        }
+        Event event = new Event(topic, data);
+        eventAdmin.postEvent(event);
+    }
+
+    static String loggerName2Topic(String loggerName) {
+        StringBuilder out = new StringBuilder();
+        for (int c=0; c<loggerName.length(); c++) {
+            Character ch = loggerName.charAt(c);
+            if (Character.isDigit(ch) || Character.isLowerCase(ch) || Character.isUpperCase(ch)) {
+                out.append(ch);
+            } else if (ch == '.') {
+                out.append("/");
+            }
+        }
+        String outSt = out.toString();
+        while (outSt.length() > 1 && outSt.endsWith("/")) {
+            outSt = outSt.substring(0, outSt.length() - 1);
+        }
+        return "decanter/collect/log/" + outSt.replace(".", "/");
+    }
+    
+    private void putLocation(Map<String, Object> data, LocationInfo loc) {
+        data.put("loc.class", loc.getClassName());
+        data.put("loc.file", loc.getFileName());
+        data.put("loc.line", loc.getLineNumber());
+        data.put("loc.method", loc.getMethodName());
+    }
+
+    private Object join(String[] throwableAr) {
+        StringBuilder builder = new StringBuilder();
+        for (String line : throwableAr) {
+            builder.append(line).append("\n");
+        }
+        return builder.toString();
+    }
+
+    @Override
+    public void close() throws IOException {
+        try {
+            this.executor.shutdown();
+            try {
+                this.executor.awaitTermination(2, TimeUnit.SECONDS);
+            } catch (InterruptedException e) {
+                // Ignore
+            }
+            this.executor.shutdownNow();
+        } catch (Exception e) {
+            LOGGER.warn("Error shutting down Socket");
+        }
+        serverSocket.close();
+    }
+    
+    @Reference
+    public void setEventAdmin(EventAdmin eventAdmin) {
+        this.eventAdmin = eventAdmin;
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/appender/log/socket/SocketCollectorTest.java
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/appender/log/socket/SocketCollectorTest.java b/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/appender/log/socket/SocketCollectorTest.java
deleted file mode 100644
index 1473824..0000000
--- a/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/appender/log/socket/SocketCollectorTest.java
+++ /dev/null
@@ -1,30 +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.karaf.decanter.appender.log.socket;
-
-import org.junit.Assert;
-import org.junit.Test;
-
-public class SocketCollectorTest  {
-
-    @Test
-    public void testLoggerName2Topic() {
-        String topic = SocketCollector.loggerName2Topic("test.[Tomcat].[localhost].[/]");
-        Assert.assertEquals("decanter/collect/log/test/Tomcat/localhost", topic);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/collector/log/socket/SocketCollectorTest.java
----------------------------------------------------------------------
diff --git a/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/collector/log/socket/SocketCollectorTest.java b/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/collector/log/socket/SocketCollectorTest.java
new file mode 100644
index 0000000..b20bd08
--- /dev/null
+++ b/collector/log4j-socket/src/test/java/org/apache/karaf/decanter/collector/log/socket/SocketCollectorTest.java
@@ -0,0 +1,31 @@
+/*
+ * 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.karaf.decanter.collector.log.socket;
+
+import org.apache.karaf.decanter.collector.log.socket.SocketCollector;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class SocketCollectorTest  {
+
+    @Test
+    public void testLoggerName2Topic() {
+        String topic = SocketCollector.loggerName2Topic("test.[Tomcat].[localhost].[/]");
+        Assert.assertEquals("decanter/collect/log/test/Tomcat/localhost", topic);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
----------------------------------------------------------------------
diff --git a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
index 064feb6..9c2b078 100644
--- a/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
+++ b/collector/rest/src/main/java/org/apache/karaf/decanter/collector/rest/RestCollector.java
@@ -37,8 +37,10 @@ import org.slf4j.LoggerFactory;
  * Decanter REST Collector
  */
 @Component(
-    configurationPid = "org.apache.karaf.decanter.collector.rest",
-    property = {"decanter.collector.name=rest"}
+    service = Runnable.class,
+    name = "org.apache.karaf.decanter.collector.rest",
+    immediate = true,
+    property = "decanter.collector.name=rest"
 )
 public class RestCollector implements Runnable {
     private final static Logger LOGGER = LoggerFactory.getLogger(RestCollector.class);
@@ -51,6 +53,7 @@ public class RestCollector implements Runnable {
     private EventAdmin eventAdmin;
     private Unmarshaller unmarshaller;
 
+    @SuppressWarnings("unchecked")
     @Activate
     public void activate(ComponentContext context) throws MalformedURLException {
         Dictionary<String, Object> props = context.getProperties();

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/system/pom.xml
----------------------------------------------------------------------
diff --git a/collector/system/pom.xml b/collector/system/pom.xml
index 88a00e5..f5e482f 100644
--- a/collector/system/pom.xml
+++ b/collector/system/pom.xml
@@ -48,7 +48,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.collector.system.Activator</Bundle-Activator>
                         <Private-Package>
                             org.apache.commons.exec*,
                             org.apache.karaf.decanter.collector.system

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/Activator.java
----------------------------------------------------------------------
diff --git a/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/Activator.java b/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/Activator.java
deleted file mode 100644
index c7b487d..0000000
--- a/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/Activator.java
+++ /dev/null
@@ -1,83 +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.karaf.decanter.collector.system;
-
-import org.osgi.framework.*;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.osgi.service.event.EventAdmin;
-import org.osgi.util.tracker.ServiceTracker;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-public class Activator implements BundleActivator {
-
-    private SystemCollector collector;
-    private ServiceTracker<EventAdmin, ServiceRegistration> tracker;
-
-    public void start(final BundleContext bundleContext) throws Exception {
-        tracker = new ServiceTracker<EventAdmin, ServiceRegistration>(bundleContext, EventAdmin.class, null) {
-
-            @Override
-            public ServiceRegistration<?> addingService(ServiceReference<EventAdmin> reference) {
-                EventAdmin eventAdmin = bundleContext.getService(reference);
-                ConfigUpdater configUpdater = new ConfigUpdater(bundleContext, eventAdmin);
-                Hashtable<String, Object> properties = new Hashtable<String, Object>();
-                properties.put(Constants.SERVICE_PID, "org.apache.karaf.decanter.collector.system");
-                return bundleContext.registerService(ManagedService.class, configUpdater, properties);
-            }
-
-            @Override
-            public void removedService(ServiceReference<EventAdmin> reference, ServiceRegistration reg) {
-                reg.unregister();
-                super.removedService(reference, reg);
-            }
-
-        };
-        tracker.open();
-    }
-
-    public void stop(BundleContext bundleContext) throws Exception {
-        tracker.close();
-    }
-
-    private final class ConfigUpdater implements ManagedService {
-
-        private BundleContext bundleContext;
-        private EventAdmin eventAdmin;
-        private ServiceRegistration serviceReg;
-
-        public ConfigUpdater(BundleContext bundleContext, EventAdmin eventAdmin) {
-            this.bundleContext = bundleContext;
-            this.eventAdmin = eventAdmin;
-        }
-
-        @Override
-        public void updated(Dictionary config) throws ConfigurationException {
-            if (serviceReg != null) {
-                serviceReg.unregister();
-            }
-            collector = new SystemCollector(config, eventAdmin);
-            Dictionary<String, String> serviceProperties = new Hashtable<String, String>();
-            serviceProperties.put("decanter.collector.name", "system");
-            serviceReg = bundleContext.registerService(Runnable.class, collector, serviceProperties);
-        }
-
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/SystemCollector.java
----------------------------------------------------------------------
diff --git a/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/SystemCollector.java b/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/SystemCollector.java
index daea9be..5d13c11 100644
--- a/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/SystemCollector.java
+++ b/collector/system/src/main/java/org/apache/karaf/decanter/collector/system/SystemCollector.java
@@ -19,6 +19,10 @@ package org.apache.karaf.decanter.collector.system;
 import org.apache.commons.exec.CommandLine;
 import org.apache.commons.exec.DefaultExecutor;
 import org.apache.commons.exec.PumpStreamHandler;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventAdmin;
 import org.slf4j.Logger;
@@ -30,16 +34,21 @@ import java.util.Dictionary;
 import java.util.Enumeration;
 import java.util.HashMap;
 
+@Component(
+    name = "org.apache.karaf.decanter.collector.system",
+    immediate = true,
+    property = "decanter.collector.name=system"
+)
 public class SystemCollector implements Runnable {
-
     private final static Logger LOGGER = LoggerFactory.getLogger(SystemCollector.class);
 
     private EventAdmin eventAdmin;
-    private Dictionary config;
+    private Dictionary<String, Object> config;
 
-    public SystemCollector(Dictionary config, EventAdmin eventAdmin) {
-        this.config = config;
-        this.eventAdmin = eventAdmin;
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void activate(ComponentContext context) {
+        this.config = context.getProperties();
     }
 
     @Override
@@ -54,7 +63,7 @@ public class SystemCollector implements Runnable {
             } catch (Exception e) {
                 // nothing to do
             }
-            Enumeration keys = config.keys();
+            Enumeration<String> keys = config.keys();
             while (keys.hasMoreElements()) {
                 String key = (String) keys.nextElement();
                 try {
@@ -106,4 +115,8 @@ public class SystemCollector implements Runnable {
         }
     }
 
+    @Reference
+    public void setEventAdmin(EventAdmin eventAdmin) {
+        this.eventAdmin = eventAdmin;
+    }
 }

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-1.x/pom.xml
----------------------------------------------------------------------
diff --git a/elasticsearch-1.x/pom.xml b/elasticsearch-1.x/pom.xml
index b116ad5..1cb44f7 100644
--- a/elasticsearch-1.x/pom.xml
+++ b/elasticsearch-1.x/pom.xml
@@ -48,7 +48,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.elasticsearch.Activator</Bundle-Activator>
                     </instructions>
                 </configuration>
             </plugin>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
----------------------------------------------------------------------
diff --git a/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java b/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
deleted file mode 100644
index 02a4833..0000000
--- a/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
+++ /dev/null
@@ -1,93 +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.karaf.decanter.elasticsearch;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.elasticsearch.node.Node;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("rawtypes")
-public class Activator implements BundleActivator {
-    private static final String CONFIG_PID = "org.apache.karaf.decanter.elasticsearch";
-    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-
-    private EmbeddedNode node;
-    private ServiceRegistration service;
-    private ServiceRegistration registration;
-
-    public void start(BundleContext bundleContext) throws Exception {
-        Dictionary<String, String> properties = new Hashtable<>();
-        properties.put(Constants.SERVICE_PID, CONFIG_PID);
-        registration = bundleContext.registerService(ManagedService.class.getName(),
-                                                     new ConfigUpdater(bundleContext), properties);
-    }
-
-    public void stop(BundleContext bundleContext) throws Exception {
-        if (node != null) {
-            node.stop();
-        }
-        if (service != null) {
-            service.unregister();
-        }
-        if (registration != null) {
-            registration.unregister();
-        }
-    }
-
-    private final class ConfigUpdater implements ManagedService {
-        private BundleContext bundleContext;
-
-        public ConfigUpdater(BundleContext bundleContext) {
-            this.bundleContext = bundleContext;
-        }
-
-        @Override
-        public void updated(Dictionary<String, ?> config) throws ConfigurationException {
-            if (node != null) {
-                try {
-                    node.stop();
-                } catch (Exception e) {
-                    String message = "Failed to stop embedded elasticsearch node";
-                    LOGGER.error(message, e);
-                    throw new ConfigurationException(null, message, e);
-                }
-                service.unregister();
-                node = null;
-            }
-
-            try {
-                node = new EmbeddedNode(config);
-                node.start();
-            } catch (Exception e) {
-                String message = "Failed to start embedded elasticsearch node";
-                LOGGER.error(message, e);
-                throw new ConfigurationException(null, message, e);
-            }
-            service = bundleContext.registerService(Node.class, node.getNode(), null);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
----------------------------------------------------------------------
diff --git a/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java b/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
index 8270d12..db7150e 100644
--- a/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
+++ b/elasticsearch-1.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
@@ -21,6 +21,10 @@ import org.elasticsearch.common.settings.ImmutableSettings.Builder;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.internal.InternalNode;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -30,9 +34,14 @@ import java.util.Dictionary;
 /**
  * Start an Elasticsearch node internally to Karaf.
  */
+@Component(
+    name = "org.apache.karaf.decanter.elasticsearch",
+    immediate = true
+)
 public class EmbeddedNode {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(EmbeddedNode.class);
+    
     private static Node node;
     
     public static String PLUGINS_DIRECTORY = "plugins.directory";
@@ -45,12 +54,19 @@ public class EmbeddedNode {
     public static String NODE_MASTER = "node.master";
     public static String PATH_DATA = "path.data";
     public static String NETWORK_HOST = "network.host";
+    public static String PORT = "port";
     public static String CLUSTER_ROUTING_SCHEDULE = "cluster.routing.schedule";
     public static String PATH_PLUGINS = "path.plugins";
     public static String HTTP_CORS_ENABLED = "http.cors.enabled";
     public static String HTTP_CORS_ALLOW_ORIGIN = "http.cors.allow-origin";
 
-    public EmbeddedNode(Dictionary<String, ?> config) throws Exception {
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void acticate(ComponentContext context) throws Exception {
+        start(context.getProperties());
+    }
+    
+    public void start(Dictionary<String, ?> config) throws Exception {
         LOGGER.info("Starting Elasticsearch node ...");
 
         LOGGER.debug("Creating elasticsearch settings");
@@ -58,10 +74,12 @@ public class EmbeddedNode {
         String karafHome = System.getProperty("karaf.home");
         
         //first some defaults
-        File pluginsFile = new File(getConfig(config, null, PLUGINS_DIRECTORY, new File(new File(karafHome), "/elasticsearch/plugins").getAbsolutePath()));
+        String defaultPluginsPath = new File(new File(karafHome), "/elasticsearch/plugins").getAbsolutePath();
+        File pluginsFile = new File((String)getConfig(config, null, PLUGINS_DIRECTORY, defaultPluginsPath));
         LOGGER.debug("Elasticsearch plugins folder: {}", pluginsFile.getAbsolutePath());
         
-        File ymlFile = new File(getConfig(config, null, ELASTIC_YAML_FILE, new File(System.getProperty("karaf.etc"), "elasticsearch.yml").getAbsolutePath()));
+        String defaultConfigPath = new File(System.getProperty("karaf.etc"), "elasticsearch.yml").getAbsolutePath();
+        File ymlFile = new File((String)getConfig(config, null, ELASTIC_YAML_FILE, defaultConfigPath));
         LOGGER.debug("Eleasticsearch yml configuration: {}", ymlFile.getAbsolutePath());
 
         Settings settings = null;
@@ -86,6 +104,7 @@ public class EmbeddedNode {
        	settingsBuilder.put(NODE_DATA, getConfig(config, settings, NODE_DATA, "true"));
        	settingsBuilder.put(NODE_NAME, getConfig(config, settings, NODE_NAME, getNodeName()));
        	settingsBuilder.put(NETWORK_HOST, getConfig(config, settings, NETWORK_HOST, "127.0.0.1"));
+       	settingsBuilder.put(PORT, getConfig(config, settings, PORT, 9300));
        	settingsBuilder.put(CLUSTER_ROUTING_SCHEDULE, getConfig(config, settings, CLUSTER_ROUTING_SCHEDULE, "50ms"));
        	settingsBuilder.put(PATH_PLUGINS, getConfig(config, settings, PATH_PLUGINS, pluginsFile.getAbsolutePath()));
        	settingsBuilder.put(HTTP_CORS_ENABLED, getConfig(config, settings, HTTP_CORS_ENABLED, "true"));
@@ -96,18 +115,16 @@ public class EmbeddedNode {
         node = new InternalNode(settingsBuilder.build(), false);
 
         LOGGER.info("Elasticsearch node created");
+        if (node != null) {
+            node.start();
+        }
     }
 
     private String getNodeName() {
         return System.getProperty("karaf.name") == null ? "decanter" : System.getProperty("karaf.name");
     }
 
-    public void start() throws Exception {
-        if (node != null) {
-            node.start();
-        }
-    }
-
+    @Deactivate
     public void stop() throws Exception {
         if (node != null) {
             node.close();
@@ -125,13 +142,13 @@ public class EmbeddedNode {
         return node;
     }
     
-    private String getConfig(Dictionary<String, ?> config, Settings settings, String key,
-                             String defaultValue) {
+    private Object getConfig(Dictionary<String, ?> config, Settings settings, String key,
+                             Object defaultValue) {
         if (settings != null && settings.get(key) != null)
             defaultValue = settings.get(key);
         if (config == null)
             return defaultValue;
-        String value = (String)config.get(key);
+        Object value = config.get(key);
         return value != null ? value : defaultValue;
     }
 

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-1.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
----------------------------------------------------------------------
diff --git a/elasticsearch-1.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java b/elasticsearch-1.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
index 4ef0854..7d4c1ce 100644
--- a/elasticsearch-1.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
+++ b/elasticsearch-1.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
@@ -36,12 +36,13 @@ public class TestEmbeddedNode {
         System.setProperty("karaf.home", "target/karaf");
         System.setProperty("karaf.name", "decanter-test");
 
-        Dictionary<String, String> configuration = new Hashtable<>();
+        Dictionary<String, Object> configuration = new Hashtable<>();
         configuration.put(EmbeddedNode.PATH_DATA, "target/karaf/es");
-        EmbeddedNode embeddedNode = new EmbeddedNode(configuration);
-        
+        configuration.put(EmbeddedNode.CLUSTER_NAME, "elasticsearch-test");
+        configuration.put(EmbeddedNode.PORT, 9301);
+        EmbeddedNode embeddedNode = new EmbeddedNode();
+        embeddedNode.start(configuration);
         Node node = embeddedNode.getNode();
-        embeddedNode.start();
         ClusterHealthResponse healthResponse = node.client().admin().cluster().health(Requests.clusterHealthRequest()).actionGet();
         assertEquals(ClusterHealthStatus.GREEN, healthResponse.getStatus());
         embeddedNode.stop();

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-2.x/pom.xml
----------------------------------------------------------------------
diff --git a/elasticsearch-2.x/pom.xml b/elasticsearch-2.x/pom.xml
index d58564b..ac74e0d 100644
--- a/elasticsearch-2.x/pom.xml
+++ b/elasticsearch-2.x/pom.xml
@@ -48,7 +48,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.elasticsearch.Activator</Bundle-Activator>
                     </instructions>
                 </configuration>
             </plugin>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
----------------------------------------------------------------------
diff --git a/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java b/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
deleted file mode 100644
index 02a4833..0000000
--- a/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/Activator.java
+++ /dev/null
@@ -1,93 +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.karaf.decanter.elasticsearch;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-import org.elasticsearch.node.Node;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-@SuppressWarnings("rawtypes")
-public class Activator implements BundleActivator {
-    private static final String CONFIG_PID = "org.apache.karaf.decanter.elasticsearch";
-    private static final Logger LOGGER = LoggerFactory.getLogger(Activator.class);
-
-    private EmbeddedNode node;
-    private ServiceRegistration service;
-    private ServiceRegistration registration;
-
-    public void start(BundleContext bundleContext) throws Exception {
-        Dictionary<String, String> properties = new Hashtable<>();
-        properties.put(Constants.SERVICE_PID, CONFIG_PID);
-        registration = bundleContext.registerService(ManagedService.class.getName(),
-                                                     new ConfigUpdater(bundleContext), properties);
-    }
-
-    public void stop(BundleContext bundleContext) throws Exception {
-        if (node != null) {
-            node.stop();
-        }
-        if (service != null) {
-            service.unregister();
-        }
-        if (registration != null) {
-            registration.unregister();
-        }
-    }
-
-    private final class ConfigUpdater implements ManagedService {
-        private BundleContext bundleContext;
-
-        public ConfigUpdater(BundleContext bundleContext) {
-            this.bundleContext = bundleContext;
-        }
-
-        @Override
-        public void updated(Dictionary<String, ?> config) throws ConfigurationException {
-            if (node != null) {
-                try {
-                    node.stop();
-                } catch (Exception e) {
-                    String message = "Failed to stop embedded elasticsearch node";
-                    LOGGER.error(message, e);
-                    throw new ConfigurationException(null, message, e);
-                }
-                service.unregister();
-                node = null;
-            }
-
-            try {
-                node = new EmbeddedNode(config);
-                node.start();
-            } catch (Exception e) {
-                String message = "Failed to start embedded elasticsearch node";
-                LOGGER.error(message, e);
-                throw new ConfigurationException(null, message, e);
-            }
-            service = bundleContext.registerService(Node.class, node.getNode(), null);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
----------------------------------------------------------------------
diff --git a/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java b/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
index 64046be..e39ee57 100644
--- a/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
+++ b/elasticsearch-2.x/src/main/java/org/apache/karaf/decanter/elasticsearch/EmbeddedNode.java
@@ -19,6 +19,10 @@ package org.apache.karaf.decanter.elasticsearch;
 import org.elasticsearch.common.settings.Settings;
 import org.elasticsearch.node.Node;
 import org.elasticsearch.node.NodeBuilder;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,6 +33,10 @@ import java.util.Dictionary;
 /**
  * Start an Elasticsearch node internally to Karaf.
  */
+@Component(
+    name = "org.apache.karaf.decanter.elasticsearch",
+    immediate = true
+)
 public class EmbeddedNode {
 
     private final static Logger LOGGER = LoggerFactory.getLogger(EmbeddedNode.class);
@@ -49,7 +57,13 @@ public class EmbeddedNode {
     public static String HTTP_CORS_ALLOW_ORIGIN = "http.cors.allow-origin";
     public static String INDEX_MAX_RESULT_WINDOW = "index.max_result_window";
 
-    public EmbeddedNode(Dictionary<String, ?> config) throws Exception {
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void acticate(ComponentContext context) throws Exception {
+        start(context.getProperties());
+    }
+    
+    public void start(Dictionary<String, ?> config) throws Exception {
         LOGGER.info("Starting Elasticsearch node ...");
 
         LOGGER.debug("Creating elasticsearch settings");
@@ -94,18 +108,16 @@ public class EmbeddedNode {
         node = NodeBuilder.nodeBuilder().settings(settingsBuilder).build();
 
         LOGGER.info("Elasticsearch node created");
+        if (node != null) {
+            node.start();
+        }
     }
 
     private String getNodeName() {
         return System.getProperty("karaf.name") == null ? "decanter" : System.getProperty("karaf.name");
     }
 
-    public void start() throws Exception {
-        if (node != null) {
-            node.start();
-        }
-    }
-
+    @Deactivate
     public void stop() throws Exception {
         if (node != null) {
             node.close();

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/elasticsearch-2.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
----------------------------------------------------------------------
diff --git a/elasticsearch-2.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java b/elasticsearch-2.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
index 2d4152c..8d3746a 100644
--- a/elasticsearch-2.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
+++ b/elasticsearch-2.x/src/test/java/org/apache/karaf/decanter/elasticsearch/TestEmbeddedNode.java
@@ -38,11 +38,10 @@ public class TestEmbeddedNode {
 
         Dictionary<String, String> configuration = new Hashtable<>();
         configuration.put(EmbeddedNode.PATH_DATA, "target/karaf/es");
-        EmbeddedNode embeddedNode = new EmbeddedNode(configuration);
-        
+        EmbeddedNode embeddedNode = new EmbeddedNode();
+        embeddedNode.start(configuration);
         Node node = embeddedNode.getNode();
-        embeddedNode.start();
-
+        
         // gives time to the cluster to startup
         Thread.sleep(5000);
 

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
----------------------------------------------------------------------
diff --git a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
index 8e48459..fc4eefe 100644
--- a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
+++ b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonMarshaller.java
@@ -34,13 +34,13 @@ import javax.json.JsonObjectBuilder;
 import javax.json.JsonWriter;
 
 import org.apache.karaf.decanter.api.marshaller.Marshaller;
-import org.osgi.service.component.annotations.Activate;
 import org.osgi.service.component.annotations.Component;
 import org.osgi.service.event.Event;
 import org.osgi.service.event.EventConstants;
 
 @Component(
-        property = { Marshaller.SERVICE_KEY_DATAFORMAT + "=json" }
+    immediate = true,
+    property = Marshaller.SERVICE_KEY_DATAFORMAT + "=json"
 )
 public class JsonMarshaller implements Marshaller {
 

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonUnmarshaller.java
----------------------------------------------------------------------
diff --git a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonUnmarshaller.java b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonUnmarshaller.java
index 607119e..0382738 100644
--- a/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonUnmarshaller.java
+++ b/marshaller/json/src/main/java/org/apache/karaf/decanter/marshaller/json/JsonUnmarshaller.java
@@ -32,7 +32,8 @@ import org.apache.karaf.decanter.api.marshaller.Unmarshaller;
 import org.osgi.service.component.annotations.Component;
 
 @Component(
-        property = { Marshaller.SERVICE_KEY_DATAFORMAT + "=json" }
+    immediate = true,
+    property = Marshaller.SERVICE_KEY_DATAFORMAT + "=json"
 )
 public class JsonUnmarshaller implements Unmarshaller {
 

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 9703e8a..da9c9a7 100644
--- a/pom.xml
+++ b/pom.xml
@@ -260,12 +260,6 @@
                 <scope>provided</scope>
             </dependency>
 
-            <dependency>
-                <groupId>biz.aQute.bnd</groupId>
-                <artifactId>biz.aQute.bnd.annotation</artifactId>
-                <version>3.1.0</version>
-            </dependency>
-
             <!-- ActiveMQ -->
             <dependency>
                 <groupId>org.apache.activemq</groupId>
@@ -337,11 +331,6 @@
             <scope>provided</scope>
         </dependency>
         <dependency>
-            <groupId>biz.aQute.bnd</groupId>
-            <artifactId>biz.aQute.bnd.annotation</artifactId>
-            <scope>provided</scope>
-        </dependency>
-        <dependency>
             <groupId>org.slf4j</groupId>
             <artifactId>slf4j-api</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/scheduler/simple/bnd.bnd
----------------------------------------------------------------------
diff --git a/scheduler/simple/bnd.bnd b/scheduler/simple/bnd.bnd
deleted file mode 100644
index bb852db..0000000
--- a/scheduler/simple/bnd.bnd
+++ /dev/null
@@ -1 +0,0 @@
-Bundle-Activator: org.apache.karaf.decanter.scheduler.simple.Activator

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/scheduler/simple/pom.xml
----------------------------------------------------------------------
diff --git a/scheduler/simple/pom.xml b/scheduler/simple/pom.xml
index 5775923..8143ff9 100644
--- a/scheduler/simple/pom.xml
+++ b/scheduler/simple/pom.xml
@@ -47,7 +47,6 @@
                 <artifactId>maven-bundle-plugin</artifactId>
                 <configuration>
                     <instructions>
-                        <Bundle-Activator>org.apache.karaf.decanter.scheduler.simple.Activator</Bundle-Activator>
                     </instructions>
                 </configuration>
             </plugin>

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/Activator.java
----------------------------------------------------------------------
diff --git a/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/Activator.java b/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/Activator.java
deleted file mode 100644
index 6c45922..0000000
--- a/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/Activator.java
+++ /dev/null
@@ -1,76 +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.karaf.decanter.scheduler.simple;
-
-import org.apache.karaf.decanter.api.Scheduler;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.cm.ConfigurationException;
-import org.osgi.service.cm.ManagedService;
-
-import java.util.Dictionary;
-import java.util.Hashtable;
-
-public class Activator implements BundleActivator {
-
-    private SimpleScheduler scheduler;
-    private ServiceRegistration registration;
-    private static final String CONFIG_PID = "org.apache.karaf.decanter.scheduler.simple";
-
-    public void start(BundleContext bundleContext) {
-        Dictionary<String, String> properties = new Hashtable<>();
-        properties.put(Constants.SERVICE_PID, CONFIG_PID);
-        registration = bundleContext.registerService(
-                ManagedService.class.getName(),
-                new ConfigUpdater(bundleContext),
-                properties);
-    }
-
-    public void stop(BundleContext bundleContext) {
-        if (scheduler != null) {
-            scheduler.stop();
-        }
-        if (registration != null) {
-            registration.unregister();
-        }
-    }
-
-    private final class ConfigUpdater implements ManagedService {
-
-        private BundleContext bundleContext;
-        private ServiceRegistration<?> serviceRegistration;
-
-        public ConfigUpdater(BundleContext bundleContext) {
-            this.bundleContext = bundleContext;
-        }
-
-        @Override
-        public void updated(Dictionary config) throws ConfigurationException {
-            if (scheduler != null) {
-                scheduler.stop();
-                serviceRegistration.unregister();
-            }
-            int period = config != null ? Integer.parseInt((String)config.get("period")) : 5000;
-            scheduler = new SimpleScheduler(period, bundleContext);
-            scheduler.start();
-            serviceRegistration = bundleContext.registerService(Scheduler.class, scheduler, null);
-        }
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf-decanter/blob/18e8b297/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/SimpleScheduler.java
----------------------------------------------------------------------
diff --git a/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/SimpleScheduler.java b/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/SimpleScheduler.java
index 2147f6a..d06840e 100644
--- a/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/SimpleScheduler.java
+++ b/scheduler/simple/src/main/java/org/apache/karaf/decanter/scheduler/simple/SimpleScheduler.java
@@ -16,41 +16,48 @@
  */
 package org.apache.karaf.decanter.scheduler.simple;
 
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.karaf.decanter.api.Scheduler;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.Filter;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.service.component.ComponentContext;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Reference;
+import org.osgi.service.component.annotations.ReferenceCardinality;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
  * Very simple Decanter scheduler using a single thread.
  */
+@Component(
+    name = "org.apache.karaf.decanter.scheduler.simple",
+    immediate = true
+)
 public class SimpleScheduler implements Runnable, Scheduler {
     private final static Logger LOGGER = LoggerFactory.getLogger(SimpleScheduler.class);
 
     private AtomicBoolean running = new AtomicBoolean(false);
-    private long period;
-    ServiceTracker<Runnable, Runnable> collectors;
+    private long period = 5000;
+    Set<Runnable> collectors;
     
-    SimpleScheduler() {
+    public SimpleScheduler() {
+        collectors = new HashSet<>();
     }
     
-    public SimpleScheduler(int period, BundleContext bundleContext) {
-        this.period = period;
-        this.collectors = new ServiceTracker<>(bundleContext, collectorFilter(bundleContext), null);
-        this.collectors.open();
+    @SuppressWarnings("unchecked")
+    @Activate
+    public void activate(ComponentContext context) {
+        configure(context.getProperties());
+        start();
     }
-
-    private Filter collectorFilter(BundleContext bundleContext) {
-        try {
-            return bundleContext.createFilter(String.format("(&(objectClass=%s)(decanter.collector.name=*))", Runnable.class.getName()));
-        } catch (InvalidSyntaxException e) {
-            throw new RuntimeException(e);
-        }
+    
+    public void configure(Dictionary<String, String> config) {
+        String periodSt = config.get("period");
+        period = periodSt != null ? Integer.parseInt(periodSt) : 5000;
     }
 
     @Override
@@ -59,7 +66,7 @@ public class SimpleScheduler implements Runnable, Scheduler {
 
         while (running.get()) {
             LOGGER.debug("Calling the collectors ...");
-            for (Runnable collector : collectors.getServices(new Runnable[] {})) {
+            for (Runnable collector : collectors) {
                 try {
                     collector.run();
                 } catch (Exception e) {
@@ -80,9 +87,6 @@ public class SimpleScheduler implements Runnable, Scheduler {
     @Override
     public void stop() {
         running.set(false);
-        if (collectors != null) {
-            this.collectors.close();
-        }
     }
 
     @Override
@@ -100,11 +104,16 @@ public class SimpleScheduler implements Runnable, Scheduler {
 
     @Override
     public String state() {
-        if (running.get()) {
-            return "Started";
-        } else {
-            return "Stopped";
-        }
+        return running.get() ? "Started" : "Stopped";
+    }
+
+    @Reference(target="(decanter.collector.name=*)", cardinality=ReferenceCardinality.MULTIPLE)
+    public void setCollector(Runnable collector) {
+        this.collectors.add(collector);
+    }
+    
+    public void unsetCollector(Runnable collector) {
+        this.collectors.remove(collector);
     }
 
 }


Mime
View raw message