Class K8sObserver<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject>

java.lang.Object
org.jdrupes.vmoperator.common.K8sObserver<O,L>
Type Parameters:
O - the object type for the context
L - the object list type for the context

public class K8sObserver<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject> extends Object
An observer that watches namespaced resources in a given context and invokes a handler on changes.
  • Field Details

    • logger

      protected final Logger logger
    • client

      protected final K8sClient client
    • api

      protected final io.kubernetes.client.util.generic.GenericKubernetesApi<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject> api
    • context

      protected final io.kubernetes.client.Discovery.APIResource context
    • namespace

      protected final String namespace
    • options

      protected final io.kubernetes.client.util.generic.options.ListOptions options
    • thread

      protected final Thread thread
    • handler

      protected BiConsumer<K8sClient,io.kubernetes.client.util.Watch.Response<O extends io.kubernetes.client.common.KubernetesObject>> handler
    • onTerminated

      protected BiConsumer<K8sObserver<O extends io.kubernetes.client.common.KubernetesObject,L extends io.kubernetes.client.common.KubernetesListObject>,Throwable> onTerminated
  • Constructor Details

    • K8sObserver

      public K8sObserver(Class<O> objectClass, Class<L> objectListClass, K8sClient client, io.kubernetes.client.Discovery.APIResource context, String namespace, io.kubernetes.client.util.generic.options.ListOptions options)
      Create and start a new observer for objects in the given context (using preferred version) and namespace with the given options.
      Parameters:
      objectClass - the object class
      objectListClass - the object list class
      client - the client
      context - the context
      namespace - the namespace
      options - the options
  • Method Details

    • handler

      public K8sObserver<O,L> handler(BiConsumer<K8sClient,io.kubernetes.client.util.Watch.Response<O>> handler)
      Sets the handler.
      Parameters:
      handler - the handler
      Returns:
      the observer
    • onTerminated

      Sets a function to invoke if the observer terminates.

      First argument is this observer, the second is the throwable that caused the abnormal termination or null if the observer was terminated by stop().

      Parameters:
      onTerminated - the on terminated
      Returns:
      the observer
    • start

      public K8sObserver<O,L> start()
      Start the observer.
      Returns:
      the observer
    • stop

      public K8sObserver<O,L> stop()
      Stops the observer.
      Returns:
      the observer
    • client

      public K8sClient client()
      Returns the client.
      Returns:
      the client
    • context

      public io.kubernetes.client.Discovery.APIResource context()
      Returns the context.
      Returns:
      the context
    • getNamespace

      public String getNamespace()
      Returns the observed namespace.
      Returns:
      the namespace
    • options

      public io.kubernetes.client.util.generic.options.ListOptions options()
      Returns the options for object selection.
      Returns:
      the list options
    • toString

      public String toString()
      Overrides:
      toString in class Object