Brooklyn

brooklyn.entity.nosql.mongodb
[Java] Class ReplicaSetConfig

java.lang.Object
  brooklyn.entity.nosql.mongodb.ReplicaSetConfig

public class ReplicaSetConfig

Simplifies the creation of configuration objects for Mongo DB replica sets.

A configuration object is structured like this:

 {
	"_id" : "replica-set-name",
 	"version" : 3,
	"members" : [
		{ "_id" : 0, "host" : "Sams.local:27017" },
		{ "_id" : 1, "host" : "Sams.local:27018" },
		{ "_id" : 2, "host" : "Sams.local:27019" }
	]
 }
 
To add or remove servers to a replica set you must redefine this configuration (run replSetReconfig on the primary) with the new members list and the version updated.


Constructor Summary
ReplicaSetConfig(java.lang.String name)

ReplicaSetConfig(java.lang.String name, BasicBSONList existingMembers)

 
Method Summary
BasicBSONObject build()

@return A BasicBSONObject representing the configuration that is suitable for a MongoDB server.

static ReplicaSetConfig builder(java.lang.String name)

Creates a configuration with the given name.

static ReplicaSetConfig fromExistingConfig(BSONObject config)

Creates a configuration from an existing configuration.

ReplicaSetConfig member(MongoDBServer server, java.lang.Integer id)

Adds a new member to the replica set config using MongoDBServer#HOSTNAME#HOSTNAME and MongoDBServer#PORT#PORT for hostname and port.

ReplicaSetConfig member(ServerAddress address, java.lang.Integer id)

Adds a new member to the replica set config using com.mongodb.ServerAddress#getHost() and com.mongodb.ServerAddress#getPort() for hostname and port.

ReplicaSetConfig member(java.lang.String hostname, java.lang.Integer port, java.lang.Integer id)

Adds a new member to the replica set config with the given hostname, port and id.

ReplicaSetConfig remove(MongoDBServer server)

Removes the first entity using MongoDBServer#HOSTNAME#HOSTNAME and MongoDBServer#PORT#PORT.

ReplicaSetConfig remove(java.lang.String hostname, java.lang.Integer port)

Removes the first entity with the given hostname and port from the list of members

ReplicaSetConfig version(java.lang.Integer version)

Sets the version of the configuration.

 
Methods inherited from class java.lang.Object
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()
 

Constructor Detail

ReplicaSetConfig

public ReplicaSetConfig(java.lang.String name)


ReplicaSetConfig

public ReplicaSetConfig(java.lang.String name, BasicBSONList existingMembers)


 
Method Detail

build

public BasicBSONObject build()
Returns:
A BasicBSONObject representing the configuration that is suitable for a MongoDB server.


builder

public static ReplicaSetConfig builder(java.lang.String name)
Creates a configuration with the given name.


fromExistingConfig

public static ReplicaSetConfig fromExistingConfig(BSONObject config)
Creates a configuration from an existing configuration.

Auto-incrememnts the replica set's version number.

See Also:
MongoClientSupport#getReplicaSetConfig()#getReplicaSetConfig()


member

public ReplicaSetConfig member(MongoDBServer server, java.lang.Integer id)
Adds a new member to the replica set config using MongoDBServer#HOSTNAME#HOSTNAME and MongoDBServer#PORT#PORT for hostname and port. Doesn't attempt to check that the id is free.


member

public ReplicaSetConfig member(ServerAddress address, java.lang.Integer id)
Adds a new member to the replica set config using com.mongodb.ServerAddress#getHost() and com.mongodb.ServerAddress#getPort() for hostname and port. Doesn't attempt to check that the id is free.


member

public ReplicaSetConfig member(java.lang.String hostname, java.lang.Integer port, java.lang.Integer id)
Adds a new member to the replica set config with the given hostname, port and id. Doesn't attempt to check that the id is free.


remove

public ReplicaSetConfig remove(MongoDBServer server)
Removes the first entity using MongoDBServer#HOSTNAME#HOSTNAME and MongoDBServer#PORT#PORT.


remove

public ReplicaSetConfig remove(java.lang.String hostname, java.lang.Integer port)
Removes the first entity with the given hostname and port from the list of members


version

public ReplicaSetConfig version(java.lang.Integer version)
Sets the version of the configuration. The version number must increase as the replica set changes.


 

Brooklyn Multi-Cloud Application Management Platform
brooklyncentral.github.com. Apache License. © 2012.