Class UpdatableClusterView
- java.lang.Object
-
- io.hekate.cluster.UpdatableClusterView
-
- All Implemented Interfaces:
ClusterFilterSupport<ClusterView>
,ClusterTopologySupport
,ClusterView
public class UpdatableClusterView extends Object implements ClusterView
Simple updatable version of theClusterView
interface.This class represents an updatable version of the
ClusterView
interface and provides support for manual management of this view's cluster topology viaupdate(ClusterTopology)
method. This class can be used for manual testing of cluster-dependent components.Notice: This class doesn't support neither
ClusterEventListener
s nor clusterfutures
. All methods related to this functionality throwUnsupportedOperationException
s.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
UpdatableClusterView(ClusterTopology topology)
Constructs a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addListener(ClusterEventListener listener)
ThrowsUnsupportedOperationException
.void
addListener(ClusterEventListener listener, ClusterEventType... eventTypes)
ThrowsUnsupportedOperationException
.boolean
awaitFor(Predicate<ClusterTopology> predicate)
ThrowsUnsupportedOperationException
.boolean
awaitFor(Predicate<ClusterTopology> predicate, long timeout, TimeUnit timeUnit)
ThrowsUnsupportedOperationException
.static UpdatableClusterView
empty()
Constructs a new empty cluster view.ClusterView
filterAll(ClusterFilter filter)
Returns a copy of this instance that will use the specified filter along with all the filter criteria that were inherited from this instance.CompletableFuture<ClusterTopology>
futureOf(Predicate<ClusterTopology> predicate)
ThrowsUnsupportedOperationException
.static UpdatableClusterView
of(int version, ClusterNode node)
Constructs a new view.static UpdatableClusterView
of(int version, Set<ClusterNode> nodes)
Constructs a new view.static UpdatableClusterView
of(ClusterTopology topology)
Constructs a new view.void
removeListener(ClusterEventListener listener)
ThrowsUnsupportedOperationException
.ClusterTopology
topology()
Returns the cluster topology.<T> T
topologyContext(Function<ClusterTopology,T> supplier)
Constructs a new context object or returns a cached one, based on the current cluster topology.String
toString()
void
update(ClusterTopology topology)
Updates the cluster topology of this view if the specified topology has higherversion
than the one that is already assigned to this view.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface io.hekate.cluster.ClusterFilterSupport
filter, forNode, forNode, forOldest, forProperty, forProperty, forRemotes, forRole, forService, forYoungest
-
Methods inherited from interface io.hekate.cluster.ClusterView
awaitForNodes, awaitForNodes, forEach
-
-
-
-
Constructor Detail
-
UpdatableClusterView
protected UpdatableClusterView(ClusterTopology topology)
Constructs a new instance.- Parameters:
topology
- Topology.
-
-
Method Detail
-
of
public static UpdatableClusterView of(ClusterTopology topology)
Constructs a new view.- Parameters:
topology
- Topology.- Returns:
- New cluster view.
-
of
public static UpdatableClusterView of(int version, ClusterNode node)
Constructs a new view.- Parameters:
version
- Topology version (seeClusterTopology.version()
).node
- Cluster node.- Returns:
- New cluster view.
-
of
public static UpdatableClusterView of(int version, Set<ClusterNode> nodes)
Constructs a new view.- Parameters:
version
- Topology version (seeClusterTopology.version()
).nodes
- Cluster nodes.- Returns:
- New cluster view.
-
empty
public static UpdatableClusterView empty()
Constructs a new empty cluster view.- Returns:
- New cluster view.
- See Also:
ClusterTopology.empty()
-
update
public void update(ClusterTopology topology)
Updates the cluster topology of this view if the specified topology has higherversion
than the one that is already assigned to this view.- Parameters:
topology
- New topology.
-
filterAll
public ClusterView filterAll(ClusterFilter filter)
Description copied from interface:ClusterFilterSupport
Returns a copy of this instance that will use the specified filter along with all the filter criteria that were inherited from this instance.Notice: for performance reasons it is highly recommended to cache and reuse the filtered instance instead of re-building it over and over again.
// Bad!!! (filtering is performed on every iteration). for (int i = 0; i < 1000; i++) { cluster.forRemotes().forRole("some_role").doSomething(); } // Good (filtering is performed only once). filtered = cluster.forRemotes().forRole("some_role"); for (int i = 0; i < 1000; i++) { filtered.doSomething(); }
- Specified by:
filterAll
in interfaceClusterFilterSupport<ClusterView>
- Parameters:
filter
- Filter.- Returns:
- Filtered instance.
-
topology
public ClusterTopology topology()
Description copied from interface:ClusterTopologySupport
Returns the cluster topology.- Specified by:
topology
in interfaceClusterTopologySupport
- Returns:
- Cluster topology.
-
addListener
public void addListener(ClusterEventListener listener)
ThrowsUnsupportedOperationException
.- Specified by:
addListener
in interfaceClusterView
- Parameters:
listener
- Listener.
-
addListener
public void addListener(ClusterEventListener listener, ClusterEventType... eventTypes)
ThrowsUnsupportedOperationException
.- Specified by:
addListener
in interfaceClusterView
- Parameters:
listener
- Listener.eventTypes
- Types of cluster events that this listener should be notified on.
-
removeListener
public void removeListener(ClusterEventListener listener)
ThrowsUnsupportedOperationException
.- Specified by:
removeListener
in interfaceClusterView
- Parameters:
listener
- Listener.
-
topologyContext
public <T> T topologyContext(Function<ClusterTopology,T> supplier)
Description copied from interface:ClusterView
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.- Specified by:
topologyContext
in interfaceClusterView
- Type Parameters:
T
- Context type.- Parameters:
supplier
- Context supplier (must be idempotent and free of side effects).- Returns:
- Context object.
-
futureOf
public CompletableFuture<ClusterTopology> futureOf(Predicate<ClusterTopology> predicate)
ThrowsUnsupportedOperationException
.- Specified by:
futureOf
in interfaceClusterView
- Parameters:
predicate
- Topology predicate.- Returns:
- Topology future.
-
awaitFor
public boolean awaitFor(Predicate<ClusterTopology> predicate)
ThrowsUnsupportedOperationException
.- Specified by:
awaitFor
in interfaceClusterView
- 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
public boolean awaitFor(Predicate<ClusterTopology> predicate, long timeout, TimeUnit timeUnit)
ThrowsUnsupportedOperationException
.- Specified by:
awaitFor
in interfaceClusterView
- 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).
-
-