T - a type of Kubernetes resource@ThreadSafe public class Reflector<T extends HasMetadata> extends Object implements Closeable
EventCache so as to logically
"reflect" the contents of Kubernetes into the cache.
Instances of this class are safe for concurrent use by multiple
Threads.
This class loosely models the Reflector type in the tools/cache package of the client-go subproject of Kubernetes.
EventCache| Constructor and Description |
|---|
Reflector(X operation,
EventCache<T> eventCache)
Creates a new
Reflector. |
Reflector(X operation,
EventCache<T> eventCache,
Duration synchronizationInterval)
Creates a new
Reflector. |
Reflector(X operation,
EventCache<T> eventCache,
ScheduledExecutorService synchronizationExecutorService,
Duration synchronizationInterval)
Creates a new
Reflector. |
Reflector(X operation,
EventCache<T> eventCache,
ScheduledExecutorService synchronizationExecutorService,
Duration synchronizationInterval,
Function<? super Throwable,Boolean> synchronizationErrorHandler)
Creates a new
Reflector. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
|
protected Logger |
createLogger()
|
protected void |
onClose()
Invoked when
close() is invoked. |
protected boolean |
shouldSynchronize()
|
@NonBlocking Future<?> |
start()
Using the
operation supplied at construction time,
lists appropriate Kubernetes
resources, and then, on a separate Thread, sets up a watch on them, calling EventCache.replace(Collection, Object) and EventCache.add(Object, AbstractEvent.Type, HasMetadata) methods
as appropriate. |
protected final Logger logger
createLogger()public Reflector(X operation, EventCache<T> eventCache)
Reflector.X - a type that is both an appropriate kind of Listable and VersionWatchable, such as the kind of
operation returned by DefaultKubernetesClient.configMaps() and the likeoperation - a Listable and a VersionWatchable that can report information from a Kubernetes
cluster; must not be nulleventCache - an EventCache that will be
synchronized on and into which Events will be
logically "reflected"; must not be nullNullPointerException - if operation or eventCache is nullIllegalStateException - if the createLogger()
method returns nullReflector(Listable, EventCache, ScheduledExecutorService,
Duration, Function),
start()public Reflector(X operation, EventCache<T> eventCache, Duration synchronizationInterval)
Reflector.X - a type that is both an appropriate kind of Listable and VersionWatchable, such as the kind of
operation returned by DefaultKubernetesClient.configMaps() and the likeoperation - a Listable and a VersionWatchable that can report information from a Kubernetes
cluster; must not be nulleventCache - an EventCache that will be
synchronized on and into which Events will be
logically "reflected"; must not be nullsynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; interpreted with a
granularity of seconds; may be null or semantically equal
to 0 seconds in which case no synchronization will occurNullPointerException - if operation or eventCache is nullIllegalStateException - if the createLogger()
method returns nullReflector(Listable, EventCache, ScheduledExecutorService,
Duration, Function),
start()public Reflector(X operation, EventCache<T> eventCache, ScheduledExecutorService synchronizationExecutorService, Duration synchronizationInterval)
Reflector.X - a type that is both an appropriate kind of Listable and VersionWatchable, such as the kind of
operation returned by DefaultKubernetesClient.configMaps() and the likeoperation - a Listable and a VersionWatchable that can report information from a Kubernetes
cluster; must not be nulleventCache - an EventCache that will be
synchronized on and into which Events will be
logically "reflected"; must not be nullsynchronizationExecutorService - a ScheduledExecutorService to be used to tell the supplied EventCache to synchronize
on a schedule; may be null in which case no
synchronization will occursynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; may be null in
which case no synchronization will occurNullPointerException - if operation or eventCache is nullIllegalStateException - if the createLogger()
method returns nullReflector(Listable, EventCache, ScheduledExecutorService,
Duration, Function),
start()public Reflector(X operation, EventCache<T> eventCache, ScheduledExecutorService synchronizationExecutorService, Duration synchronizationInterval, Function<? super Throwable,Boolean> synchronizationErrorHandler)
Reflector.X - a type that is both an appropriate kind of Listable and VersionWatchable, such as the kind of
operation returned by DefaultKubernetesClient.configMaps() and the likeoperation - a Listable and a VersionWatchable that can report information from a Kubernetes
cluster; must not be nulleventCache - an EventCache that will be
synchronized on and into which Events will be
logically "reflected"; must not be nullsynchronizationExecutorService - a ScheduledExecutorService to be used to tell the supplied EventCache to synchronize
on a schedule; may be null in which case no
synchronization will occursynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; may be null in
which case no synchronization will occursynchronizationErrorHandler - a Function that
consumes a Throwable and returns a Boolean
indicating whether the error represented by the Throwable
in question was handled or not; may be nullNullPointerException - if operation or eventCache is nullIllegalStateException - if the createLogger()
method returns nullstart()protected Logger createLogger()
Logger that will be used for this Reflector.
This method never returns null.
Overrides of this method must not return null.
null Loggerpublic final void close() throws IOException
Reflector by terminating any
Threads that it has started and invoking the onClose() method while holding this Reflector's
monitor.close in interface Closeableclose in interface AutoCloseableIOException - if an error occursonClose()protected boolean shouldSynchronize()
Reflector
should cause its EventCache to synchronize.
The default implementation of this method returns true
if this Reflector was constructed with an explicit
synchronization interval or ScheduledExecutorService or
both.
This code follows the Go code in the Kubernetes client-go/tools/cache package. One thing that becomes clear
when looking at all of this through an object-oriented lens is
that it is the EventCache (the delta_fifo, in the
Go code) that is ultimately in charge of synchronizing. It is
not clear why in the Go code this is a function of a reflector.
In an object-oriented world, perhaps the EventCache
itself should be in charge of resynchronization schedules, but we
choose to follow the Go code's division of responsibilities
here.
true if this Reflector should cause its
EventCache to synchronize; false otherwise@NonBlocking public final @NonBlocking Future<?> start() throws IOException
operation supplied at construction time,
lists appropriate Kubernetes
resources, and then, on a separate Thread, sets up a watch on them, calling EventCache.replace(Collection, Object) and EventCache.add(Object, AbstractEvent.Type, HasMetadata) methods
as appropriate.
For convenience only, this method returns a
Future representing any scheduled synchronization task
created as a result of the user's having supplied a Duration at construction time. The return value may be (and
usually is) safely ignored. Invoking Future.cancel(boolean) on the returned Future will
result in the scheduled synchronization task being cancelled
irrevocably. Notably, invoking Future.cancel(boolean) on the returned Future will
not close this Reflector.
This method never returns null.
The calling Thread is not blocked by invocations of
this method.
This method loosely models the Run function in reflector.go together with the ListAndWatch function in the same file.
Future representing a scheduled synchronization
operation; never nullIOException - if a watch has previously been established
and could not be closedKubernetesClientException - if the initial attempt to
list Kubernetes resources failsclose()Copyright © 2017–2021, microBean™. All rights reserved.