public class MongoFactory extends Object
ServerAddress instances becomes mandatory.IllegalStateException is
thrown. Be warned, it is better to provide multiple servers in case of a Replica Set.
To configure a Mongo that fits your purpose, you can use two other configuration options. You can provide a
WriteConcern and a MongoOptions object.
The write concern is important in relation to the environment. In a single instance context, the SAFE WriteConcern is
by default used. For a replica set environment, by default the REPLICA_SAFE is used.
Configuring the Mongo instance thread pool can be done by providing a MongoOptions. To make this easier,
a factory is provided. The MongoOptionsFactory facilitates creating such an object. One good reason to
provide a MongoOptions object is to increase the number of connections to the actual mongo databasel| Constructor and Description |
|---|
MongoFactory()
Default constructor that configures the factory to create test context Mongo instances.
|
MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses)
Constructor creating defaults for WriteConcern.REPLICA_SAFE and default MongoOptions
|
MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses,
com.mongodb.MongoOptions mongoOptions,
com.mongodb.WriteConcern writeConcern)
Constructor that accepts addresses, options and the default write concern.
|
| Modifier and Type | Method and Description |
|---|---|
com.mongodb.Mongo |
createMongoInstance()
Creates a mongo instance based on the provided configuration.
|
void |
setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
Provide a list of ServerAddress objects to use for locating the Mongo replica set.
|
void |
setMongoOptions(com.mongodb.MongoOptions mongoOptions)
Provide an instance of MongoOptions to be used for the connections.
|
void |
setSingleInstanceContext(boolean testContext)
Sets the singleInstanceContext, provide true if you want the test context and false if you want the production
context.
|
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Provided a write concern to be used by the mongo instance.
|
public MongoFactory()
public MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses)
mongoAddresses - List containing the address of the servers to usepublic MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses, com.mongodb.MongoOptions mongoOptions, com.mongodb.WriteConcern writeConcern)
mongoAddresses - List of server addresses to configure the Mongo instance with.mongoOptions - MongoOptions instance to configure the Mongo instance withwriteConcern - WriteConcern to configure for the connection to the Mongo instancepublic void setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
mongoAddresses - List of ServerAddress instancespublic void setMongoOptions(com.mongodb.MongoOptions mongoOptions)
mongoOptions - MongoOptions to overrule the defaultpublic void setSingleInstanceContext(boolean testContext)
testContext - Boolean indicating the context, true for test and false for production.public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
writeConcern - WriteConcern to use for the connectionspublic com.mongodb.Mongo createMongoInstance()
Copyright © 2012. All Rights Reserved.