T
- a type of Kubernetes resource@Immutable @ThreadSafe public final class EventDistributor<T extends HasMetadata> extends ResourceTrackingEventQueueConsumer<T> implements AutoCloseable
ResourceTrackingEventQueueConsumer
that consumes
EventQueue instances by feeding each AbstractEvent
in the EventQueue
being consumed to Consumer
s of AbstractEvent
s that have been registered.
EventDistributor
instances must be closed and discarded after use.
logger
Constructor and Description |
---|
EventDistributor(Map<Object,T> knownObjects)
Creates a new
EventDistributor . |
EventDistributor(Map<Object,T> knownObjects,
Duration synchronizationInterval)
Creates a new
EventDistributor . |
Modifier and Type | Method and Description |
---|---|
protected void |
accept(AbstractEvent<? extends T> event)
Consumes the supplied
AbstractEvent by forwarding it to
the Consumer.accept(Object) method of each Consumer registered with
this EventDistributor . |
void |
addConsumer(Consumer<? super AbstractEvent<? extends T>> consumer)
Adds the supplied
Consumer to this EventDistributor as a listener that will be notified of each
AbstractEvent this EventDistributor receives. |
void |
addConsumer(Consumer<? super AbstractEvent<? extends T>> consumer,
Function<? super Throwable,Boolean> errorHandler)
Adds the supplied
Consumer to this EventDistributor as a listener that will be notified of each
AbstractEvent this EventDistributor receives. |
void |
close()
Releases resources held by this
EventDistributor during
its execution. |
void |
removeConsumer(Consumer<? super AbstractEvent<? extends T>> consumer)
|
boolean |
shouldSynchronize()
Returns
true if this EventDistributor should
synchronize with its upstream source. |
accept, createEvent, createLogger, createSynchronizationEvent
public EventDistributor(Map<Object,T> knownObjects)
EventDistributor
.knownObjects
- a mutable Map
of Kubernetes resources
that contains or will contain Kubernetes resources known to this
EventDistributor
and whatever mechanism (such as a Controller
) is feeding it; may be null
EventDistributor(Map, Duration)
public EventDistributor(Map<Object,T> knownObjects, Duration synchronizationInterval)
EventDistributor
.knownObjects
- a mutable Map
of Kubernetes resources
that contains or will contain Kubernetes resources known to this
EventDistributor
and whatever mechanism (such as a Controller
) is feeding it; may be null
synchronizationInterval
- a Duration
representing
the interval after which an attempt to synchronize might happen;
may be null
in which case no synchronization will occurResourceTrackingEventQueueConsumer.ResourceTrackingEventQueueConsumer(Map)
public final void addConsumer(Consumer<? super AbstractEvent<? extends T>> consumer)
Consumer
to this EventDistributor
as a listener that will be notified of each
AbstractEvent
this EventDistributor
receives.
The supplied Consumer
's Consumer.accept(Object)
method may be called later on a separate
thread of execution.
consumer
- a Consumer
of AbstractEvent
s; may
be null
in which case no action will be takenaddConsumer(Consumer, Function)
,
removeConsumer(Consumer)
public final void addConsumer(Consumer<? super AbstractEvent<? extends T>> consumer, Function<? super Throwable,Boolean> errorHandler)
Consumer
to this EventDistributor
as a listener that will be notified of each
AbstractEvent
this EventDistributor
receives.
The supplied Consumer
's Consumer.accept(Object)
method may be called later on a separate
thread of execution.
consumer
- a Consumer
of AbstractEvent
s; may
be null
in which case no action will be takenerrorHandler
- a Function
to handle any Throwable
s encountered; may be null
in which case a
default error handler will be used insteadremoveConsumer(Consumer)
public final void removeConsumer(Consumer<? super AbstractEvent<? extends T>> consumer)
consumer
- the Consumer
to remove; may be null
in which case no action will be takenaddConsumer(Consumer)
public final void close()
EventDistributor
during
its execution.close
in interface AutoCloseable
public final boolean shouldSynchronize()
true
if this EventDistributor
should
synchronize with its upstream source.
The Kubernetes tools/cache
package spreads
synchronization out among the reflector, controller, event cache
and event processor constructs for no seemingly good reason.
They should probably be consolidated, particularly in an
object-oriented environment such as Java.
true
if synchronization should occur; false
otherwiseEventCache.synchronize()
protected final void accept(AbstractEvent<? extends T> event)
AbstractEvent
by forwarding it to
the Consumer.accept(Object)
method of each Consumer
registered with
this EventDistributor
.accept
in class ResourceTrackingEventQueueConsumer<T extends HasMetadata>
event
- the AbstractEvent
to forward; may be null
in which case no action is takenaddConsumer(Consumer)
,
ResourceTrackingEventQueueConsumer.accept(AbstractEvent)
Copyright © 2017–2021, microBean™. All rights reserved.