Skip to content

Commit

Permalink
[FELIX-6066] Prevent duplicate activation of ConfigurationManager
Browse files Browse the repository at this point in the history
  • Loading branch information
grgrzybek committed Feb 21, 2019
1 parent 207a63c commit 10b1b03
Showing 1 changed file with 25 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ public void run()
{
deactivate();
}
activate(holder.getPersistenceManager());
if (!holder.isActivated()) {
activate(holder.getPersistenceManager());
holder.setActivated();
}
}
});
}
Expand All @@ -197,7 +200,7 @@ public void modifiedService(final ServiceReference<PersistenceManager> reference
this.holders.remove(holder);
this.holders.add(new Holder(reference, holder.getPersistenceManager()));
Collections.sort(this.holders);
if ( holders.get(0) == holder && oldHolder.compareTo(holder) != 0 )
if ( holders.get(0) == holder && oldHolder != null && oldHolder.compareTo(holder) != 0 )
{
this.workerQueue.enqueue(new Runnable()
{
Expand All @@ -206,7 +209,10 @@ public void modifiedService(final ServiceReference<PersistenceManager> reference
public void run()
{
deactivate();
activate(holder.getPersistenceManager());
if (!holder.isActivated()) {
activate(holder.getPersistenceManager());
holder.setActivated();
}
}
});
}
Expand Down Expand Up @@ -234,7 +240,11 @@ public void run()
deactivate();
if ( !holders.isEmpty() )
{
activate(holders.get(0).getPersistenceManager());
Holder h = holders.get(0);
if (!h.isActivated()) {
activate(h.getPersistenceManager());
h.setActivated();
}
}
}
});
Expand All @@ -248,6 +258,9 @@ public static final class Holder implements Comparable<Holder>

private final ExtPersistenceManager manager;

// no need to synchronize, as it's changed only in WorkQueue tasks
private boolean activated;

public Holder(final ServiceReference<PersistenceManager> ref, final ExtPersistenceManager epm)
{
this.reference = ref;
Expand All @@ -266,6 +279,14 @@ public int compareTo(final Holder o)
return -reference.compareTo(o.reference);
}

public boolean isActivated() {
return activated;
}

public void setActivated() {
this.activated = true;
}

@Override
public int hashCode()
{
Expand Down

0 comments on commit 10b1b03

Please sign in to comment.