Class PipelinedMongoServerSelector

  • All Implemented Interfaces:
    com.mongodb.event.ClusterListener, com.mongodb.selector.ServerSelector, EventListener

    public class PipelinedMongoServerSelector
    extends Object
    implements com.mongodb.selector.ServerSelector, com.mongodb.event.ClusterListener
    Selects a Mongo server that is available for a new connection. This policy is used by PipelinedMongoDownloadTask, the goal being to spread the two connections between the secondaries and avoid downloading from the primary. The policy tries to ensure the following:

    - Establish new connections only to secondaries. - Do not establish more than one connection to a secondary. - If there is a connection to a secondary and that secondary is promoted to primary, the thread should disconnect from the primary and reconnect to a secondary.

    This class uses the thread id of the caller to distribute the connections, that is, it assumes that there are two threads downloading from Mongo and each thread should be sent to a different secondary. If a thread calls several times the selection logic, it will receive always the same server. The thread id is used to identify the calling thread.

    • Constructor Detail

      • PipelinedMongoServerSelector

        public PipelinedMongoServerSelector​(String threadNamePrefix)
        Parameters:
        threadNamePrefix - Threads that start with this prefix will be assigned only to secondary server. Other threads will be assigned all servers available.
    • Method Detail

      • select

        public List<com.mongodb.connection.ServerDescription> select​(com.mongodb.connection.ClusterDescription clusterDescription)
        Specified by:
        select in interface com.mongodb.selector.ServerSelector
      • clusterOpening

        public void clusterOpening​(com.mongodb.event.ClusterOpeningEvent event)
        Specified by:
        clusterOpening in interface com.mongodb.event.ClusterListener
      • clusterClosed

        public void clusterClosed​(com.mongodb.event.ClusterClosedEvent event)
        Specified by:
        clusterClosed in interface com.mongodb.event.ClusterListener
      • clusterDescriptionChanged

        public void clusterDescriptionChanged​(com.mongodb.event.ClusterDescriptionChangedEvent event)
        Specified by:
        clusterDescriptionChanged in interface com.mongodb.event.ClusterListener
      • isConnectedToPrimary

        public boolean isConnectedToPrimary()
        Returns true if the current thread is connected to the primary.
      • atLeastOneConnectionActive

        public boolean atLeastOneConnectionActive()
        Returns true if there is at least one connection active.
      • threadFinished

        public void threadFinished()
        Called by the downloader thread when it finishes downloading. This method removes the thread from the list of active threads.