org.axonframework.eventstore.mongo
Class MongoFactory

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

public class MongoFactory
extends Object

Convenience class for creating Mongo instances. It helps configuring a Mongo instance with a WriteConcern safe to use in combination with the given server addresses.

Depending on the number of addresses provided, the factory defaults to either WriteConcern.REPLICAS_SAFE when more than one address is provided, or WriteConcern.FSYNC_SAFE 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...

Since:
2.0 (in incubator since 0.7)
Author:
Jettro Coenradie

Constructor Summary
MongoFactory()
           
 
Method Summary
 com.mongodb.Mongo createMongo()
          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 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()
Method Detail

createMongo

public com.mongodb.Mongo createMongo()
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.

setMongoAddresses

public void setMongoAddresses(List<com.mongodb.ServerAddress> mongoAddresses)
Provide a list of ServerAddress objects to use for locating the Mongo replica set. An empty list will result in a single Mongo instance being used on the default host (127.0.0.1) and port ()

Defaults to an empty list, which locates a single Mongo instance on the default host (127.0.0.1) and port ()

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. Defaults to a MongoOptions with all its default settings.

Parameters:
mongoOptions - MongoOptions to overrule the default

setWriteConcern

public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
Provided a write concern to be used by the mongo instance. The provided concern should be compatible with the number of addresses provided with setMongoAddresses(java.util.List). For example, providing WriteConcern.REPLICAS_SAFE in combination with a single address will cause each write operation to hang.

While safe (e.g. WriteConcern.REPLICAS_SAFE) 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.REPLICAS_SAFE if you provided more than one address with setMongoAddresses(java.util.List), or WriteConcern.FSYNC_SAFE if there is only one address (or none at all).

Parameters:
writeConcern - WriteConcern to use for the connections


Copyright © 2010-2016. All Rights Reserved.