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.
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. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
|
protected Logger |
createLogger()
|
protected void |
onClose()
Invoked when
close() is invoked. |
protected boolean |
shouldSynchronize()
|
void |
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),
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),
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 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.
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 this is a function of a reflector. In an
object-oriented world, perhaps the EventCache itself
should be in charge of resynchronization schedules.
true if this Reflector should cause its
EventCache to synchronize; false otherwise@NonBlocking public final void start()
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.
The calling Thread is not blocked by invocations of
this method.
close()Copyright © 2017–2018, microBean. All rights reserved.