T
- a Kubernetes resource typepublic abstract class ResourceTrackingEventQueueConsumer<T extends HasMetadata> extends Object implements Consumer<EventQueue<? extends T>>
Consumer
of EventQueue
s that tracks the
Kubernetes resources they contain before allowing subclasses to
process their individual Event
s.
Typically you would supply an implementation of this class to a
Controller
.
accept(AbstractEvent)
,
Controller
Modifier and Type | Field and Description |
---|---|
protected Logger |
logger
A
Logger for use by this ResourceTrackingEventQueueConsumer implementation. |
Modifier | Constructor and Description |
---|---|
protected |
ResourceTrackingEventQueueConsumer(Map<Object,T> knownObjects)
Creates a new
ResourceTrackingEventQueueConsumer . |
Modifier and Type | Method and Description |
---|---|
protected abstract void |
accept(AbstractEvent<? extends T> event)
Called to process a given
AbstractEvent from the EventQueue supplied to the accept(EventQueue) method,
with that EventQueue 's monitor held. |
void |
accept(EventQueue<? extends T> eventQueue)
Loops through all the
AbstractEvent s in the supplied EventQueue , keeping track
of the HasMetadata it concerns along the way by
synchronizing on and writing to the Map
supplied at
construction time. |
protected Event<T> |
createEvent(AbstractEvent.Type eventType,
T priorResource,
T resource)
Creates and returns a new
Event . |
protected Logger |
createLogger()
Returns a
Logger for use with this ResourceTrackingEventQueueConsumer . |
protected SynchronizationEvent<T> |
createSynchronizationEvent(AbstractEvent.Type eventType,
T priorResource,
T resource)
Creates and returns a new
SynchronizationEvent . |
protected final Logger logger
Logger
for use by this ResourceTrackingEventQueueConsumer
implementation.
This field is never null
.
createLogger()
protected ResourceTrackingEventQueueConsumer(Map<Object,T> knownObjects)
ResourceTrackingEventQueueConsumer
.knownObjects
- a mutable Map
of HasMetadata
objects indexed by their keys (often a pairing of namespace and
name); may be null
if deletion tracking is not needed;
will have its contents changed by this ResourceTrackingEventQueueConsumer
's accept(EventQueue)
method; will be synchronized on by this ResourceTrackingEventQueueConsumer
's accept(EventQueue)
methodaccept(EventQueue)
protected Logger createLogger()
Logger
for use with this ResourceTrackingEventQueueConsumer
.
This method never returns null
.
Overrides of this method must not return null
.
null
Logger
public final void accept(EventQueue<? extends T> eventQueue)
AbstractEvent
s in the supplied EventQueue
, keeping track
of the HasMetadata
it concerns along the way by
synchronizing on and writing to the Map
supplied at
construction time.
Individual AbstractEvent
s are forwarded on to the
accept(AbstractEvent)
method.
This loosely models the HandleDeltas
function in tools/cache/shared_informer.go
. The final distribution step
is left unimplemented on purpose.
accept
in interface Consumer<EventQueue<? extends T extends HasMetadata>>
eventQueue
- the EventQueue
to process; may be
null
in which case no action will be takenaccept(AbstractEvent)
protected Event<T> createEvent(AbstractEvent.Type eventType, T priorResource, T resource)
Event
.
This method never returns null
.
Overrides of this method must not return null
.
eventType
- the AbstractEvent.Type
for the new
Event
; must not be null
; when supplied by the
accept(EventQueue)
method's internals, will always be
either AbstractEvent.Type.ADDITION
or AbstractEvent.Type.MODIFICATION
priorResource
- the prior state of the resource the new
Event
will represent; may be (and often is) null
resource
- the latest state of the resource the new Event
will represent; must not be null
null
Event
with each
invocationNullPointerException
- if eventType
or resource
is null
protected SynchronizationEvent<T> createSynchronizationEvent(AbstractEvent.Type eventType, T priorResource, T resource)
SynchronizationEvent
.
This method never returns null
.
Overrides of this method must not return null
.
eventType
- the AbstractEvent.Type
for the new
SynchronizationEvent
; must not be null
; when
supplied by the accept(EventQueue)
method's internals,
will always be AbstractEvent.Type.MODIFICATION
priorResource
- the prior state of the resource the new
SynchronizationEvent
will represent; may be (and often
is) null
resource
- the latest state of the resource the new SynchronizationEvent
will represent; must not be null
null
SynchronizationEvent
with
each invocationNullPointerException
- if eventType
or resource
is null
protected abstract void accept(AbstractEvent<? extends T> event)
AbstractEvent
from the EventQueue
supplied to the accept(EventQueue)
method,
with that EventQueue
's monitor held.
Implementations of this method should be relatively fast as
this method dictates the speed of EventQueue
processing.
event
- the AbstractEvent
encountered in the EventQueue
; must not be null
NullPointerException
- if event
is null
accept(EventQueue)
Copyright © 2017–2021, microBean™. All rights reserved.