List of usage examples for com.mongodb WriteConcern REPLICAS_SAFE
WriteConcern REPLICAS_SAFE
To view the source code for com.mongodb WriteConcern REPLICAS_SAFE.
Click Source Link
Exceptions are raised for network issues, and server errors; waits for at least 2 servers for the write operation.
This field has been superseded by WriteConcern.REPLICA_ACKNOWLEDGED , and may be deprecated in a future release.
From source file:org.lucee.mongodb.support.ObjectSupport.java
License:Open Source License
public WriteConcern toWriteConcern(Object obj, WriteConcern defaultValue) { if (obj instanceof WriteConcern) return (WriteConcern) obj; if (decision.isSimpleValue(obj)) { String str = caster.toString(obj, ""); str = str.trim().toUpperCase();/*from w w w. ja va 2s . c o m*/ if ("ACKNOWLEDGED".equals(str)) return WriteConcern.ACKNOWLEDGED; else if ("ACKNOWLEDGED".equals(str)) return WriteConcern.FSYNC_SAFE; else if ("FSYNC_SAFE".equals(str) || "FSYNCSAFE".equals(str)) return WriteConcern.FSYNCED; else if ("JOURNAL_SAFE".equals(str) || "JOURNALSAFE".equals(str)) return WriteConcern.JOURNAL_SAFE; else if ("JOURNALED".equals(str)) return WriteConcern.JOURNALED; else if ("MAJORITY".equals(str)) return WriteConcern.MAJORITY; else if ("NORMAL".equals(str)) return WriteConcern.NORMAL; else if ("REPLICA_ACKNOWLEDGED".equals(str) || "REPLICAACKNOWLEDGED".equals(str)) return WriteConcern.REPLICA_ACKNOWLEDGED; else if ("REPLICAS_SAFE".equals(str) || "REPLICASSAFE".equals(str)) return WriteConcern.REPLICAS_SAFE; else if ("SAFE".equals(str)) return WriteConcern.SAFE; else if ("UNACKNOWLEDGED".equals(str)) return WriteConcern.UNACKNOWLEDGED; } return defaultValue; }
From source file:org.qi4j.entitystore.mongodb.MongoMapEntityStoreMixin.java
License:Apache License
private void loadConfiguration() throws UnknownHostException { configuration.refresh();/*from w w w. j a v a2 s . c om*/ MongoEntityStoreConfiguration config = configuration.get(); // Combine hostname, port and nodes configuration properties serverAddresses = new ArrayList<ServerAddress>(); if (config.hostname().get() != null && !config.hostname().get().isEmpty()) { serverAddresses.add(new ServerAddress(config.hostname().get(), config.port().get())); } serverAddresses.addAll(config.nodes().get()); // If database name not configured, set it to qi4j:entitystore databaseName = config.database().get(); if (databaseName == null) { databaseName = DEFAULT_DATABASE_NAME; } // If collection name not configured, set it to qi4j:entitystore:entities collectionName = config.collection().get(); if (collectionName == null) { collectionName = DEFAULT_COLLECTION_NAME; } // If write concern not configured, set it to normal switch (config.writeConcern().get()) { case FSYNC_SAFE: writeConcern = WriteConcern.FSYNC_SAFE; break; case JOURNAL_SAFE: writeConcern = WriteConcern.JOURNAL_SAFE; break; case MAJORITY: writeConcern = WriteConcern.MAJORITY; break; case NONE: writeConcern = WriteConcern.NONE; break; case REPLICAS_SAFE: writeConcern = WriteConcern.REPLICAS_SAFE; break; case SAFE: writeConcern = WriteConcern.SAFE; break; case NORMAL: default: writeConcern = WriteConcern.NORMAL; } // Username and password are defaulted to empty strings username = config.username().get(); password = config.password().get().toCharArray(); }
From source file:org.slc.sli.dal.repository.MongoRepository.java
License:Apache License
/** * Sets the write concern of the template. Support options defined in Mongo's WriteConcern * class./*w w w .j ava2 s .co m*/ * * @see com.mongodb.WriteConcern */ @Override public void setWriteConcern(String writeConcern) { try { WriteConcern concern = WriteConcern.valueOf(writeConcern); template.setWriteConcern(concern); } catch (RuntimeException ex) { LOG.warn("Unknown write concern", writeConcern); // When in doubt, play it (Replicas) safe. template.setWriteConcern(WriteConcern.REPLICAS_SAFE); } }
From source file:test.elasticsearch.plugin.river.mongodb.RiverMongoDBTestAsbtract.java
License:Apache License
private void initMongoInstances() throws Exception { logger.debug("*** initMongoInstances ***"); CommandResult cr;/* w w w.j ava 2s . c o m*/ // Create 3 mongod processes mongodConfig1 = new MongodConfig(new GenericVersion(mongoVersion), new Net(mongoPort1, Network.localhostIsIPv6()), new Storage(null, REPLICA_SET_NAME, 20), new Timeout()); MongodStarter starter = MongodStarter.getDefaultInstance(); mongodExe1 = starter.prepare(mongodConfig1); mongod1 = mongodExe1.start(); mongodConfig2 = new MongodConfig(new GenericVersion(mongoVersion), new Net(mongoPort2, Network.localhostIsIPv6()), new Storage(null, REPLICA_SET_NAME, 20), new Timeout()); mongodExe2 = starter.prepare(mongodConfig2); mongod2 = mongodExe2.start(); mongodConfig3 = new MongodConfig(new GenericVersion(mongoVersion), new Net(mongoPort3, Network.localhostIsIPv6()), new Storage(null, REPLICA_SET_NAME, 20), new Timeout()); mongodExe3 = starter.prepare(mongodConfig3); mongod3 = mongodExe3.start(); String server1 = Network.getLocalHost().getHostName() + ":" + mongodConfig1.net().getPort(); String server2 = Network.getLocalHost().getHostName() + ":" + mongodConfig2.net().getPort(); String server3 = Network.getLocalHost().getHostName() + ":" + mongodConfig3.net().getPort(); logger.debug("Server #1: {}", server1); logger.debug("Server #2: {}", server2); logger.debug("Server #3: {}", server3); Thread.sleep(2000); MongoClientOptions mco = MongoClientOptions.builder().autoConnectRetry(true).connectTimeout(15000) .socketTimeout(60000).build(); mongo = new MongoClient( new ServerAddress(Network.getLocalHost().getHostName(), mongodConfig1.net().getPort()), mco); mongoAdminDB = mongo.getDB(ADMIN_DATABASE_NAME); cr = mongoAdminDB.command(new BasicDBObject("isMaster", 1)); logger.debug("isMaster: " + cr); // Initialize replica set cr = mongoAdminDB.command(new BasicDBObject("replSetInitiate", (DBObject) JSON.parse("{'_id': '" + REPLICA_SET_NAME + "', 'members': [{'_id': 0, 'host': '" + server1 + "'}, {'_id': 1, 'host': '" + server2 + "'}, {'_id': 2, 'host': '" + server3 + "', 'arbiterOnly' : true}]} }"))); logger.debug("replSetInitiate: " + cr); Thread.sleep(5000); cr = mongoAdminDB.command(new BasicDBObject("replSetGetStatus", 1)); logger.info("replSetGetStatus: " + cr); // Check replica set status before to proceed while (!isReplicaSetStarted(cr)) { logger.debug("Waiting for 3 seconds..."); Thread.sleep(1000); cr = mongoAdminDB.command(new BasicDBObject("replSetGetStatus", 1)); logger.debug("replSetGetStatus: " + cr); } mongo.close(); mongo = null; // Initialize a new client using all instances. List<ServerAddress> mongoServers = new ArrayList<ServerAddress>(); mongoServers.add(new ServerAddress(Network.getLocalHost().getHostName(), mongodConfig1.net().getPort())); mongoServers.add(new ServerAddress(Network.getLocalHost().getHostName(), mongodConfig2.net().getPort())); mongoServers.add(new ServerAddress(Network.getLocalHost().getHostName(), mongodConfig3.net().getPort())); mongo = new MongoClient(mongoServers, mco); Assert.assertNotNull(mongo); mongo.setReadPreference(ReadPreference.secondaryPreferred()); mongo.setWriteConcern(WriteConcern.REPLICAS_SAFE); }