Class ConnectionContext

    • Field Detail

      • PAUSE_AFTER_ERROR

        private static final Duration PAUSE_AFTER_ERROR
        A pause between failed MongoDB operations to prevent CPU throttling and DoS of target MongoDB database.
      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • primaryBackoffStrategy

        protected final DelayStrategy primaryBackoffStrategy
      • useHostsAsSeeds

        protected final boolean useHostsAsSeeds
    • Constructor Detail

      • ConnectionContext

        public ConnectionContext​(Configuration config)
        Parameters:
        config - the configuration
    • Method Detail

      • shutdown

        public void shutdown()
      • logger

        protected org.slf4j.Logger logger()
      • performSnapshotEvenIfNotNeeded

        public boolean performSnapshotEvenIfNotNeeded()
      • clientForReplicaSet

        public com.mongodb.client.MongoClient clientForReplicaSet​(ReplicaSet replicaSet)
      • clientFor

        public com.mongodb.client.MongoClient clientFor​(String seedAddresses)
      • clientFor

        public com.mongodb.client.MongoClient clientFor​(List<com.mongodb.ServerAddress> addresses)
      • hosts

        public String hosts()
      • pollInterval

        public Duration pollInterval()
      • maxConnectionAttemptsForPrimary

        public int maxConnectionAttemptsForPrimary()
      • primaryFor

        public ConnectionContext.MongoPrimary primaryFor​(ReplicaSet replicaSet,
                                                         Filters filters,
                                                         BiConsumer<String,​Throwable> errorHandler)
        Obtain a client that will repeated try to obtain a client to the primary node of the replica set, waiting (and using this context's back-off strategy) if required until the primary becomes available.
        Parameters:
        replicaSet - the replica set information; may not be null
        filters - the filter configuration
        errorHandler - the function to be called whenever the primary is unable to execute an operation to completion; may be null
        Returns:
        the client, or null if no primary could be found for the replica set
      • primaryClientFor

        protected Supplier<com.mongodb.client.MongoClient> primaryClientFor​(ReplicaSet replicaSet)
        Obtain a client that will repeated try to obtain a client to the primary node of the replica set, waiting (and using this context's back-off strategy) if required until the primary becomes available.
        Parameters:
        replicaSet - the replica set information; may not be null
        Returns:
        the client, or null if no primary could be found for the replica set
      • primaryClientFor

        protected Supplier<com.mongodb.client.MongoClient> primaryClientFor​(ReplicaSet replicaSet,
                                                                            ConnectionContext.PrimaryConnectFailed handler)
        Obtain a client that will repeated try to obtain a client to the primary node of the replica set, waiting (and using this context's back-off strategy) if required until the primary becomes available.
        Parameters:
        replicaSet - the replica set information; may not be null
        handler - the function that will be called when the primary could not be obtained; may not be null
        Returns:
        the client, or null if no primary could be found for the replica set
      • clientForPrimary

        protected com.mongodb.client.MongoClient clientForPrimary​(ReplicaSet replicaSet)
        Obtain a client that talks only to the primary node of the replica set.
        Parameters:
        replicaSet - the replica set information; may not be null
        Returns:
        the client, or null if no primary could be found for the replica set