Interface ClusterView
-
- All Superinterfaces:
ClusterFilterSupport<ClusterView>
,ClusterTopologySupport
- All Known Subinterfaces:
ClusterService
- All Known Implementing Classes:
UpdatableClusterView
public interface ClusterView extends ClusterFilterSupport<ClusterView>, ClusterTopologySupport
Filtered view ofClusterService
.Filtering can be done by calling
ClusterFilterSupport.filter(ClusterNodeFilter)
method on theClusterView
interface. The resulting view will contain only those nodes that match the specifiedClusterNodeFilter
. Filtering is also applied to allClusterEvent
s that are received byClusterEventListener
s registered to this view.Cluster views can be stacked. If you call
ClusterFilterSupport.filter(ClusterNodeFilter)
method on a view that is already filtered then the resulting view will contain only those nodes that match both filters (i.e. existing filter of this view and the new filter).
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description void
addListener(ClusterEventListener listener)
Registers the cluster event listener.void
addListener(ClusterEventListener listener, ClusterEventType... eventTypes)
Registers the cluster event listener that will be notified only on events of the specified event types.boolean
awaitFor(Predicate<ClusterTopology> predicate)
Awaits for this cluster view to match the specified predicate.boolean
awaitFor(Predicate<ClusterTopology> predicate, long timeout, TimeUnit timeUnit)
Awaits for this cluster view to match the specified predicate up to the specified timeout.default boolean
awaitForNodes()
Awaits for this cluster view to contain at least one node.default boolean
awaitForNodes(long timeout, TimeUnit timeUnit)
Awaits for this cluster view to contain at least one node.default void
forEach(Consumer<ClusterNode> consumer)
Performs the given action for each node of this view.CompletableFuture<ClusterTopology>
futureOf(Predicate<ClusterTopology> predicate)
Returns a future object that will be completed once the cluster topology matches the specified predicate.void
removeListener(ClusterEventListener listener)
Unregisters the cluster event listener.<T> T
topologyContext(Function<ClusterTopology,T> supplier)
Constructs a new context object or returns a cached one, based on the current cluster topology.-
Methods inherited from interface io.hekate.cluster.ClusterFilterSupport
filter, filterAll, forNode, forNode, forOldest, forProperty, forProperty, forRemotes, forRole, forService, forYoungest
-
Methods inherited from interface io.hekate.cluster.ClusterTopologySupport
topology
-
-
-
-
Method Detail
-
addListener
void addListener(ClusterEventListener listener)
Registers the cluster event listener.Please see
ClusterEventListener
javadocs for more details about cluster events handling.- Parameters:
listener
- Listener.
-
addListener
void addListener(ClusterEventListener listener, ClusterEventType... eventTypes)
Registers the cluster event listener that will be notified only on events of the specified event types.Please see
ClusterEventListener
javadocs for more details about cluster events handling.- Parameters:
listener
- Listener.eventTypes
- Types of cluster events that this listener should be notified on.
-
removeListener
void removeListener(ClusterEventListener listener)
Unregisters the cluster event listener.- Parameters:
listener
- Listener.
-
topologyContext
<T> T topologyContext(Function<ClusterTopology,T> supplier)
Constructs a new context object or returns a cached one, based on the current cluster topology.This method provides support to cache user context objects that depend on the current cluster topology and should be reconstructed whenever the cluster topology changes. Such objects are cached at the
ClusterView
instance level. When topology changes, a new object is constructed via the providedsupplier
function.Note that only one context object is supported per
ClusterView
instance. Any attempt to use differentsupplier
functions will lead to unpredictable results.- Type Parameters:
T
- Context type.- Parameters:
supplier
- Context supplier (must be idempotent and free of side effects).- Returns:
- Context object.
-
futureOf
CompletableFuture<ClusterTopology> futureOf(Predicate<ClusterTopology> predicate)
Returns a future object that will be completed once the cluster topology matches the specified predicate. If this cluster node leaves the cluster before the specified condition is met then the future object will becancelled
.Important: Future object can be completed on the same thread that performs cluster events processing and hence all of its associated
CompletionStage
s will be notified on the same thread. If completion stage contains some long running computations then please consider moving them to an asynchronous completion stage (f.e.CompletableFuture.whenCompleteAsync(BiConsumer, Executor)
).- Parameters:
predicate
- Topology predicate.- Returns:
- Topology future.
-
awaitFor
boolean awaitFor(Predicate<ClusterTopology> predicate)
Awaits for this cluster view to match the specified predicate.This method blocks unless the specified predicate accepts the cluster topology of this view or one of the following happens:
- Caller thread gets interrupted
- This cluster node is stopped
- Parameters:
predicate
- Predicate that gets checked every time when underlying cluster topology is changed.- Returns:
- if predicate matched with this cluster view;
false
in all other cases (thread interruption, node stop, etc).
-
awaitFor
boolean awaitFor(Predicate<ClusterTopology> predicate, long timeout, TimeUnit timeUnit)
Awaits for this cluster view to match the specified predicate up to the specified timeout.This method blocks unless the specified predicate accepts the cluster topology of this view or one of the following happens:
- Caller thread gets interrupted
- This cluster node is stopped
- Waiting times out
- Parameters:
predicate
- Predicate that gets checked every time when underlying cluster topology is changed.timeout
- Timeout.timeUnit
- Time unit.- Returns:
- if predicate matched with this cluster view;
false
in all other cases (thread interruption, node stop, etc).
-
awaitForNodes
default boolean awaitForNodes()
Awaits for this cluster view to contain at least one node.This method blocks unless the the cluster topology to have at least one node or one of the following happens:
- Caller thread gets interrupted
- This cluster node is stopped
- Waiting times out
- Returns:
- if this cluster view has at least one node;
false
in all other cases (thread interruption, node stop, etc).
-
awaitForNodes
default boolean awaitForNodes(long timeout, TimeUnit timeUnit)
Awaits for this cluster view to contain at least one node.This method blocks unless the the cluster topology to have at least one node or one of the following happens:
- Caller thread gets interrupted
- This cluster node is stopped
- Waiting times out
- Parameters:
timeout
- Timeout.timeUnit
- Time unit.- Returns:
- if predicate matched with this cluster view;
false
in all other cases (thread interruption, node stop, etc).
-
forEach
default void forEach(Consumer<ClusterNode> consumer)
Performs the given action for each node of this view.- Parameters:
consumer
- The action to be performed for each node.
-
-