You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by gn...@apache.org on 2016/06/17 20:10:20 UTC

karaf git commit: [KARAF-4577] Use ServiceComponentRuntime api and provide a BundleStateService for DS

Repository: karaf
Updated Branches:
  refs/heads/master 452379457 -> 9e301b649


[KARAF-4577] Use ServiceComponentRuntime api and provide a BundleStateService for DS

Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/9e301b64
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/9e301b64
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/9e301b64

Branch: refs/heads/master
Commit: 9e301b649f68e4ce4e80d9412cec0bf253bb2058
Parents: 4523794
Author: Guillaume Nodet <gn...@apache.org>
Authored: Fri Jun 17 21:55:50 2016 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Fri Jun 17 22:10:14 2016 +0200

----------------------------------------------------------------------
 .../standard/src/main/feature/feature.xml       |   4 +
 scr/command/pom.xml                             |   4 -
 .../org/apache/karaf/scr/command/ScrUtils.java  |  35 +-----
 .../scr/command/action/ActivateAction.java      |  16 +--
 .../scr/command/action/DeactivateAction.java    |  15 ++-
 .../karaf/scr/command/action/DetailsAction.java | 121 +++++++++++--------
 .../karaf/scr/command/action/ListAction.java    |  26 ++--
 .../scr/command/action/ScrActionSupport.java    |  46 +++----
 .../command/completer/ActivateCompleter.java    |   8 +-
 .../command/completer/DeactivateCompleter.java  |   8 +-
 .../scr/command/completer/DetailsCompleter.java |   6 +-
 .../command/completer/ScrCompleterSupport.java  |  34 +++---
 .../karaf/scr/command/support/IdComparator.java |  12 +-
 scr/pom.xml                                     |   1 +
 scr/state/pom.xml                               | 100 +++++++++++++++
 .../org/apache/karaf/scr/state/Activator.java   |  38 ++++++
 .../karaf/scr/state/ScrBundleStateService.java  |  90 ++++++++++++++
 17 files changed, 394 insertions(+), 170 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/assemblies/features/standard/src/main/feature/feature.xml
----------------------------------------------------------------------
diff --git a/assemblies/features/standard/src/main/feature/feature.xml b/assemblies/features/standard/src/main/feature/feature.xml
index dd260a9..4cb99a2 100644
--- a/assemblies/features/standard/src/main/feature/feature.xml
+++ b/assemblies/features/standard/src/main/feature/feature.xml
@@ -542,6 +542,10 @@
             <condition>shell</condition>
             <bundle start-level="30">mvn:org.apache.karaf.scr/org.apache.karaf.scr.command/${project.version}</bundle>
         </conditional>
+        <conditional>
+            <condition>bundle</condition>
+            <bundle start-level="30">mvn:org.apache.karaf.scr/org.apache.karaf.scr.state/${project.version}</bundle>
+        </conditional>
         <capability>
             osgi.service;effective:=active;objectClass=org.apache.felix.scr.ScrService,
             osgi.extender;osgi.extender="osgi.component";uses:="org.osgi.service.component";version:Version="1.2.1"

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/pom.xml
----------------------------------------------------------------------
diff --git a/scr/command/pom.xml b/scr/command/pom.xml
index 7c2ab60..56d5b59 100644
--- a/scr/command/pom.xml
+++ b/scr/command/pom.xml
@@ -60,10 +60,6 @@
             <artifactId>org.apache.felix.scr</artifactId>
         </dependency>
         <dependency>
-            <groupId>org.apache.felix</groupId>
-            <artifactId>org.apache.felix.scr.compat</artifactId>
-        </dependency>
-        <dependency>
             <groupId>biz.aQute.bnd</groupId>
             <artifactId>bndlib</artifactId>
             <scope>provided</scope>

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/ScrUtils.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/ScrUtils.java b/scr/command/src/main/java/org/apache/karaf/scr/command/ScrUtils.java
index 2904887..b2ac830 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/ScrUtils.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/ScrUtils.java
@@ -18,7 +18,7 @@ package org.apache.karaf.scr.command;
 
 import java.lang.reflect.Array;
 
-import org.apache.felix.scr.Component;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
 public class ScrUtils {
     
@@ -31,37 +31,14 @@ public class ScrUtils {
         String retVal = null;
 
         switch (componentState) {
-        case Component.STATE_ACTIVE:
+        case ComponentConfigurationDTO.ACTIVE:
             retVal = "ACTIVE";
             break;
-        case Component.STATE_ACTIVATING:
-            retVal = "ACTIVATING";
+        case ComponentConfigurationDTO.SATISFIED:
+            retVal = "SATISFIED";
             break;
-        case Component.STATE_DEACTIVATING:
-            retVal = "DEACTIVATING";
-            break;
-        case Component.STATE_DISABLED:
-            retVal = "DISABLED";
-            break;
-        case Component.STATE_DISABLING:
-            retVal = "DISABLING";
-            break;
-        case Component.STATE_DISPOSED:
-            retVal = "DISPOSED";
-            break;
-        case Component.STATE_DISPOSING:
-            retVal = "DISPOSING";
-            break;
-        case Component.STATE_ENABLING:
-            retVal = "ENABLING";
-            break;
-        case Component.STATE_FACTORY:
-            retVal = "FACTORY";
-            break;
-        case Component.STATE_REGISTERED:
-            retVal = "REGISTERED";
-            break;
-        case Component.STATE_UNSATISFIED:
+        case ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION:
+        case ComponentConfigurationDTO.UNSATISFIED_REFERENCE:
             retVal = "UNSATISFIED";
             break;
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
index c86909d..4a50267 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ActivateAction.java
@@ -16,15 +16,14 @@
  */
 package org.apache.karaf.scr.command.action;
 
-import org.apache.karaf.scr.command.completer.ActivateCompleter;
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
 import org.apache.karaf.scr.command.ScrCommandConstants;
-import org.apache.karaf.scr.command.ScrUtils;
+import org.apache.karaf.scr.command.completer.ActivateCompleter;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
 
 /**
  * Activates the given component by supplying its component name.
@@ -38,12 +37,13 @@ public class ActivateAction extends ScrActionSupport {
     String name;
 
     @Override
-    protected Object doScrAction(ScrService scrService) throws Exception {
+    protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
         logger.debug("Activate Action");
         logger.debug("  Activating the Component: " + name);
-        Component[] components = scrService.getComponents(name);
-        for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
-            component.enable();
+        for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
+            if (name.equals(component.name)) {
+                serviceComponentRuntime.enableComponent(component);
+            }
         }
         return null;
     }

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
index 622b0e7..b1939f1 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DeactivateAction.java
@@ -16,14 +16,14 @@
  */
 package org.apache.karaf.scr.command.action;
 
-import org.apache.karaf.scr.command.completer.DeactivateCompleter;
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
 import org.apache.karaf.scr.command.ScrCommandConstants;
+import org.apache.karaf.scr.command.completer.DeactivateCompleter;
 import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
 
 /**
  * Deactivates the given component by supplying its component name.
@@ -37,13 +37,12 @@ public class DeactivateAction extends ScrActionSupport {
     String name;
 
     @Override
-    protected Object doScrAction(ScrService scrService) throws Exception {
+    protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
         logger.debug("Deactivate Action");
         logger.debug("  Deactivating the Component: " + name);
-        Component[] components = scrService.getComponents(name);
-        if (components != null && components.length > 0) {
-            for (int i = 0; i < components.length; i++) {
-                components[i].disable();
+        for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
+            if (name.equals(component.name)) {
+                serviceComponentRuntime.disableComponent(component);
             }
         }
         return null;

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
index dcf0076..572ece0 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/DetailsAction.java
@@ -16,9 +16,9 @@
  */
 package org.apache.karaf.scr.command.action;
 
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.Reference;
-import org.apache.felix.scr.ScrService;
+import java.util.Map;
+import java.util.TreeMap;
+
 import org.apache.karaf.scr.command.ScrCommandConstants;
 import org.apache.karaf.scr.command.ScrUtils;
 import org.apache.karaf.scr.command.completer.DetailsCompleter;
@@ -28,13 +28,14 @@ import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.support.ansi.SimpleAnsi;
 import org.osgi.framework.Constants;
-import org.osgi.framework.ServiceReference;
+import org.osgi.framework.dto.ServiceReferenceDTO;
 import org.osgi.service.component.ComponentConstants;
-
-import java.util.Hashtable;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.TreeMap;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+import org.osgi.service.component.runtime.dto.ReferenceDTO;
+import org.osgi.service.component.runtime.dto.SatisfiedReferenceDTO;
+import org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO;
 
 /**
  * Display the details associated with a given component by supplying its component name.
@@ -49,62 +50,76 @@ public class DetailsAction extends ScrActionSupport {
 
     @SuppressWarnings("rawtypes")
 	@Override
-    protected Object doScrAction(ScrService scrService) throws Exception {
+    protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
         if (logger.isDebugEnabled()) {
             logger.debug("Executing the Details Action");
         }
         System.out.println(SimpleAnsi.INTENSITY_BOLD + "Component Details" + SimpleAnsi.INTENSITY_NORMAL);
-        Component[] components = scrService.getComponents(name);
-        for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
-            printDetail("  Name                : ", component.getName());
-            printDetail("  State               : ", ScrUtils.getState(component.getState()));
+        for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
+            for (ComponentConfigurationDTO config : serviceComponentRuntime.getComponentConfigurationDTOs(component)) {
+                if (name.equals(component.name)) {
+                    printDetail("  Name                : ", component.name);
+                    printDetail("  State               : ", ScrUtils.getState(config.state));
 
-            Hashtable props = (Hashtable)component.getProperties();
-            Map map = new TreeMap(props);
-            if (!map.isEmpty()) {
-                System.out.println(SimpleAnsi.INTENSITY_BOLD + "  Properties          : " + SimpleAnsi.INTENSITY_NORMAL);
-                for (Object key : map.keySet()) {
-                    Object value = map.get(key);
-                    printDetail("    ", key + "=" + value);
-                }
-            }
-            Reference[] references = component.getReferences();
-            System.out.println(SimpleAnsi.INTENSITY_BOLD + "References" + SimpleAnsi.INTENSITY_NORMAL);
+                    Map<String, Object> map = new TreeMap<>(component.properties);
+                    if (!map.isEmpty()) {
+                        System.out.println(SimpleAnsi.INTENSITY_BOLD + "  Properties          : " + SimpleAnsi.INTENSITY_NORMAL);
+                        for (Object key : map.keySet()) {
+                            Object value = map.get(key);
+                            printDetail("    ", key + "=" + value);
+                        }
+                    }
+                    ReferenceDTO[] references = component.references;
+                    System.out.println(SimpleAnsi.INTENSITY_BOLD + "References" + SimpleAnsi.INTENSITY_NORMAL);
 
-            for (Reference reference : ScrUtils.emptyIfNull(Reference.class, references)) {
-                printDetail("  Reference           : ", reference.getName());
-                printDetail("    State             : ", (reference.isSatisfied()) ? "satisfied" : "unsatisfied");
-                printDetail("    Multiple          : ", (reference.isMultiple() ? "multiple" : "single" ));
-                printDetail("    Optional          : ", (reference.isOptional() ? "optional" : "mandatory" ));
-                printDetail("    Policy            : ", (reference.isStatic() ?  "static" : "dynamic" ));
+                    for (ReferenceDTO reference : ScrUtils.emptyIfNull(ReferenceDTO.class, references)) {
+                        ServiceReferenceDTO[] boundServices = null;
+                        boolean satisfied = true;
+                        for (SatisfiedReferenceDTO satRef : config.satisfiedReferences) {
+                            if (satRef.name.equals(reference.name)) {
+                                boundServices = satRef.boundServices;
+                                satisfied = true;
+                            }
+                        }
+                        for (UnsatisfiedReferenceDTO satRef : config.unsatisfiedReferences) {
+                            if (satRef.name.equals(reference.name)) {
+                                boundServices = satRef.targetServices;
+                                satisfied = false;
+                            }
+                        }
+                        printDetail("  Reference           : ", reference.name);
+                        printDetail("    State             : ", satisfied ? "satisfied" : "unsatisfied");
+                        printDetail("    Cardinality       : ", reference.cardinality);
+                        printDetail("    Policy            : ", reference.policy);
+                        printDetail("    PolicyOption      : ", reference.policyOption);
 
-                // list bound services
-				ServiceReference[] boundRefs = reference.getServiceReferences();
-                for (ServiceReference serviceReference : ScrUtils.emptyIfNull(ServiceReference.class, boundRefs)) {
-                    final StringBuffer b = new StringBuffer();
-                    b.append("Bound Service ID ");
-                    b.append(serviceReference.getProperty(Constants.SERVICE_ID));
+                        // list bound services
+                        for (ServiceReferenceDTO serviceReference : ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices)) {
+                            final StringBuffer b = new StringBuffer();
+                            b.append("Bound Service ID ");
+                            b.append(serviceReference.properties.get(Constants.SERVICE_ID));
 
-                    String componentName = (String) serviceReference.getProperty(ComponentConstants.COMPONENT_NAME);
-                    if (componentName == null) {
-                        componentName = (String) serviceReference.getProperty(Constants.SERVICE_PID);
-                        if (componentName == null) {
-                            componentName = (String) serviceReference.getProperty(Constants.SERVICE_DESCRIPTION);
+                            String componentName = (String) serviceReference.properties.get(ComponentConstants.COMPONENT_NAME);
+                            if (componentName == null) {
+                                componentName = (String) serviceReference.properties.get(Constants.SERVICE_PID);
+                                if (componentName == null) {
+                                    componentName = (String) serviceReference.properties.get(Constants.SERVICE_DESCRIPTION);
+                                }
+                            }
+                            if (componentName != null) {
+                                b.append(" (");
+                                b.append(componentName);
+                                b.append(")");
+                            }
+                            printDetail("    Service Reference : ", b.toString());
+                        }
+
+                        if (ScrUtils.emptyIfNull(ServiceReferenceDTO.class, boundServices).length == 0) {
+                            printDetail("    Service Reference : ", "No Services bound");
                         }
                     }
-                    if (componentName != null) {
-                        b.append(" (");
-                        b.append(componentName);
-                        b.append(")");
-                    }
-                    printDetail("    Service Reference : ", b.toString());
-                }
-                
-                if (ScrUtils.emptyIfNull(ServiceReference.class, boundRefs).length == 0) {
-                    printDetail("    Service Reference : ", "No Services bound");
                 }
             }
-
         }
     
         return null;

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
index 50d2e93..be90d11 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ListAction.java
@@ -16,16 +16,19 @@
  */
 package org.apache.karaf.scr.command.action;
 
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.karaf.scr.command.ScrCommandConstants;
 import org.apache.karaf.scr.command.ScrUtils;
 import org.apache.karaf.scr.command.support.IdComparator;
 import org.apache.karaf.shell.api.action.Command;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.apache.karaf.shell.support.table.ShellTable;
-
-import java.util.Arrays;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
 
 /**
  * List all the components currently installed.
@@ -37,18 +40,21 @@ public class ListAction extends ScrActionSupport {
     private final IdComparator idComparator = new IdComparator();
 
     @Override
-    protected Object doScrAction(ScrService scrService) throws Exception {
+    protected Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception {
         ShellTable table = new ShellTable();
         table.column("ID");
         table.column("State");
         table.column("Component Name");
 
-        Component[] components = scrService.getComponents();
-        Arrays.sort(components, idComparator);
-        for (Component component : ScrUtils.emptyIfNull(Component.class, components)) {
+        List<ComponentConfigurationDTO> configs = new ArrayList<>();
+        for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
+            configs.addAll(serviceComponentRuntime.getComponentConfigurationDTOs(component));
+        }
+        Collections.sort(configs, idComparator);
+        for (ComponentConfigurationDTO config : configs) {
             // Display only non hidden components, or all if showHidden is true
-            if (showHidden || !ScrActionSupport.isHiddenComponent(component)) {
-                table.addRow().addContent(component.getId(), ScrUtils.getState(component.getState()), component.getName());
+            if (showHidden || !ScrActionSupport.isHiddenComponent(config)) {
+                table.addRow().addContent(config.id, ScrUtils.getState(config.state), config.description.name);
             }
         }
         table.print(System.out);

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
index 6cfe354..998969c 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/action/ScrActionSupport.java
@@ -17,18 +17,16 @@
 package org.apache.karaf.scr.command.action;
 
 import java.util.Arrays;
-import java.util.Dictionary;
 import java.util.List;
 
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
 import org.apache.karaf.scr.command.ScrCommandConstants;
 import org.apache.karaf.shell.api.action.Action;
 import org.apache.karaf.shell.api.action.Option;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.console.CommandLine;
-import org.apache.karaf.shell.api.console.Session;
 import org.osgi.framework.BundleContext;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -43,7 +41,7 @@ public abstract class ScrActionSupport implements Action {
     protected final Logger logger = LoggerFactory.getLogger(getClass().getName());
 
     @Reference
-    private ScrService scrService;
+    private ServiceComponentRuntime serviceComponentRuntime;
 
     @Reference
     BundleContext bundleContext;
@@ -53,24 +51,19 @@ public abstract class ScrActionSupport implements Action {
 
     @Override
     public Object execute() throws Exception {
-        if (scrService == null) {
-            String msg = "ScrService is unavailable";
+        if (serviceComponentRuntime == null) {
+            String msg = "ServiceComponentRuntime is unavailable";
             System.out.println(msg);
             logger.warn(msg);
         } else {
-            doScrAction(scrService);
+            doScrAction(serviceComponentRuntime);
         }
         return null;
     }
 
-    protected abstract Object doScrAction(ScrService scrService) throws Exception;
+    protected abstract Object doScrAction(ServiceComponentRuntime serviceComponentRuntime) throws Exception;
 
-    protected boolean isActionable(Component component) {
-        boolean answer = true;
-        return answer;
-    }
-
-    public static boolean showHiddenComponent(CommandLine commandLine, Component component) {
+    public static boolean showHiddenComponent(CommandLine commandLine) {
         // first look to see if the show all option is there
         // if it is we set showAllFlag to true so the next section will be skipped
         List<String> arguments = Arrays.asList(commandLine.getArguments());
@@ -78,11 +71,10 @@ public abstract class ScrActionSupport implements Action {
     }
 
     @SuppressWarnings("rawtypes")
-    public static boolean isHiddenComponent(Component component) {
+    public static boolean isHiddenComponent(ComponentConfigurationDTO config) {
         boolean answer = false;
-        Dictionary properties = component.getProperties();
-        if (properties != null) {
-            String value = (String) properties.get(ScrCommandConstants.HIDDEN_COMPONENT_KEY);
+        if (config.properties != null) {
+            String value = (String) config.properties.get(ScrCommandConstants.HIDDEN_COMPONENT_KEY);
             // if the value is false, show the hidden
             // then someone wants us to display the name of a hidden component
             answer = Boolean.parseBoolean(value);
@@ -101,22 +93,22 @@ public abstract class ScrActionSupport implements Action {
     }
 
     /**
-     * Get the scrService Object associated with this instance of
+     * Get the ServiceComponentRuntime Object associated with this instance of
      * ScrActionSupport.
      * 
-     * @return the scrService
+     * @return the ServiceComponentRuntime
      */
-    public ScrService getScrService() {
-        return scrService;
+    public ServiceComponentRuntime getServiceComponentRuntime() {
+        return serviceComponentRuntime;
     }
 
     /**
-     * Sets the scrService Object for this ScrActionSupport instance.
+     * Sets the ServiceComponentRuntime Object for this ScrActionSupport instance.
      * 
-     * @param scrService the scrService to set
+     * @param serviceComponentRuntime the ServiceComponentRuntime to set
      */
-    public void setScrService(ScrService scrService) {
-        this.scrService = scrService;
+    public void setServiceComponentRuntime(ServiceComponentRuntime serviceComponentRuntime) {
+        this.serviceComponentRuntime = serviceComponentRuntime;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
index 0908814..734a606 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ActivateCompleter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.karaf.scr.command.completer;
 
-import org.apache.felix.scr.Component;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
 @Service
 public class ActivateCompleter extends ScrCompleterSupport {
@@ -26,11 +26,11 @@ public class ActivateCompleter extends ScrCompleterSupport {
      * Overrides the super method noted below. See super documentation
      * for details.
      * 
-     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(org.apache.felix.scr.Component)
+     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(ComponentConfigurationDTO)
      */
     @Override
-    public boolean availableComponent(Component component) throws Exception {
-        return (component != null && component.getState() == Component.STATE_DISABLED);
+    public boolean availableComponent(ComponentConfigurationDTO component) throws Exception {
+        return (component != null && component.state == ComponentConfigurationDTO.SATISFIED);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
index a968223..f76bc40 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DeactivateCompleter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.karaf.scr.command.completer;
 
-import org.apache.felix.scr.Component;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
 @Service
 public class DeactivateCompleter extends ScrCompleterSupport {
@@ -26,11 +26,11 @@ public class DeactivateCompleter extends ScrCompleterSupport {
      * Overrides the super method noted below. See super documentation
      * for details.
      * 
-     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(org.apache.felix.scr.Component)
+     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(ComponentConfigurationDTO)
      */
     @Override
-    public boolean availableComponent(Component component) throws Exception {
-        return (component != null && (component.getState() == Component.STATE_ACTIVE));
+    public boolean availableComponent(ComponentConfigurationDTO component) throws Exception {
+        return (component != null && (component.state == ComponentConfigurationDTO.ACTIVE));
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DetailsCompleter.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DetailsCompleter.java b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DetailsCompleter.java
index e1dab36..940604e 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DetailsCompleter.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/DetailsCompleter.java
@@ -16,8 +16,8 @@
  */
 package org.apache.karaf.scr.command.completer;
 
-import org.apache.felix.scr.Component;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
 
 @Service
 public class DetailsCompleter extends ScrCompleterSupport {
@@ -26,10 +26,10 @@ public class DetailsCompleter extends ScrCompleterSupport {
      * Overrides the super method noted below. See super documentation for
      * details.
      * 
-     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(org.apache.felix.scr.Component)
+     * @see org.apache.karaf.scr.command.completer.ScrCompleterSupport#availableComponent(ComponentConfigurationDTO)
      */
     @Override
-    public boolean availableComponent(Component component) throws Exception {
+    public boolean availableComponent(ComponentConfigurationDTO component) throws Exception {
         return (component != null);
     }
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
index 7a0dad7..787b54d 100755
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/completer/ScrCompleterSupport.java
@@ -16,16 +16,18 @@
  */
 package org.apache.karaf.scr.command.completer;
 
+import java.util.ArrayList;
 import java.util.List;
 
-import org.apache.felix.scr.Component;
-import org.apache.felix.scr.ScrService;
 import org.apache.karaf.scr.command.action.ScrActionSupport;
 import org.apache.karaf.shell.api.action.lifecycle.Reference;
 import org.apache.karaf.shell.api.console.CommandLine;
 import org.apache.karaf.shell.api.console.Completer;
 import org.apache.karaf.shell.api.console.Session;
 import org.apache.karaf.shell.support.completers.StringsCompleter;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -34,7 +36,7 @@ public abstract class ScrCompleterSupport implements Completer {
     protected final transient Logger logger = LoggerFactory.getLogger(ScrCompleterSupport.class);
 
     @Reference
-    private ScrService scrService;
+    private ServiceComponentRuntime serviceComponentRuntime;
 
     /**
      * Overrides the super method noted below. See super documentation for
@@ -46,14 +48,18 @@ public abstract class ScrCompleterSupport implements Completer {
     public int complete(Session session, CommandLine commandLine, List<String> candidates) {
         StringsCompleter delegate = new StringsCompleter();
         try {
-            for (Component component : scrService.getComponents()) {
+            List<ComponentConfigurationDTO> configs = new ArrayList<>();
+            for (ComponentDescriptionDTO component : serviceComponentRuntime.getComponentDescriptionDTOs()) {
+                configs.addAll(serviceComponentRuntime.getComponentConfigurationDTOs(component));
+            }
+            for (ComponentConfigurationDTO component : configs) {
                 if (logger.isDebugEnabled()) {
-                    logger.debug("Component Name to work on: " + component.getName());
+                    logger.debug("Component Name to work on: " + component.description.name);
                 }
-                if (ScrActionSupport.showHiddenComponent(commandLine, component)) {
+                if (ScrActionSupport.showHiddenComponent(commandLine)) {
                     // we display all because we are overridden
                     if (availableComponent(component)) {
-                        delegate.getStrings().add(component.getName());
+                        delegate.getStrings().add(component.description.name);
                     }
                 } else {
                     if (ScrActionSupport.isHiddenComponent(component)) {
@@ -61,7 +67,7 @@ public abstract class ScrCompleterSupport implements Completer {
                     } else {
                         // we aren't hidden so print it
                         if (availableComponent(component)) {
-                            delegate.getStrings().add(component.getName());
+                            delegate.getStrings().add(component.description.name);
                         }
                     }
                 }
@@ -72,7 +78,7 @@ public abstract class ScrCompleterSupport implements Completer {
         return delegate.complete(session, commandLine, candidates);
     }
 
-    public abstract boolean availableComponent(Component component) throws Exception;
+    public abstract boolean availableComponent(ComponentConfigurationDTO component) throws Exception;
 
     /**
      * Get the scrService Object associated with this instance of
@@ -80,17 +86,17 @@ public abstract class ScrCompleterSupport implements Completer {
      *
      * @return the scrService
      */
-    public ScrService getScrService() {
-        return scrService;
+    public ServiceComponentRuntime getServiceComponentRuntime() {
+        return serviceComponentRuntime;
     }
 
     /**
      * Sets the scrService Object for this ScrCompleterSupport instance.
      *
-     * @param scrService the scrService to set
+     * @param serviceComponentRuntime the ServiceComponentRuntime to set
      */
-    public void setScrService(ScrService scrService) {
-        this.scrService = scrService;
+    public void setSServiceComponentRuntime(ServiceComponentRuntime serviceComponentRuntime) {
+        this.serviceComponentRuntime = serviceComponentRuntime;
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/command/src/main/java/org/apache/karaf/scr/command/support/IdComparator.java
----------------------------------------------------------------------
diff --git a/scr/command/src/main/java/org/apache/karaf/scr/command/support/IdComparator.java b/scr/command/src/main/java/org/apache/karaf/scr/command/support/IdComparator.java
index 95c8e12..9c6afb1 100644
--- a/scr/command/src/main/java/org/apache/karaf/scr/command/support/IdComparator.java
+++ b/scr/command/src/main/java/org/apache/karaf/scr/command/support/IdComparator.java
@@ -16,16 +16,16 @@
  */
 package org.apache.karaf.scr.command.support;
 
-import org.apache.felix.scr.Component;
-
 import java.util.Comparator;
 
-public class IdComparator implements Comparator<Component> {
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+
+public class IdComparator implements Comparator<ComponentConfigurationDTO> {
     @Override
-    public int compare(Component left, Component right) {
-        if (left.getId() < right.getId()) {
+    public int compare(ComponentConfigurationDTO left, ComponentConfigurationDTO right) {
+        if (left.id < right.id) {
             return -1;
-        } else if (left.getId() == right.getId()) {
+        } else if (left.id == right.id) {
             return 0;
         } else {
             return 1;

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/pom.xml
----------------------------------------------------------------------
diff --git a/scr/pom.xml b/scr/pom.xml
index 6d1edc2..d7a5c54 100644
--- a/scr/pom.xml
+++ b/scr/pom.xml
@@ -36,6 +36,7 @@
     <modules>
         <module>command</module>
         <module>management</module>
+        <module>state</module>
         <module>examples</module>
     </modules>
 

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/state/pom.xml
----------------------------------------------------------------------
diff --git a/scr/state/pom.xml b/scr/state/pom.xml
new file mode 100644
index 0000000..7856bcb
--- /dev/null
+++ b/scr/state/pom.xml
@@ -0,0 +1,100 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+    <!--
+
+        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.
+    -->
+
+    <modelVersion>4.0.0</modelVersion>
+
+    <parent>
+        <groupId>org.apache.karaf.scr</groupId>
+        <artifactId>scr</artifactId>
+        <version>4.1.0-SNAPSHOT</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+
+    <artifactId>org.apache.karaf.scr.state</artifactId>
+    <packaging>bundle</packaging>
+    <name>Apache Karaf :: SCR :: Bundle State</name>
+    <description>Provides the Bundle state for SCR</description>
+
+    <properties>
+        <appendedResourcesDirectory>${basedir}/../../etc/appended-resources</appendedResourcesDirectory>
+        <karaf.service.ranking>1</karaf.service.ranking>
+    </properties>
+
+    <dependencies>
+
+        <dependency>
+            <groupId>org.osgi</groupId>
+            <artifactId>org.osgi.core</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf</groupId>
+            <artifactId>org.apache.karaf.util</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.karaf.bundle</groupId>
+            <artifactId>org.apache.karaf.bundle.core</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr</artifactId>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <resources>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <includes>
+                    <include>**/*</include>
+                </includes>
+            </resource>
+            <resource>
+                <directory>${project.basedir}/src/main/resources</directory>
+                <filtering>true</filtering>
+                <includes>
+                    <include>**/*.info</include>
+                </includes>
+            </resource>
+        </resources>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.karaf.tooling</groupId>
+                <artifactId>karaf-services-maven-plugin</artifactId>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <configuration>
+                    <instructions>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/state/src/main/java/org/apache/karaf/scr/state/Activator.java
----------------------------------------------------------------------
diff --git a/scr/state/src/main/java/org/apache/karaf/scr/state/Activator.java b/scr/state/src/main/java/org/apache/karaf/scr/state/Activator.java
new file mode 100644
index 0000000..a5c9d35
--- /dev/null
+++ b/scr/state/src/main/java/org/apache/karaf/scr/state/Activator.java
@@ -0,0 +1,38 @@
+/*
+ * 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.scr.state;
+
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.apache.karaf.util.tracker.BaseActivator;
+import org.apache.karaf.util.tracker.annotation.ProvideService;
+import org.apache.karaf.util.tracker.annotation.RequireService;
+import org.apache.karaf.util.tracker.annotation.Services;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+
+@Services(requires = @RequireService(ServiceComponentRuntime.class),
+          provides = @ProvideService(BundleStateService.class))
+public class Activator extends BaseActivator {
+
+    @Override
+    protected void doStart() throws Exception {
+        ServiceComponentRuntime scr = getTrackedService(ServiceComponentRuntime.class);
+        if (scr != null) {
+            register(BundleStateService.class, new ScrBundleStateService(scr));
+        }
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/karaf/blob/9e301b64/scr/state/src/main/java/org/apache/karaf/scr/state/ScrBundleStateService.java
----------------------------------------------------------------------
diff --git a/scr/state/src/main/java/org/apache/karaf/scr/state/ScrBundleStateService.java b/scr/state/src/main/java/org/apache/karaf/scr/state/ScrBundleStateService.java
new file mode 100644
index 0000000..67cc045
--- /dev/null
+++ b/scr/state/src/main/java/org/apache/karaf/scr/state/ScrBundleStateService.java
@@ -0,0 +1,90 @@
+/*
+ * 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.scr.state;
+
+import org.apache.karaf.bundle.core.BundleState;
+import org.apache.karaf.bundle.core.BundleStateService;
+import org.osgi.framework.Bundle;
+import org.osgi.service.component.runtime.ServiceComponentRuntime;
+import org.osgi.service.component.runtime.dto.ComponentConfigurationDTO;
+import org.osgi.service.component.runtime.dto.ComponentDescriptionDTO;
+import org.osgi.service.component.runtime.dto.UnsatisfiedReferenceDTO;
+
+public class ScrBundleStateService implements BundleStateService {
+
+    ServiceComponentRuntime scr;
+
+    public ScrBundleStateService(ServiceComponentRuntime scr) {
+        this.scr = scr;
+    }
+
+    @Override
+    public String getName() {
+        return BundleStateService.NAME_DS;
+    }
+
+    @Override
+    public String getDiag(Bundle bundle) {
+        StringBuilder sb = new StringBuilder();
+        for (ComponentDescriptionDTO desc : scr.getComponentDescriptionDTOs(bundle)) {
+            for (ComponentConfigurationDTO cfg : scr.getComponentConfigurationDTOs(desc)) {
+                if (cfg.state != ComponentConfigurationDTO.ACTIVE) {
+                    sb.append(cfg.description.name).append(" (").append(cfg.id).append(")\n");
+                    if ((cfg.state & ComponentConfigurationDTO.UNSATISFIED_CONFIGURATION) != 0) {
+                        sb.append("  missing configurations: ");
+                        boolean first = true;
+                        for (String s : cfg.description.configurationPid) {
+                            if (!first) {
+                                sb.append(", ");
+                            }
+                            sb.append(s);
+                            first = false;
+                        }
+                        sb.append("\n");
+                    }
+                    if ((cfg.state & ComponentConfigurationDTO.UNSATISFIED_REFERENCE) != 0) {
+                        sb.append("  missing references: ");
+                        boolean first = true;
+                        for (UnsatisfiedReferenceDTO ur : cfg.unsatisfiedReferences) {
+                            if (!first) {
+                                sb.append(", ");
+                            }
+                            sb.append(ur.name);
+                            first = false;
+                        }
+                        sb.append("\n");
+                    }
+                }
+            }
+        }
+        return sb.toString();
+    }
+
+    @Override
+    public BundleState getState(Bundle bundle) {
+        if (bundle.getState() == Bundle.ACTIVE) {
+            for (ComponentDescriptionDTO desc : scr.getComponentDescriptionDTOs(bundle)) {
+                for (ComponentConfigurationDTO cfg : scr.getComponentConfigurationDTOs(desc)) {
+                    if (cfg.state != ComponentConfigurationDTO.ACTIVE) {
+                        return BundleState.Waiting;
+                    }
+                }
+            }
+        }
+        return BundleState.Unknown;
+    }
+}