Package org.jdrupes.vmoperator.common
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 contextL
- 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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The type of change reported byWatch.Response
as enum. -
Field Summary
Modifier and TypeFieldDescriptionprotected final K8sClient
protected final io.kubernetes.client.Discovery.APIResource
protected BiConsumer
<K8sClient, io.kubernetes.client.util.Watch.Response<O>> protected final Logger
protected final String
protected BiConsumer
<K8sObserver<O, L>, Throwable> protected final io.kubernetes.client.util.generic.options.ListOptions
protected final Thread
-
Constructor Summary
ConstructorDescriptionK8sObserver
(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. -
Method Summary
Modifier and TypeMethodDescriptionclient()
Returns the client.io.kubernetes.client.Discovery.APIResource
context()
Returns the context.Returns the observed namespace.handler
(BiConsumer<K8sClient, io.kubernetes.client.util.Watch.Response<O>> handler) Sets the handler.onTerminated
(BiConsumer<K8sObserver<O, L>, Throwable> onTerminated) Sets a function to invoke if the observer terminates.io.kubernetes.client.util.generic.options.ListOptions
options()
Returns the options for object selection.start()
Start the observer.stop()
Stops the observer.toString()
-
Field Details
-
logger
-
client
-
api
-
context
-
namespace
-
options
-
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>, onTerminatedThrowable>
-
-
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 classobjectListClass
- the object list classclient
- the clientcontext
- the contextnamespace
- the namespaceoptions
- 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 bystop()
.- Parameters:
onTerminated
- the on terminated- Returns:
- the observer
-
start
Start the observer.- Returns:
- the observer
-
stop
Stops the observer.- Returns:
- the observer
-
client
Returns the client.- Returns:
- the client
-
context
Returns the context.- Returns:
- the context
-
getNamespace
Returns the observed namespace.- Returns:
- the namespace
-
options
Returns the options for object selection.- Returns:
- the list options
-
toString
-