Class UpdatableClusterView

    • Constructor Detail

      • UpdatableClusterView

        protected UpdatableClusterView​(ClusterTopology topology)
        Constructs a new instance.
        Parameters:
        topology - Topology.
    • Method Detail

      • update

        public void update​(ClusterTopology topology)
        Updates the cluster topology of this view if the specified topology has higher version 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 interface ClusterFilterSupport<ClusterView>
        Parameters:
        filter - Filter.
        Returns:
        Filtered instance.
      • 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 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.

        Specified by:
        topologyContext in interface ClusterView
        Type Parameters:
        T - Context type.
        Parameters:
        supplier - Context supplier (must be idempotent and free of side effects).
        Returns:
        Context object.
      • awaitFor

        public boolean awaitFor​(Predicate<ClusterTopology> predicate)
        Specified by:
        awaitFor in interface ClusterView
        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)
        Specified by:
        awaitFor in interface ClusterView
        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).