Permalink
Browse files

[ARIES-962] Deadlock while stopping OSGi container

git-svn-id: https://svn.apache.org/repos/asf/aries/trunk@1421113 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information...
1 parent 2c635b1 commit b069aa47c636a149300b135177f9f4593652d40c @gnodet gnodet committed Dec 13, 2012
View
15 ...re/src/main/java/org/apache/aries/blueprint/container/AbstractServiceReferenceRecipe.java
@@ -83,6 +83,7 @@
/** The list of listeners for this reference. This list will be lazy created */
protected List<Listener> listeners;
+ protected final Object monitor = new Object();
private final List<ServiceReference> references = new ArrayList<ServiceReference>();
private final AtomicBoolean started = new AtomicBoolean();
private final AtomicBoolean satisfied = new AtomicBoolean();
@@ -129,7 +130,7 @@ public void start(SatisfactionListener listener) {
satisfied.set(optional);
// Synchronized block on references so that service events won't interfere with initial references tracking
// though this may not be sufficient because we don't control ordering of those events
- synchronized (references) {
+ synchronized (monitor) {
getBundleContextForServiceLookup().addServiceListener(this, getOsgiFilter());
ServiceReference[] references = getBundleContextForServiceLookup().getServiceReferences(null, getOsgiFilter());
if (references != null) {
@@ -149,7 +150,7 @@ public void start(SatisfactionListener listener) {
public void stop() {
if (started.compareAndSet(true, false)) {
- synchronized (references) {
+ synchronized (monitor) {
getBundleContextForServiceLookup().removeServiceListener(this);
doStop();
for (Iterator<ServiceReference> it = references.iterator(); it.hasNext();) {
@@ -330,7 +331,7 @@ public void run() {
private void serviceAdded(ServiceReference ref) {
LOGGER.debug("Tracking reference {} for OSGi service {}", ref, getOsgiFilter());
if (isStarted()) {
- synchronized (references) {
+ synchronized (monitor) {
if (references.contains(ref)) {
return;
}
@@ -344,7 +345,7 @@ private void serviceAdded(ServiceReference ref) {
private void serviceModified(ServiceReference ref) {
// ref must be in references and must be satisfied
if (isStarted()) {
- synchronized (references) {
+ synchronized (monitor) {
if (references.contains(ref)) {
track(ref);
}
@@ -357,7 +358,7 @@ private void serviceRemoved(ServiceReference ref) {
LOGGER.debug("Untracking reference {} for OSGi service {}", ref, getOsgiFilter());
boolean removed;
boolean satisfied;
- synchronized (references) {
+ synchronized (monitor) {
removed = references.remove(ref);
satisfied = optional || !references.isEmpty();
}
@@ -439,13 +440,13 @@ protected void unbind(ServiceReference reference, Object service) {
}
public List<ServiceReference> getServiceReferences() {
- synchronized (references) {
+ synchronized (monitor) {
return new ArrayList<ServiceReference>(references);
}
}
public ServiceReference getBestServiceReference() {
- synchronized (references) {
+ synchronized (monitor) {
int length = references.size();
if (length == 0) { /* if no service is being tracked */
return null;
View
3 ...lueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceListRecipe.java
@@ -50,8 +50,7 @@
private final List<ManagedCollection> collections = new ArrayList<ManagedCollection>();
private final DynamicCollection<ServiceDispatcher> storage = new DynamicCollection<ServiceDispatcher>();
private final List<ServiceDispatcher> unboundDispatchers = new ArrayList<ServiceDispatcher>();
- private final Object monitor = new Object();
-
+
public ReferenceListRecipe(String name,
ExtendedBlueprintContainer blueprintContainer,
ReferenceListMetadata metadata,
View
1 ...nt/blueprint-core/src/main/java/org/apache/aries/blueprint/container/ReferenceRecipe.java
@@ -61,7 +61,6 @@
private volatile ServiceReference trackedServiceReference;
private volatile Object trackedService;
private Object defaultBean;
- private final Object monitor = new Object();
private final Collection<Class<?>> proxyChildBeanClasses;
private final Collection<WeakReference<Voidable>> proxiedChildren;

0 comments on commit b069aa4

Please sign in to comment.