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.
This class loosely models a combination of a Controller type and a SharedIndexInformer type as found in controller.go and shared_informer.go respectively.
Reflector, 
EventQueueCollection, 
ResourceTrackingEventQueueConsumer, 
start(), 
close()| Modifier and Type | Field and Description | 
|---|---|
| protected Logger | loggerA  Loggerused by thisController. | 
| Constructor and Description | 
|---|
| Controller(X operation,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Controller(X operation,
          Duration synchronizationInterval,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Controller(X operation,
          Duration synchronizationInterval,
          Map<Object,T> knownObjects,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Controller(X operation,
          Map<Object,T> knownObjects,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Controller(X operation,
          ScheduledExecutorService synchronizationExecutorService,
          Duration synchronizationInterval,
          Function<? super Throwable,Boolean> errorHandler,
          Map<Object,T> knownObjects,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Controller(X operation,
          ScheduledExecutorService synchronizationExecutorService,
          Duration synchronizationInterval,
          Map<Object,T> knownObjects,
          Consumer<? super EventQueue<? extends T>> eventQueueConsumer)Creates a new  Controllerbut does not start it. | 
| Modifier and Type | Method and Description | 
|---|---|
| void | awaitEventCacheSynchronization() | 
| @Blocking boolean | awaitEventCacheSynchronization(long timeout,
                              TimeUnit timeUnit)Blocks for the desired amount of time until the  EventQueueCollectionaffiliated with thisControllerhas
 synchronized or the amount of time has elapsed. | 
| void | close()Closes the embedded
  Reflectorand then closes the embeddedEventQueueCollection, handling exceptions
 appropriately. | 
| protected Event<T> | createEvent(Object source,
           AbstractEvent.Type eventType,
           T resource)Creates a new  Eventwhen invoked. | 
| protected EventQueue<T> | createEventQueue(Object key)Creates a new  EventQueuewhen invoked. | 
| protected Logger | createLogger()Returns a  Loggerfor use by thisController. | 
| 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  Reflectorshould synchronize. | 
| void | start() | 
protected final Logger logger
createLogger()public Controller(X operation, Consumer<? super EventQueue<? extends T>> eventQueueConsumer)
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
 nulleventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer is nullController(Listable, ScheduledExecutorService, Duration,
 Map, Consumer), 
start()public Controller(X operation, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> eventQueueConsumer)
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 operationseventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer is nullController(Listable, ScheduledExecutorService, Duration,
 Map, Consumer), 
start()public Controller(X operation, Duration synchronizationInterval, Consumer<? super EventQueue<? extends T>> eventQueueConsumer)
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 occureventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer is nullController(Listable, ScheduledExecutorService, Duration,
 Map, Consumer), 
start()public Controller(X operation, Duration synchronizationInterval, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> eventQueueConsumer)
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 operationseventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer 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>> eventQueueConsumer)
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 operationseventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer is nullstart()public Controller(X operation, ScheduledExecutorService synchronizationExecutorService, Duration synchronizationInterval, Function<? super Throwable,Boolean> errorHandler, Map<Object,T> knownObjects, Consumer<? super EventQueue<? extends T>> eventQueueConsumer)
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 occurerrorHandler - a Function that accepts a Throwable and returns a Boolean indicating whether the
 error was handled or not; used to handle truly unanticipated
 errors from within a ScheduledExecutorService used
 during synchronization and
 event consumption activities; may 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 operationseventQueueConsumer - the Consumer that will process
 each EventQueue as it becomes ready; must not be nullNullPointerException - if operation or eventQueueConsumer 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@Blocking public final void awaitEventCacheSynchronization() throws InterruptedException
InterruptedException - if the current Thread was
 interrupted@Blocking public final @Blocking boolean awaitEventCacheSynchronization(long timeout, TimeUnit timeUnit) throws InterruptedException
EventQueueCollection affiliated with this Controller
 has
 synchronized or the amount of time has elapsed.timeout - the amount of time to waittimeUnit - the TimeUnit designating the amount of
 time to wait; must not be nullfalse if the waiting time elapsed before the
 event cache synchronized; true otherwiseInterruptedException - if the current Thread was
 interruptedNullPointerException - if timeUnit is nullEventQueueCollection.SynchronizationAwaitingPropertyChangeListener@NonBlocking public final void start() throws IOException
EventQueueCollection consumption machinery
 and then starts the embedded
 Reflector.IOException - if Reflector.start() throws an
 IOExceptionKubernetesClientException - if the embedded Reflector could not be startedEventQueueCollection.start(Consumer), 
Reflector.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–2021, microBean™. All rights reserved.