public class MongoSettingsFactory extends Object
Factory class used to create a MongoClientSettings instance. The instance makes use of the defaults as
provided by the MongoOptions class. The moment you set a valid value, that value is used to create the options
object.
Note: WriteConcern enums were changed in MongoDb driver 4.x. Depending on the number of addresses provided, the
factory defaults to either WriteConcern.W2 when more than one address is provided, or WriteConcern.JOURNALED when only one server is available. The idea of these defaults is that data must be able to
survive a (not too heavy) crash without loss of data. We wouldn't want to publish untraceable events, would we...
| Constructor and Description |
|---|
MongoSettingsFactory()
Default constructor for the factory that initializes the defaults.
|
| Modifier and Type | Method and Description |
|---|---|
com.mongodb.MongoClientSettings |
createMongoClientSettings()
Uses the configured parameters to create a MongoOptions instance.
|
int |
getConnectionsPerHost()
Getter for connectionsPerHost.
|
long |
getMaxWaitTime()
get the maximum time a blocked thread that waits for a connection should wait.
|
int |
getSocketConnectTimeout()
Sets the connection timeout in milliseconds for doing something in mongo.
|
int |
getSocketReadTimeOut()
Getter for the socket read timeout.
|
void |
setConnectionsPerHost(int connectionsPerHost)
Setter for the connections per host that are allowed.
|
void |
setMaxWaitTime(long maxWaitTime)
Set the max wait time for a blocked thread in milli seconds.
|
void |
setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
Provide a list of ServerAddress objects to use for locating the Mongo replica set.
|
void |
setSocketConnectTimeout(int socketConnectTimeout)
Setter for socket connection timeout.
|
void |
setSocketReadTimeOut(int socketReadTimeOut)
Setter for the socket read timeout.
|
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Provided a write concern to be used by the mongo instance.
|
public MongoSettingsFactory()
public com.mongodb.MongoClientSettings createMongoClientSettings()
public int getConnectionsPerHost()
public void setConnectionsPerHost(int connectionsPerHost)
connectionsPerHost - number representing the number of connections per hostpublic int getSocketConnectTimeout()
public void setSocketConnectTimeout(int socketConnectTimeout)
socketConnectTimeout - number representing the connection timeout in millispublic long getMaxWaitTime()
public void setMaxWaitTime(long maxWaitTime)
maxWaitTime - number representing the number of milli seconds to wait for a threadpublic int getSocketReadTimeOut()
public void setSocketReadTimeOut(int socketReadTimeOut)
socketReadTimeOut - number representing the amount of milli seconds to wait for a socket connectionpublic void setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
127.0.0.1) and port (com.mongodb.ServerAddress#defaultPort)
Defaults to an empty list, which locates a single Mongo instance on the default host (127.0.0.1) and
port
(com.mongodb.ServerAddress#defaultPort)
mongoAddresses - List of ServerAddress instancespublic void setWriteConcern(com.mongodb.WriteConcern writeConcern)
setMongoAddresses(java.util.List). For example, providing WriteConcern.W2 in combination with a single address will cause each write operation to hang.
While safe (e.g. WriteConcern.W2) WriteConcerns allow you to detect concurrency issues immediately, you
might want to use a more relaxed write concern if you have other mechanisms in place to ensure consistency.
Defaults to WriteConcern.W2 if you provided more than one address with setMongoAddresses(java.util.List), or WriteConcern.JOURNALED if there is only one address (or none at
all).
writeConcern - WriteConcern to use for the connectionsCopyright © 2010–2022. All rights reserved.