From 0fb0f24e36bcaaaf7f35bc55db9ac6d96019f2dd Mon Sep 17 00:00:00 2001 From: Areek Zillur Date: Mon, 26 Jan 2015 18:28:39 -0500 Subject: [PATCH] [FIX] call onDisabled at first if appropriate Original commit: elastic/x-pack-elasticsearch@72ddcfd19710ce9f3780389e30b8ab79a51cfb02 --- .../license/plugin/core/LicensesService.java | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java b/plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java index dbf18871492..6e80656b5e7 100644 --- a/plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java +++ b/plugin/src/main/java/org/elasticsearch/license/plugin/core/LicensesService.java @@ -217,7 +217,7 @@ public class LicensesService extends AbstractLifecycleComponent public Set enabledFeatures() { Set enabledFeatures = Sets.newHashSet(); for (ListenerHolder holder : registeredListeners) { - if (holder.enabled.get()) { + if (holder.enabled) { enabledFeatures.add(holder.feature); } } @@ -868,7 +868,8 @@ public class LicensesService extends AbstractLifecycleComponent final AtomicLong currentExpiryDate = new AtomicLong(-1l); final Queue notificationQueue; - volatile AtomicBoolean enabled = new AtomicBoolean(false); // by default, a consumer plugin should be disabled + volatile boolean initialized = false; + volatile boolean enabled = false; // by default, a consumer plugin should be disabled private ListenerHolder(String feature, TrialLicenseOptions trialLicenseOptions, Collection expirationCallbacks, Listener listener, Queue notificationQueue) { this.feature = feature; @@ -878,16 +879,20 @@ public class LicensesService extends AbstractLifecycleComponent this.notificationQueue = notificationQueue; } - private void enableFeatureIfNeeded(License license) { - if (enabled.compareAndSet(false, true)) { + private synchronized void enableFeatureIfNeeded(License license) { + if (!initialized || !enabled) { listener.onEnabled(license); + initialized = true; + enabled = true; logger.info("license for [" + feature + "] - valid"); } } - private void disableFeatureIfNeeded(License license, boolean log) { - if (enabled.compareAndSet(true, false)) { + private synchronized void disableFeatureIfNeeded(License license, boolean log) { + if (!initialized || enabled) { listener.onDisabled(license); + initialized = true; + enabled = false; if (log) { logger.info("license for [" + feature + "] - expired"); } @@ -985,7 +990,7 @@ public class LicensesService extends AbstractLifecycleComponent } public String toString() { - return "(feature: " + feature + ", enabled: " + enabled.get() + ")"; + return "(feature: " + feature + ", enabled: " + enabled + ")"; } }