register state listeners in Adapter/ResourceAdapter service
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@947498 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
index adaa22f..5a2b07e 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/AdapterServiceImpl.java
@@ -23,6 +23,7 @@
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.service.Service;
+import org.apache.felix.dm.service.ServiceStateListener;
import org.osgi.framework.ServiceReference;
/**
@@ -58,7 +59,6 @@
public Service createService(Object[] properties) {
ServiceReference ref = (ServiceReference) properties[0];
- Object service = properties[1];
Properties props = new Properties();
String[] keys = ref.getPropertyKeys();
for (int i = 0; i < keys.length; i++) {
@@ -73,7 +73,7 @@
}
List dependencies = m_service.getDependencies();
dependencies.remove(0);
- return m_manager.createService()
+ Service service = m_manager.createService()
.setInterface(m_serviceInterfaces, props)
.setImplementation(m_serviceImpl)
.setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
@@ -83,6 +83,10 @@
.add(m_manager.createServiceDependency()
.setService(m_adapteeInterface, ref)
.setRequired(true));
+ for (int i = 0; i < m_stateListeners.size(); i ++) {
+ service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
+ }
+ return service;
}
}
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
index 9f7f1cc..d9acf70 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dm/impl/ResourceAdapterServiceImpl.java
@@ -25,6 +25,7 @@
import org.apache.felix.dm.DependencyManager;
import org.apache.felix.dm.resources.Resource;
import org.apache.felix.dm.service.Service;
+import org.apache.felix.dm.service.ServiceStateListener;
/**
* Resource adapter service implementation. This class extends the FilterService in order to catch
@@ -68,19 +69,23 @@
// the first dependency is always the dependency on the resource, which
// will be replaced with a more specific dependency below
dependencies.remove(0);
- return m_manager.createService()
- .setInterface(m_serviceInterfaces, props)
- .setImplementation(m_serviceImpl)
- .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
- .setComposition(m_compositionInstance, m_compositionMethod) // if not set, no effect
- .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if not set, no effect
- .add(dependencies)
- .add(m_manager.createResourceDependency()
- .setResource(resource)
- .setPropagate(m_propagate)
- .setCallbacks(null, "changed", null)
- .setAutoConfig(true)
- .setRequired(true));
+ Service service = m_manager.createService()
+ .setInterface(m_serviceInterfaces, props)
+ .setImplementation(m_serviceImpl)
+ .setFactory(m_factory, m_factoryCreateMethod) // if not set, no effect
+ .setComposition(m_compositionInstance, m_compositionMethod) // if not set, no effect
+ .setCallbacks(m_callbackObject, m_init, m_start, m_stop, m_destroy) // if not set, no effect
+ .add(dependencies)
+ .add(m_manager.createResourceDependency()
+ .setResource(resource)
+ .setPropagate(m_propagate)
+ .setCallbacks(null, "changed", null)
+ .setAutoConfig(true)
+ .setRequired(true));
+ for (int i = 0; i < m_stateListeners.size(); i ++) {
+ service.addStateListener((ServiceStateListener) m_stateListeners.get(i));
+ }
+ return service;
}
}
}