com.launchdarkly.sdk.server.DataStoreUpdatesImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of launchdarkly-java-server-sdk Show documentation
Show all versions of launchdarkly-java-server-sdk Show documentation
Official LaunchDarkly SDK for Java
package com.launchdarkly.sdk.server;
import com.launchdarkly.sdk.server.interfaces.DataStoreStatusProvider;
import com.launchdarkly.sdk.server.interfaces.DataStoreUpdates;
import java.util.concurrent.atomic.AtomicReference;
class DataStoreUpdatesImpl implements DataStoreUpdates {
// package-private because it's convenient to use these from DataStoreStatusProviderImpl
final EventBroadcasterImpl statusBroadcaster;
final AtomicReference lastStatus;
DataStoreUpdatesImpl(
EventBroadcasterImpl statusBroadcaster
) {
this.statusBroadcaster = statusBroadcaster;
this.lastStatus = new AtomicReference<>(new DataStoreStatusProvider.Status(true, false)); // initially "available"
}
@Override
public void updateStatus(DataStoreStatusProvider.Status newStatus) {
if (newStatus != null) {
DataStoreStatusProvider.Status oldStatus = lastStatus.getAndSet(newStatus);
if (!newStatus.equals(oldStatus)) {
statusBroadcaster.broadcast(newStatus);
}
}
}
}