Interface ClusterView

    • 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 provided supplier function.

        Note that only one context object is supported per ClusterView instance. Any attempt to use different supplier 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 be cancelled.

        Important: Future object can be completed on the same thread that performs cluster events processing and hence all of its associated CompletionStages 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.