Class PipelinedMongoServerSelector
- java.lang.Object
-
- org.apache.jackrabbit.oak.index.indexer.document.flatfile.pipelined.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 Summary
Constructors Constructor Description PipelinedMongoServerSelector(String threadNamePrefix)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanatLeastOneConnectionActive()Returns true if there is at least one connection active.voidclusterClosed(com.mongodb.event.ClusterClosedEvent event)voidclusterDescriptionChanged(com.mongodb.event.ClusterDescriptionChangedEvent event)voidclusterOpening(com.mongodb.event.ClusterOpeningEvent event)booleanisConnectedToPrimary()Returns true if the current thread is connected to the primary.List<com.mongodb.connection.ServerDescription>select(com.mongodb.connection.ClusterDescription clusterDescription)voidthreadFinished()Called by the downloader thread when it finishes downloading.
-
-
-
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:
selectin interfacecom.mongodb.selector.ServerSelector
-
clusterOpening
public void clusterOpening(com.mongodb.event.ClusterOpeningEvent event)
- Specified by:
clusterOpeningin interfacecom.mongodb.event.ClusterListener
-
clusterClosed
public void clusterClosed(com.mongodb.event.ClusterClosedEvent event)
- Specified by:
clusterClosedin interfacecom.mongodb.event.ClusterListener
-
clusterDescriptionChanged
public void clusterDescriptionChanged(com.mongodb.event.ClusterDescriptionChangedEvent event)
- Specified by:
clusterDescriptionChangedin interfacecom.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.
-
-