[FIX] call onDisabled at first if appropriate
Original commit: elastic/x-pack-elasticsearch@72ddcfd197
This commit is contained in:
parent
17924dee96
commit
0fb0f24e36
|
@ -217,7 +217,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
public Set<String> enabledFeatures() {
|
public Set<String> enabledFeatures() {
|
||||||
Set<String> enabledFeatures = Sets.newHashSet();
|
Set<String> enabledFeatures = Sets.newHashSet();
|
||||||
for (ListenerHolder holder : registeredListeners) {
|
for (ListenerHolder holder : registeredListeners) {
|
||||||
if (holder.enabled.get()) {
|
if (holder.enabled) {
|
||||||
enabledFeatures.add(holder.feature);
|
enabledFeatures.add(holder.feature);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -868,7 +868,8 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
final AtomicLong currentExpiryDate = new AtomicLong(-1l);
|
final AtomicLong currentExpiryDate = new AtomicLong(-1l);
|
||||||
final Queue<ScheduledFuture> notificationQueue;
|
final Queue<ScheduledFuture> 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<ExpirationCallback> expirationCallbacks, Listener listener, Queue<ScheduledFuture> notificationQueue) {
|
private ListenerHolder(String feature, TrialLicenseOptions trialLicenseOptions, Collection<ExpirationCallback> expirationCallbacks, Listener listener, Queue<ScheduledFuture> notificationQueue) {
|
||||||
this.feature = feature;
|
this.feature = feature;
|
||||||
|
@ -878,16 +879,20 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
this.notificationQueue = notificationQueue;
|
this.notificationQueue = notificationQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void enableFeatureIfNeeded(License license) {
|
private synchronized void enableFeatureIfNeeded(License license) {
|
||||||
if (enabled.compareAndSet(false, true)) {
|
if (!initialized || !enabled) {
|
||||||
listener.onEnabled(license);
|
listener.onEnabled(license);
|
||||||
|
initialized = true;
|
||||||
|
enabled = true;
|
||||||
logger.info("license for [" + feature + "] - valid");
|
logger.info("license for [" + feature + "] - valid");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disableFeatureIfNeeded(License license, boolean log) {
|
private synchronized void disableFeatureIfNeeded(License license, boolean log) {
|
||||||
if (enabled.compareAndSet(true, false)) {
|
if (!initialized || enabled) {
|
||||||
listener.onDisabled(license);
|
listener.onDisabled(license);
|
||||||
|
initialized = true;
|
||||||
|
enabled = false;
|
||||||
if (log) {
|
if (log) {
|
||||||
logger.info("license for [" + feature + "] - expired");
|
logger.info("license for [" + feature + "] - expired");
|
||||||
}
|
}
|
||||||
|
@ -985,7 +990,7 @@ public class LicensesService extends AbstractLifecycleComponent<LicensesService>
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "(feature: " + feature + ", enabled: " + enabled.get() + ")";
|
return "(feature: " + feature + ", enabled: " + enabled + ")";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue