org.axonframework.eventstore.mongo
Class MongoFactory

java.lang.Object
  extended by org.axonframework.eventstore.mongo.MongoFactory

public class MongoFactory
extends Object

Factory bean for a Mongo instance class. This factory is required since we want to support the most basic setup as well as a more advanced setup. The most basic setup makes use of only one instance of Mongo. This scenario is not really suitable for a production environment, but it does work for a simple test environment.

The factory supports two environments:

For Replica Set usage we expect at least 1 server to be configured. If not, an 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

Since:
0.7
Author:
Jettro Coenradie

Constructor Summary
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.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MongoFactory

public MongoFactory()
Default constructor that configures the factory to create test context Mongo instances.


MongoFactory

public MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses)
Constructor creating defaults for WriteConcern.REPLICA_SAFE and default MongoOptions

Parameters:
mongoAddresses - List containing the address of the servers to use

MongoFactory

public MongoFactory(List<com.mongodb.ServerAddress> mongoAddresses,
                    com.mongodb.MongoOptions mongoOptions,
                    com.mongodb.WriteConcern writeConcern)
Constructor that accepts addresses, options and the default write concern. Used to create a production context

Parameters:
mongoAddresses - List of server addresses to configure the Mongo instance with.
mongoOptions - MongoOptions instance to configure the Mongo instance with
writeConcern - WriteConcern to configure for the connection to the Mongo instance
Method Detail

setMongoAddresses

public void setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
Provide a list of ServerAddress objects to use for locating the Mongo replica set.

Parameters:
mongoAddresses - List of ServerAddress instances

setMongoOptions

public void setMongoOptions(com.mongodb.MongoOptions mongoOptions)
Provide an instance of MongoOptions to be used for the connections.

Parameters:
mongoOptions - MongoOptions to overrule the default

setSingleInstanceContext

public void setSingleInstanceContext(boolean testContext)
Sets the singleInstanceContext, provide true if you want the test context and false if you want the production context.

Parameters:
testContext - Boolean indicating the context, true for test and false for production.

setWriteConcern

public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
Provided a write concern to be used by the mongo instance.

Parameters:
writeConcern - WriteConcern to use for the connections

createMongoInstance

public com.mongodb.Mongo createMongoInstance()
Creates a mongo instance based on the provided configuration. Read javadoc of the class to learn about the configuration options. A new Mongo instance is created each time this method is called.

Returns:
a new Mongo instance each time this method is called.


Copyright © 2011. All Rights Reserved.