Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsboshev2009-08-06 17:46:39 +0000
committersboshev2009-08-06 17:46:39 +0000
commitc1a281ef1dac7a90dd88287eb304ddbf05e56262 (patch)
tree30b6648bc908fa2ec5636d66711e9c00733e5f78
parentf6ef3db27908e853ae952d8b1f692e6095cf194b (diff)
downloadrt.equinox.bundles-c1a281ef1dac7a90dd88287eb304ddbf05e56262.tar.gz
rt.equinox.bundles-c1a281ef1dac7a90dd88287eb304ddbf05e56262.tar.xz
rt.equinox.bundles-c1a281ef1dac7a90dd88287eb304ddbf05e56262.zip
Bug 285464. [DS] dependency injection does not work when starting more than one instance of a serviceR35x_v20090806
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/SCRmessages.properties1
-rw-r--r--bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ComponentReference.java118
2 files changed, 36 insertions, 83 deletions
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/SCRmessages.properties b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/SCRmessages.properties
index 9399c8bb7..16ddd7f0c 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/SCRmessages.properties
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/SCRmessages.properties
@@ -166,7 +166,6 @@ SENT_ENABLING_REQUEST=Sent request for enabling component {0}
SERVICE_EVENT_TYPE=Service event type: {0}
SERVICE_NO_LONGER_USED=ServiceReg.ungetService(): service ''{0}'' no longer used, disposing object = {1}
SERVICE_REFERENCE_ALREADY_BOUND=[SCR] ComponentReference.bind(): service reference {0} is already bound to instance {1}
-SERVICE_REFERENCE_BOUND=[SCR] ComponentReference.bind(): service reference {0} is already bound to another instance: {1}
SERVICE_UNREGISTERED_BECAUSE_COMP_DISPOSED=The service of component {0} was unregistered because the component is already disposed\!
SERVICE_USAGE_COUNT=service ''{0}'' is used {1} time(s)
SPECIFIED_ACTIVATE_METHOD_NOT_FOUND=[SCR] Cannot activate instance {0} of component {1}! The specified activate method was not found!
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ComponentReference.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ComponentReference.java
index c6144d1fd..09a0c4158 100644
--- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ComponentReference.java
+++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ComponentReference.java
@@ -294,34 +294,19 @@ public class ComponentReference implements Externalizable {
final void bind(Reference reference, ComponentInstance instance, ServiceReference serviceReference) throws Exception {
if (bind != null) {
// DON'T rebind the same object again
- boolean isComponentFactory = component.factory != null;
synchronized (serviceReferences) {
- if (isComponentFactory) {
- Vector instances = (Vector) serviceReferences.get(serviceReference);
- if (instances == null) {
- instances = new Vector(2);
- instances.addElement(instance);
- serviceReferences.put(serviceReference, instances);
- } else if (instances.contains(instance)) {
- if (reference.isUnary()) {
- logWarning(NLS.bind(Messages.SERVICE_REFERENCE_ALREADY_BOUND, serviceReference, instance), null, reference);
- }
- return;
- } else {
- instances.addElement(instance);
+ Vector instances = (Vector) serviceReferences.get(serviceReference);
+ if (instances == null) {
+ instances = new Vector(1);
+ instances.addElement(instance);
+ serviceReferences.put(serviceReference, instances);
+ } else if (instances.contains(instance)) {
+ if (reference.isUnary()) {
+ logWarning(NLS.bind(Messages.SERVICE_REFERENCE_ALREADY_BOUND, serviceReference, instance), null, reference);
}
+ return;
} else {
- Object compInstance = serviceReferences.get(serviceReference);
- if (compInstance == instance) {
- if (reference.isUnary()) {
- logWarning(NLS.bind(Messages.SERVICE_REFERENCE_ALREADY_BOUND, serviceReference, instance), null, reference);
- }
- return;
- } else if (compInstance != null) {
- logWarning(NLS.bind(Messages.SERVICE_REFERENCE_BOUND, serviceReference, compInstance), null, reference);
- return;
- }
- serviceReferences.put(serviceReference, instance);
+ instances.addElement(instance);
}
}
// retrieve the method from cache
@@ -391,14 +376,9 @@ public class ComponentReference implements Externalizable {
}
private void removeServiceReference(ServiceReference serviceReference, ComponentInstance instance) {
- boolean isComponentFactory = component.factory != null;
- if (isComponentFactory) {
- Vector instances = (Vector) serviceReferences.get(serviceReference);
- instances.removeElement(instance);
- if (instances.isEmpty()) {
- serviceReferences.remove(serviceReference);
- }
- } else {
+ Vector instances = (Vector) serviceReferences.get(serviceReference);
+ instances.removeElement(instance);
+ if (instances.isEmpty()) {
serviceReferences.remove(serviceReference);
}
}
@@ -406,48 +386,27 @@ public class ComponentReference implements Externalizable {
public final void unbind(Reference reference, ComponentInstance instance, ServiceReference serviceReference) {
// don't unbind an object that wasn't bound
boolean referenceExists = true;
- boolean componentFactory = (component.factory != null);
synchronized (serviceReferences) {
- if (componentFactory) {
- Vector instances = (Vector) serviceReferences.get(serviceReference);
- if (instances == null) {
- referenceExists = false;
- } else {
- if (!instances.contains(instance)) {
- logWarning(NLS.bind(Messages.INSTANCE_NOT_BOUND, instance), null, reference);
- return;
- }
- }
+ Vector instances = (Vector) serviceReferences.get(serviceReference);
+ if (instances == null) {
+ referenceExists = false;
} else {
- Object compInstance = serviceReferences.get(serviceReference);
- if (compInstance == null) {
- referenceExists = false;
- } else {
- if (compInstance != instance) {
- logWarning(NLS.bind(Messages.INSTANCE_NOT_BOUND, instance), null, reference);
- return;
- }
+ if (!instances.contains(instance)) {
+ logWarning(NLS.bind(Messages.INSTANCE_NOT_BOUND, instance), null, reference);
+ return;
}
}
if (referenceExists) {
- if (componentFactory) {
- Vector instances = (Vector) serviceReferencesToUnbind.get(serviceReference);
- if (instances != null && instances.contains(instance)) {
- //the service reference is already in process of unbinding
- return;
- }
- if (instances == null) {
- instances = new Vector(2);
- serviceReferencesToUnbind.put(serviceReference, instances);
- }
- instances.addElement(instance);
- } else {
- if (serviceReferencesToUnbind.get(serviceReference) == instance) {
- //the service reference is already in process of unbinding
- return;
- }
- serviceReferencesToUnbind.put(serviceReference, instance);
+ Vector instancesToUnbind = (Vector) serviceReferencesToUnbind.get(serviceReference);
+ if (instancesToUnbind != null && instancesToUnbind.contains(instance)) {
+ //the service reference is already in process of unbinding
+ return;
+ }
+ if (instancesToUnbind == null) {
+ instancesToUnbind = new Vector(1);
+ serviceReferencesToUnbind.put(serviceReference, instancesToUnbind);
}
+ instancesToUnbind.addElement(instance);
}
}
if (!referenceExists) {
@@ -506,20 +465,15 @@ public class ComponentReference implements Externalizable {
}
} finally {
synchronized (serviceReferences) {
- if (componentFactory) {
- Vector instances = (Vector) serviceReferences.get(serviceReference);
- instances.removeElement(instance);
- if (instances.isEmpty()) {
- serviceReferences.remove(serviceReference);
- }
-
- instances = (Vector) serviceReferencesToUnbind.get(serviceReference);
- instances.removeElement(instance);
- if (instances.isEmpty()) {
- serviceReferencesToUnbind.remove(serviceReference);
- }
- } else {
+ Vector instances = (Vector) serviceReferences.get(serviceReference);
+ instances.removeElement(instance);
+ if (instances.isEmpty()) {
serviceReferences.remove(serviceReference);
+ }
+
+ instances = (Vector) serviceReferencesToUnbind.get(serviceReference);
+ instances.removeElement(instance);
+ if (instances.isEmpty()) {
serviceReferencesToUnbind.remove(serviceReference);
}
}

Back to the top