All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.launchdarkly.sdk.server.DataStoreUpdatesImpl Maven / Gradle / Ivy

There is a newer version: 7.5.0
Show newest version
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);
      }
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy