public class MongoDbConfiguration extends Object implements Cloneable, Serializable
Modifier and Type | Field and Description |
---|---|
static String |
ADMIN_DB_NAME
The name of the administration database.
|
static String |
DEFAULT_DB_NAME
The default database.
|
static Charset |
UTF8
The ASCII character encoding.
|
Constructor and Description |
---|
MongoDbConfiguration()
Creates a new MongoDbConfiguration.
|
MongoDbConfiguration(InetSocketAddress... servers)
Creates a new MongoDbConfiguration.
|
MongoDbConfiguration(MongoDbConfiguration other)
Creates a new MongoDbConfiguration.
|
MongoDbConfiguration(MongoDbUri mongoDbUri)
Creates a new
MongoDbConfiguration instance using a MongoDB style
URL to initialize its state. |
MongoDbConfiguration(String mongoDbUri)
Creates a new
MongoDbConfiguration instance using a MongoDB style
URL to initialize its state. |
Modifier and Type | Method and Description |
---|---|
void |
addServer(InetSocketAddress server)
Adds a server to initially attempt to connect to.
|
void |
addServer(String server)
Adds a server to initially attempt to connect to.
|
void |
authenticate(String userName,
String password)
Sets up the instance to authenticate with the MongoDB servers.
|
void |
authenticateAsAdmin(String userName,
String password)
Sets up the instance to authenticate with the MongoDB servers.
|
MongoDbConfiguration |
clone()
Creates a copy of this MongoDbConfiguration.
|
int |
getConnectTimeout()
Returns how long to wait (in milliseconds) for a socket connection to
complete.
|
String |
getDefaultDatabase()
Returns the default database for the connection.
|
Durability |
getDefaultDurability()
Returns the default durability for write operations on the server.
|
ReadPreference |
getDefaultReadPreference()
Returns the default read preference for a query.
|
LockType |
getLockType()
Returns the type of hand off lock to use between threads in the core of
the driver.
|
int |
getMaxConnectionCount()
Returns the maximum number of connections to use.
|
int |
getMaxPendingOperationsPerConnection()
Returns the maximum number of pending operations to allow per connection.
|
long |
getMaxSecondaryLag()
Returns the maximum number of milliseconds that a secondary can be behind
the primary before they will be excluded from being used for queries on
secondaries.
|
String |
getPasswordHash()
Gets the password hash for authentication with the database.
|
int |
getReadTimeout()
Returns how long to wait (in milliseconds) for a socket read to complete.
|
int |
getReconnectTimeout()
Returns how long to wait (in milliseconds) for a broken connection to be
reconnected.
|
List<String> |
getServers()
Returns the list of servers to initially attempt to connect to.
|
ThreadFactory |
getThreadFactory()
Returns the thread factory for managing connections.
|
String |
getUserName()
Gets the user name for authenticating with the database.
|
boolean |
isAdminUser()
Returns true if the user should authenticate as an administrative user.
|
boolean |
isAuthenticating()
Returns true if the connection is authenticating.
|
boolean |
isAutoDiscoverServers()
Returns if additional servers are auto discovered or if connections are
limited to the ones manually configured.
|
boolean |
isUsingSoKeepalive()
Returns if the
SO_KEEPALIVE
socket option is set. |
void |
setAutoDiscoverServers(boolean autoDiscoverServers)
Sets if additional servers are auto discovered or if connections are
limited to the ones manually configured.
|
void |
setConnectTimeout(int connectTimeout)
Sets how long to wait (in milliseconds) for a socket connection to
complete.
|
void |
setDefaultDatabase(String defaultDatabase)
Sets the default database for the connection.
|
void |
setDefaultDurability(Durability defaultDurability)
Sets the default durability for write operations on the server to the new
value.
|
void |
setDefaultReadPreference(ReadPreference defaultReadPreference)
Sets the value of the default read preference for a query.
|
void |
setLockType(LockType lockType)
Sets the type of hand off lock to use between threads in the core of the
driver.
|
void |
setMaxConnectionCount(int maxConnectionCount)
Sets the maximum number of connections to use.
|
void |
setMaxPendingOperationsPerConnection(int maxPendingOperationsPerConnection)
Sets the maximum number of pending operations to allow per connection.
|
void |
setMaxSecondaryLag(long maxSecondaryLag)
Sets the maximum number of milliseconds that a secondary can be behind
the primary before they will be excluded from being used for queries on
secondaries.
|
void |
setReadTimeout(int readTimeout) |
void |
setReconnectTimeout(int connectTimeout)
Sets how long to wait (in milliseconds) for a broken connection to
reconnect.
|
void |
setServers(List<InetSocketAddress> servers)
Sets the servers to initially attempt to connect to.
|
void |
setThreadFactory(ThreadFactory factory)
Sets the thread factory for managing connections to the new value.
|
void |
setUsingSoKeepalive(boolean usingSoKeepalive)
Sets if the
SO_KEEPALIVE
socket option is set. |
public static final String ADMIN_DB_NAME
public static final String DEFAULT_DB_NAME
public static final Charset UTF8
public MongoDbConfiguration()
public MongoDbConfiguration(InetSocketAddress... servers)
servers
- The initial set of servers to connect to.public MongoDbConfiguration(MongoDbConfiguration other)
other
- The configuration to copy.public MongoDbConfiguration(MongoDbUri mongoDbUri) throws IllegalArgumentException
MongoDbConfiguration
instance using a MongoDB style
URL to initialize its state. Further configuration is possible once the
MongoDbConfiguration
has been instantiated.mongoDbUri
- The configuration for the connection to MongoDB expressed as a
MongoDB URL.IllegalArgumentException
- If the mongoDbUri is not a properly formated MongoDB
style URL.public MongoDbConfiguration(String mongoDbUri) throws IllegalArgumentException
MongoDbConfiguration
instance using a MongoDB style
URL to initialize its state. Further configuration is possible once the
MongoDbConfiguration
has been instantiated.mongoDbUri
- The configuration for the connection to MongoDB expressed as a
MongoDB URL.IllegalArgumentException
- If the mongoDbUri is not a properly formated MongoDB
style URL.public void addServer(InetSocketAddress server)
server
- The server to add.public void addServer(String server)
server
- The server to add.public void authenticate(String userName, String password) throws MongoDbAuthenticationException
Mongo
instance.userName
- The user name.password
- the password.MongoDbAuthenticationException
- On a failure initializing the authentication information.public void authenticateAsAdmin(String userName, String password) throws MongoDbAuthenticationException
Mongo
instance.userName
- The user name.password
- the password.MongoDbAuthenticationException
- On a failure initializing the authentication information.public MongoDbConfiguration clone()
Note: This is not a traditional clone to ensure a deep copy of all information.
public int getConnectTimeout()
Defaults to 0 or forever.
public String getDefaultDatabase()
This is used as the database to authenticate against if the user is not an administrative user.
Defaults to "local".
public Durability getDefaultDurability()
Defaults to Durability.NONE
.
public ReadPreference getDefaultReadPreference()
Defaults to ReadPreference.PRIMARY
.
public LockType getLockType()
Defaults to LockType.MUTEX
.
public int getMaxConnectionCount()
Defaults to 3.
Note: In the case of connecting to a replica set this setting
limits the number of connections to the primary server. The driver will
create single connections to the secondary servers if queries are issued
with a ReadPreference
other than ReadPreference.PRIMARY
.
public int getMaxPendingOperationsPerConnection()
Defaults to 1024.
Note: In the case of an connection error it is impossible to determine which pending operations completed and which did not. Setting this value to 1 results in synchronous operations that wait for responses.
public long getMaxSecondaryLag()
Defaults to 5 minutes (300,000).
public String getPasswordHash()
public int getReadTimeout()
Defaults to 0 or never.
public int getReconnectTimeout()
Defaults to 0 or forever.
public List<String> getServers()
public ThreadFactory getThreadFactory()
public String getUserName()
public boolean isAdminUser()
public boolean isAuthenticating()
public boolean isAutoDiscoverServers()
Defaults to true, e.g., auto-discover.
public boolean isUsingSoKeepalive()
SO_KEEPALIVE
socket option is set.
Defaults to true, e.g., use SO_KEEPALIVE.
SO_KEEPALIVE
socket option is set.public void setAutoDiscoverServers(boolean autoDiscoverServers)
Defaults to true, e.g., auto-discover.
autoDiscoverServers
- The new value for auto-discovering servers.public void setConnectTimeout(int connectTimeout)
connectTimeout
- The time to wait (in milliseconds) for a socket connection to
complete.public void setDefaultDatabase(String defaultDatabase)
This is used as the database to authenticate against if the user is not an administrative user.
Defaults to "local".
defaultDatabase
- The new default database value.public void setDefaultDurability(Durability defaultDurability)
defaultDurability
- The default durability for write operations on the server.public void setDefaultReadPreference(ReadPreference defaultReadPreference)
Defaults to ReadPreference.PRIMARY
if null
is set.
defaultReadPreference
- The default read preference for a query.public void setLockType(LockType lockType)
Defaults to LockType.MUTEX
.
lockType
- The new value for the type of hand off lock used.public void setMaxConnectionCount(int maxConnectionCount)
Defaults to 3.
Note: In the case of connecting to a replica set this setting
limits the number of connections to the primary server. The driver will
create single connections to the secondary servers if queries are issued
with a ReadPreference
other than ReadPreference.PRIMARY
.
maxConnectionCount
- New maximum number of connections to use.public void setMaxPendingOperationsPerConnection(int maxPendingOperationsPerConnection)
maxPendingOperationsPerConnection
- The new maximum number of pending operations to allow per
connection.public void setMaxSecondaryLag(long maxSecondaryLag)
Defaults to 5 minutes (300,000).
maxSecondaryLag
- The new value for the maximum number of milliseconds that a
secondary can be behind the primary before they will be
excluded from being used for queries on secondaries.public void setReadTimeout(int readTimeout)
readTimeout
- The time to wait (in milliseconds) for a socket read to
complete.public void setReconnectTimeout(int connectTimeout)
connectTimeout
- The time to wait (in milliseconds) for a broken connection to
reconnect.public void setServers(List<InetSocketAddress> servers)
servers
- The servers to connect to.public void setThreadFactory(ThreadFactory factory)
factory
- The thread factory for managing connections.public void setUsingSoKeepalive(boolean usingSoKeepalive)
SO_KEEPALIVE
socket option is set.
Defaults to true, e.g., use SO_KEEPALIVE.
usingSoKeepalive
- The new value for using SO_KEEPALIVE.Copyright © 2011-2012 Allanbank Consulting, Inc.. All Rights Reserved.