T - a Kubernetes resource type@Immutable @ThreadSafe public class Controller<T extends HasMetadata> extends Object implements Closeable
Reflector, a VersionWatchable and Listable implementation, an
(internal) EventQueueCollection, a Map of known
Kubernetes resources and an EventQueue Consumer
that mirrors Kubernetes cluster
events into a collection of
EventQueues and arranges for their consumption
and processing.
Starting a Controller starts the
Consumer supplied at construction time, and
starts the embedded
Reflector. Closing a Controller closes its embedded
Reflector and causes the Consumer
supplied at construction time to stop receiving
Events.
Several protected methods in this class exist to make
customization easier; none require overriding and their default
behavior is usually just fine.
Instances of this class are safe for concurrent use by multiple threads.
Reflector,
EventQueueCollection,
ResourceTrackingEventQueueConsumer,
start(),
close()| Modifier and Type | Field and Description |
|---|---|
protected Logger |
logger
A
Logger used by this Controller. |
| Constructor and Description |
|---|
Controller(X operation,
Consumer<? super EventQueue<? extends T>> siphon)
Creates a new
Controller but does not start it. |
Controller(X operation,
Duration synchronizationInterval,
Consumer<? super EventQueue<? extends T>> siphon)
Creates a new
Controller but does not start it. |
Controller(X operation,
Duration synchronizationInterval,
Map<Object,T> knownObjects,
Consumer<? super EventQueue<? extends T>> siphon)
Creates a new
Controller but does not start it. |
Controller(X operation,
Map<Object,T> knownObjects,
Consumer<? super EventQueue<? extends T>> siphon)
Creates a new
Controller but does not start it. |
Controller(X operation,
ScheduledExecutorService synchronizationExecutorService,
Duration synchronizationInterval,
Map<Object,T> knownObjects,
Consumer<? super EventQueue<? extends T>> siphon)
Creates a new
Controller but does not start it. |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the embedded
Reflector and then closes the embedded
EventQueueCollection, handling exceptions
appropriately. |
protected Event<T> |
createEvent(Object source,
AbstractEvent.Type eventType,
T resource)
Creates a new
Event when invoked. |
protected EventQueue<T> |
createEventQueue(Object key)
Creates a new
EventQueue when invoked. |
protected Logger |
createLogger()
Returns a
Logger for use by this Controller. |
protected Object |
getKey(T resource)
Returns a key that can be used to identify the supplied
HasMetadata. |
protected void |
onClose()
|
protected boolean |
shouldSynchronize()
Returns if the embedded
Reflector should synchronize. |
void |
start()
|
protected final Logger logger
createLogger()public Controller(X operation, Consumer<? super EventQueue<? extends T>> siphon)
Controller but does not start it.X - a Listable and VersionWatchable that
will be used by the embedded Reflector; must not be
nulloperation - a Listable and a VersionWatchable that produces Kubernetes events; must not be
nullsiphon - the Consumer that will process each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or siphon is nullController(Listable, ScheduledExecutorService, Duration,
Map, Consumer),
start()public Controller(X operation, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> siphon)
Controller but does not start it.X - a Listable and VersionWatchable that
will be used by the embedded Reflector; must not be
nulloperation - a Listable and a VersionWatchable that produces Kubernetes events; must not be
nullknownObjects - a Map containing the last known state
of Kubernetes resources the embedded EventQueueCollection
is caching events for; may be null if this Controller is not interested in tracking deletions of objects;
if non-null will be synchronized on by this
class during retrieval and traversal operationssiphon - the Consumer that will process each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or siphon is nullController(Listable, ScheduledExecutorService, Duration,
Map, Consumer),
start()public Controller(X operation, Duration synchronizationInterval, Consumer<? super EventQueue<? extends T>> siphon)
Controller but does not start it.X - a Listable and VersionWatchable that
will be used by the embedded Reflector; must not be
nulloperation - a Listable and a VersionWatchable that produces Kubernetes events; must not be
nullsynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; may be null in
which case no synchronization will occursiphon - the Consumer that will process each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or siphon is nullController(Listable, ScheduledExecutorService, Duration,
Map, Consumer),
start()public Controller(X operation, Duration synchronizationInterval, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> siphon)
Controller but does not start it.X - a Listable and VersionWatchable that
will be used by the embedded Reflector; must not be
nulloperation - a Listable and a VersionWatchable that produces Kubernetes events; must not be
nullsynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; may be null in
which case no synchronization will occurknownObjects - a Map containing the last known state
of Kubernetes resources the embedded EventQueueCollection
is caching events for; may be null if this Controller is not interested in tracking deletions of objects;
if non-null will be synchronized on by this
class during retrieval and traversal operationssiphon - the Consumer that will process each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or siphon is nullController(Listable, ScheduledExecutorService, Duration,
Map, Consumer),
start()public Controller(X operation, ScheduledExecutorService synchronizationExecutorService, Duration synchronizationInterval, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> siphon)
Controller but does not start it.X - a Listable and VersionWatchable that
will be used by the embedded Reflector; must not be
nulloperation - a Listable and a VersionWatchable that produces Kubernetes events; must not be
nullsynchronizationExecutorService - the ScheduledExecutorService that will be passed to the Reflector constructor; may be null in which case a
default ScheduledExecutorService may be used insteadsynchronizationInterval - a Duration representing
the time in between one synchronization operation and another; may be null in
which case no synchronization will occurknownObjects - a Map containing the last known state
of Kubernetes resources the embedded EventQueueCollection
is caching events for; may be null if this Controller is not interested in tracking deletions of objects;
if non-null will be synchronized on by this
class during retrieval and traversal operationssiphon - the Consumer that will process each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or siphon is nullstart()protected Logger createLogger()
Logger for use by this Controller.
This method never returns null.
Overrides of this method must not return null.
null Logger@NonBlocking public final void start()
public final void close() throws IOException
Reflector and then closes the embedded
EventQueueCollection, handling exceptions
appropriately.close in interface Closeableclose in interface AutoCloseableIOException - if the Reflector could not
close properlyReflector.close(),
EventQueueCollection.close()protected boolean shouldSynchronize()
true if the embedded Reflector should
synchronize; false otherwiseprotected void onClose()
Reflector.close(),
Reflector.onClose()protected Object getKey(T resource)
HasMetadata.
This method never returns null.
Overrides of this method must not return null.
The default implementation of this method returns the return
value of invoking the HasMetadatas.getKey(HasMetadata)
method.
resource - the Kubernetes resource for which a key is
desired; must not be nullnull key for the supplied HasMetadataNullPointerException - if resource is nullprotected Event<T> createEvent(Object source, AbstractEvent.Type eventType, T resource)
Event when invoked.
This method never returns null.
Overrides of this method must not return null.
Overrides of this method must return a new Event or
subclass with each invocation.
source - the source of the new Event; must not be
nulleventType - the Event.Type for the new Event; must not be nullresource - the HasMetadata that the new Event concerns; must not be nullnull EventNullPointerException - if any of the parameters is
nullprotected EventQueue<T> createEventQueue(Object key)
EventQueue when invoked.
This method never returns null.
Overrides of this method must not return null.
Overrides of this method must return a new EventQueue
or subclass with each invocation.
key - the key to create the new EventQueue with;
must not be nullnull EventQueueNullPointerException - if key is nullCopyright © 2017–2018, microBean. All rights reserved.