public class BootstrapConnectionFactory extends Object implements ConnectionFactory
ConnectionFactory
based on the configuration of the server(s)
connected to.Modifier and Type | Field and Description |
---|---|
protected static Log |
LOG
The logger for the
BootstrapConnectionFactory . |
Constructor and Description |
---|
BootstrapConnectionFactory(MongoClientConfiguration config)
Creates a
BootstrapConnectionFactory |
Modifier and Type | Method and Description |
---|---|
protected void |
bootstrap()
Re-bootstraps the environment.
|
protected ConnectionFactory |
bootstrapReplicaSet(ProxiedConnectionFactory factory)
Initializes the factory for connecting to the replica set.
|
protected ConnectionFactory |
bootstrapSharded(ProxiedConnectionFactory factory)
Initializes the factory for connecting to the sharded cluster.
|
void |
close() |
Connection |
connect()
Creates a connection to the address provided.
|
ClusterStats |
getClusterStats()
Returns the meta-data on the current cluster.
|
ClusterType |
getClusterType()
Returns the type of cluster the connection factory connects to.
|
protected MongoClientConfiguration |
getConfig()
The configuration for the client.
|
protected ConnectionFactory |
getDelegate()
Returns the underlying delegate factory.
|
ReconnectStrategy |
getReconnectStrategy()
Returns the reconnection strategy for the type of connections.
|
protected void |
setDelegate(ConnectionFactory delegate)
Sets the underlying delegate factory.
|
protected static final Log LOG
BootstrapConnectionFactory
.public BootstrapConnectionFactory(MongoClientConfiguration config)
BootstrapConnectionFactory
config
- The configuration to use in discovering the server
configuration.public void close()
Overridden to close the delegate ConnectionFactory
.
close
in interface Closeable
close
in interface AutoCloseable
public Connection connect() throws IOException
Delegates the connection to the setup delegate.
connect
in interface ConnectionFactory
IOException
- On a failure connecting to the server.public ClusterStats getClusterStats()
Overridden to return the cluster stats of the proxied
ConnectionFactory
.
getClusterStats
in interface ConnectionFactory
public ClusterType getClusterType()
Overridden to return the cluster type of the delegate
ConnectionFactory
.
getClusterType
in interface ConnectionFactory
public ReconnectStrategy getReconnectStrategy()
Overridden to return the delegates strategy.
getReconnectStrategy
in interface ConnectionFactory
protected void bootstrap()
A bootstrap will issue one commands to the first working MongoDB process.
The reply to the IsMaster
command is used to detect connecting to
a mongos process and by extension a Sharded configuration.
If not using a Sharded configuration then the server status is checked for a repl element. If present a Replication Set configuration is assumed.
If neither a Sharded or Replication Set is being used then a plain socket connection factory is used.
protected ConnectionFactory bootstrapReplicaSet(ProxiedConnectionFactory factory)
factory
- The factory for connecting to the servers directly.protected ConnectionFactory bootstrapSharded(ProxiedConnectionFactory factory)
factory
- The factory for connecting to the servers directly.protected MongoClientConfiguration getConfig()
protected ConnectionFactory getDelegate()
protected void setDelegate(ConnectionFactory delegate)
delegate
- The underlying delegate factory.Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.