From 10b1b031f914f58f30f92f745af1d790da224f4f Mon Sep 17 00:00:00 2001 From: Grzegorz Grzybek Date: Thu, 21 Feb 2019 17:23:26 +0100 Subject: [PATCH] [FELIX-6066] Prevent duplicate activation of ConfigurationManager --- .../PersistenceManagerTracker.java | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java b/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java index 4b63419c3f9..d4ea2c757c9 100644 --- a/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java +++ b/configadmin/src/main/java/org/apache/felix/cm/impl/persistence/PersistenceManagerTracker.java @@ -175,7 +175,10 @@ public void run() { deactivate(); } - activate(holder.getPersistenceManager()); + if (!holder.isActivated()) { + activate(holder.getPersistenceManager()); + holder.setActivated(); + } } }); } @@ -197,7 +200,7 @@ public void modifiedService(final ServiceReference 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() { @@ -206,7 +209,10 @@ public void modifiedService(final ServiceReference reference public void run() { deactivate(); - activate(holder.getPersistenceManager()); + if (!holder.isActivated()) { + activate(holder.getPersistenceManager()); + holder.setActivated(); + } } }); } @@ -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(); + } } } }); @@ -248,6 +258,9 @@ public static final class Holder implements Comparable private final ExtPersistenceManager manager; + // no need to synchronize, as it's changed only in WorkQueue tasks + private boolean activated; + public Holder(final ServiceReference ref, final ExtPersistenceManager epm) { this.reference = ref; @@ -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() {