Class ReplicaSetMonitorThread

  • All Implemented Interfaces:
    Runnable

    public final class ReplicaSetMonitorThread
    extends Object
    implements Runnable
    A thread that can be used to when new replica sets are added or existing replica sets are removed. The logic does not evaluate membership changes of individual replica sets, since that is handled independently by each task.
    Author:
    Randall Hauch
    • Constructor Detail

      • ReplicaSetMonitorThread

        public ReplicaSetMonitorThread​(Supplier<ReplicaSets> monitor,
                                       Duration period,
                                       Clock clock,
                                       Runnable onStartup,
                                       Consumer<ReplicaSets> onChange)
        Parameters:
        monitor - the component used to periodically obtain the replica set specifications; may not be null
        period - the time period between polling checks; must be non-negative
        clock - the clock to use; may be null if the system clock should be used
        onStartup - the function to call when the thread is started; may be null if not needed
        onChange - the function to call when the set of replica set specifications has changed; may be null if not needed
    • Method Detail

      • run

        public void run()
        Specified by:
        run in interface Runnable
      • getReplicaSets

        public ReplicaSets getReplicaSets​(long timeout,
                                          TimeUnit unit)
        Get the information about each of the replica sets.
        Parameters:
        timeout - the time to block until the replica sets are first obtained from MongoDB; may not be negative
        unit - the time unit for the timeout; may not be null
        Returns:
        the replica sets, or null if the timeout occurred before the replica set information was obtained