Class DataRoutingStateAdapter

java.lang.Object
com.illumon.iris.db.v2.routing.impl.kv.DataRoutingStateAdapter
All Implemented Interfaces:
WatchClient.UnitListener

public class DataRoutingStateAdapter extends Object implements WatchClient.UnitListener
Adapts a WatchClient.UnitListener into a WatchClient.StateListener. Track all kv state and updates for the routing-file prefix, and provide synchronized access to current data and routing service.
  • Method Details

    • getDataRoutingYmlString

      @Nullable public @Nullable String getDataRoutingYmlString()
      Get the data routing data as a yaml String. This is the routing file only and does not include additional DISes.
      Returns:
      the data routing configuration, or null if not present
    • getDataRoutingService

      @NotNull public @NotNull DataRoutingService getDataRoutingService()
      Get the data routing service. This is the etcd implementation, parsed from the routing file and additional DISes. The service might be invalid/non-functional if the routing file is missing, or there are errors parsing the configuration.
      Returns:
      the data routing service
    • getRoutingFileRev

      public long getRoutingFileRev()
      Get the current wrt revision of the routing file.
      Returns:
      the current wrt of the routing file, or 0 if it does not exist.
    • getDisesRev

      public long getDisesRev()
      Get the current wrt revision of the additional DISes container.
      Returns:
      the current wrt of the DISes prefix, or 0 if it does not exist.
    • getDisRev

      public long getDisRev(String disName)
      Get the current wrt revision of the named additional DIS file.
      Parameters:
      disName - the name of the DIS
      Returns:
      the current wrt of the named DIS, or 0 if it does not exist.
    • getExtraDisMap

      @NotNull public @NotNull Map<String,DataImportServiceConfig> getExtraDisMap()
      Get the configured additional DISes as a map.
      Returns:
      map of additional DISes
    • getExtraDisNames

      @NotNull public @NotNull Set<String> getExtraDisNames()
      Get the configured additional DIS names as a set.
      Returns:
      set of additional DIS names
    • getExtraDisText

      @NotNull public @NotNull Map<String,String> getExtraDisText()
      Get the configured additional DISes as a map of name to raw yml string. For error handling.
      Returns:
      map of additional DIS names to raw yml strings
    • publishInitial

      public void publishInitial(@NotNull @NotNull HeaderResponse initialHeader, @NotNull @NotNull KeyValuesCollection initialState)
      Initialize the state.
      Parameters:
      initialHeader - the initial header
      initialState - the initial state - all keys and values starting at the GetPrefix root
    • onNext

      public void onNext(@NotNull @NotNull WatchResponseUnit unit)
      Description copied from interface: WatchClient.UnitListener
      Invoked on new events.

      Can be called many times but is never called after WatchClient.UnitListener.onError(Throwable) or WatchClient.UnitListener.onCompleted() are called.

      Specified by:
      onNext in interface WatchClient.UnitListener
      Parameters:
      unit - the watch response unit
    • onError

      public void onError(@NotNull @NotNull Throwable t)
      Description copied from interface: WatchClient.UnitListener
      Invoked on errors.

      May only be called once and if called it must be the last method called.

      Specified by:
      onError in interface WatchClient.UnitListener
      Parameters:
      t - the error
    • onCompleted

      public void onCompleted()
      Description copied from interface: WatchClient.UnitListener
      Invoked on completion.

      May only be called once and if called it must be the last method called.

      Specified by:
      onCompleted in interface WatchClient.UnitListener
    • createWatch

      public CompletableFuture<WatchClient.Watch> createWatch(@NotNull @NotNull KVClient kvClient, @NotNull @NotNull WatchClient watchClient, @NotNull @NotNull GetPrefix request)
      Returns a future that will create, but not start, the watch.
      Parameters:
      kvClient - the kv client
      watchClient - the watch client
      request - the get prefix request
      Returns:
      a future for the watch