FELIX-1546 applied the patch with some modifications
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@883476 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
index 2fa8b13..88ffcf7 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyActivatorBase.java
@@ -108,6 +108,16 @@
}
/**
+ * Creates a new temporal service dependency.
+ *
+ * @param timeout the max number of milliseconds to wait for a service availability.
+ * @return the service dependency
+ */
+ public TemporalServiceDependency createTemporalServiceDependency() {
+ return new TemporalServiceDependency(m_context, m_logger);
+ }
+
+ /**
* Creates a new configuration dependency.
*
* @return the configuration dependency
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
index 5c99c7b..cb1fe44 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/DependencyManager.java
@@ -85,6 +85,16 @@
return new ServiceDependency(m_context, m_logger);
}
+ /**
+ * Creates a new temporal service dependency.
+ *
+ * @param timeout the max number of milliseconds to wait for a service availability.
+ * @return the service dependency
+ */
+ public TemporalServiceDependency createTemporalServiceDependency() {
+ return new TemporalServiceDependency(m_context, m_logger);
+ }
+
public ConfigurationDependency createConfigurationDependency() {
return new ConfigurationDependency(m_context, m_logger);
}
diff --git a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/ServiceDependency.java b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/ServiceDependency.java
index 195fa12..b1db122 100644
--- a/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/ServiceDependency.java
+++ b/dependencymanager/core/src/main/java/org/apache/felix/dependencymanager/ServiceDependency.java
@@ -41,11 +41,11 @@
*/
public class ServiceDependency implements Dependency, ServiceTrackerCustomizer, ServiceComponentDependency {
private boolean m_isRequired;
- private Service m_service;
- private volatile ServiceTracker m_tracker;
- private BundleContext m_context;
+ protected Service m_service;
+ protected volatile ServiceTracker m_tracker;
+ protected BundleContext m_context;
private boolean m_isAvailable;
- private volatile Class m_trackedServiceName;
+ protected volatile Class m_trackedServiceName;
private Object m_nullObject;
private volatile String m_trackedServiceFilter;
private volatile String m_trackedServiceFilterUnmodified;
@@ -56,8 +56,8 @@
private String m_callbackChanged;
private String m_callbackRemoved;
private boolean m_autoConfig;
- private ServiceReference m_reference;
- private Object m_serviceInstance;
+ protected ServiceReference m_reference;
+ protected Object m_serviceInstance;
private final Logger m_logger;
private String m_autoConfigInstance;
private boolean m_autoConfigInvoked;
@@ -407,7 +407,7 @@
}
}
- private synchronized boolean makeAvailable() {
+ protected synchronized boolean makeAvailable() {
if (!m_isAvailable) {
m_isAvailable = true;
return true;
diff --git a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
index ad50d3f..39d4d59 100644
--- a/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
+++ b/dependencymanager/test/src/test/java/org/apache/felix/dependencymanager/test/ServiceDependencyTest.java
@@ -52,12 +52,15 @@
// create a service provider and consumer
Service sp = m.createService().setImplementation(new ServiceProvider(e)).setInterface(ServiceInterface.class.getName(), null);
Service sc = m.createService().setImplementation(new ServiceConsumer(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(true));
+ Service sc2 = m.createService().setImplementation(new ServiceConsumerCallbacks(e)).add(m.createServiceDependency().setService(ServiceInterface.class).setRequired(false).setCallbacks("add", "remove"));
m.add(sp);
m.add(sc);
- m.remove(sp);
m.remove(sc);
+ m.add(sc2);
+ m.remove(sp);
+ m.remove(sc2);
// ensure we executed all steps inside the component instance
- e.step(4);
+ e.step(6);
}
}
@@ -92,3 +95,18 @@
m_ensure.step(3);
}
}
+
+class ServiceConsumerCallbacks {
+ private final Ensure m_ensure;
+
+ public ServiceConsumerCallbacks(Ensure e) {
+ m_ensure = e;
+ }
+
+ public void add(ServiceInterface service) {
+ m_ensure.step(4);
+ }
+ public void remove(ServiceInterface service) {
+ m_ensure.step(5);
+ }
+}