List of usage examples for com.mongodb WriteConcern REPLICA_ACKNOWLEDGED
WriteConcern REPLICA_ACKNOWLEDGED
To view the source code for com.mongodb WriteConcern REPLICA_ACKNOWLEDGED.
Click Source Link
From source file:com.ricardolorenzo.identity.user.impl.UserIdentityManagerMongoDB.java
License:Open Source License
public UserIdentityManagerMongoDB(final Properties conf) throws UnknownHostException { this.properties = conf; this.databaseUsers = new Boolean(this.properties.getProperty("mongodb.databaseUsers", "true")); WriteConcern writeConcern = WriteConcern.MAJORITY; String writeConcernType = conf.getProperty("mongodb.writeConcern", "majority").toLowerCase(); if ("majority".equals(writeConcernType)) { writeConcern = WriteConcern.UNACKNOWLEDGED; } else if ("unacknowledged".equals(writeConcernType)) { writeConcern = WriteConcern.UNACKNOWLEDGED; } else if ("acknowledged".equals(writeConcernType)) { writeConcern = WriteConcern.ACKNOWLEDGED; } else if ("journaled".equals(writeConcernType)) { writeConcern = WriteConcern.JOURNALED; } else if ("replica_acknowledged".equals(writeConcernType)) { writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; }// w w w. j a v a2 s .co m ReadPreference readPreference = null; String readPreferenceType = conf.getProperty("mongodb.readPreference", "primary").toLowerCase(); if ("primary".equals(readPreferenceType)) { readPreference = ReadPreference.primary(); } else if ("primary_preferred".equals(readPreferenceType)) { readPreference = ReadPreference.primaryPreferred(); } else if ("secondary".equals(readPreferenceType)) { readPreference = ReadPreference.secondary(); } else if ("secondary_preferred".equals(readPreferenceType)) { readPreference = ReadPreference.secondaryPreferred(); } else if ("nearest".equals(readPreferenceType)) { readPreference = ReadPreference.nearest(); } MongoClientOptions.Builder options = MongoClientOptions.builder(); options.writeConcern(writeConcern); options.readPreference(readPreference); try { options.connectionsPerHost(Integer.parseInt(conf.getProperty("mongodb.threads", "100"))); } catch (NumberFormatException e) { options.connectionsPerHost(100); } MongoClientURI mongoClientURI = new MongoClientURI( conf.getProperty("mongodb.url", "mongodb://localhost:27017"), options); if (!this.properties.containsKey("mongodb.database")) { if (mongoClientURI.getDatabase() != null && !mongoClientURI.getDatabase().isEmpty()) { this.properties.setProperty("mongodb.database", mongoClientURI.getDatabase()); } else { this.properties.setProperty("mongodb.database", DEFAULT_DATABASE); } } mongoClient = new MongoClient(mongoClientURI); }
From source file:com.stratio.connector.mongodb.core.configuration.MongoClientConfiguration.java
License:Apache License
/** * Convert the mongo connector string option to the appropriate write concern. * * @param writeSetting/*ww w . j a v a 2 s . c o m*/ * the write concern string setting * @return the write concern * @throws MongoValidationException * if the value cannot be parsed to a WriteConcern */ private WriteConcern settingToWritePreference(String writeSetting) throws MongoValidationException { WriteConcern writeConcern = null; switch (writeSetting.trim().toLowerCase()) { case "acknowledged": writeConcern = WriteConcern.ACKNOWLEDGED; break; case "unacknowledged": writeConcern = WriteConcern.UNACKNOWLEDGED; break; case "replica_acknowledged": writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; break; case "journaled": writeConcern = WriteConcern.JOURNALED; break; default: throw new MongoValidationException("Write preference " + writeSetting + " is not a legal value"); } return writeConcern; }
From source file:net.acesinc.nifi.processors.mongodb.PartialUpdateMongo.java
protected WriteConcern getWriteConcern(final ProcessContext context) { final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue(); WriteConcern writeConcern = null;//w w w. j a v a2 s . c o m switch (writeConcernProperty) { case WRITE_CONCERN_ACKNOWLEDGED: writeConcern = WriteConcern.ACKNOWLEDGED; break; case WRITE_CONCERN_UNACKNOWLEDGED: writeConcern = WriteConcern.UNACKNOWLEDGED; break; case WRITE_CONCERN_FSYNCED: writeConcern = WriteConcern.FSYNCED; break; case WRITE_CONCERN_JOURNALED: writeConcern = WriteConcern.JOURNALED; break; case WRITE_CONCERN_REPLICA_ACKNOWLEDGED: writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; break; case WRITE_CONCERN_MAJORITY: writeConcern = WriteConcern.MAJORITY; break; default: writeConcern = WriteConcern.ACKNOWLEDGED; } return writeConcern; }
From source file:org.apache.nifi.mongodb.AbstractMongoDBControllerService.java
License:Apache License
protected WriteConcern getWriteConcern(final ConfigurationContext context) { final String writeConcernProperty = context.getProperty(WRITE_CONCERN).getValue(); WriteConcern writeConcern = null;/*from www . j a va2 s . c o m*/ switch (writeConcernProperty) { case WRITE_CONCERN_ACKNOWLEDGED: writeConcern = WriteConcern.ACKNOWLEDGED; break; case WRITE_CONCERN_UNACKNOWLEDGED: writeConcern = WriteConcern.UNACKNOWLEDGED; break; case WRITE_CONCERN_FSYNCED: writeConcern = WriteConcern.FSYNCED; break; case WRITE_CONCERN_JOURNALED: writeConcern = WriteConcern.JOURNALED; break; case WRITE_CONCERN_REPLICA_ACKNOWLEDGED: writeConcern = WriteConcern.REPLICA_ACKNOWLEDGED; break; case WRITE_CONCERN_MAJORITY: writeConcern = WriteConcern.MAJORITY; break; default: writeConcern = WriteConcern.ACKNOWLEDGED; } return writeConcern; }
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();// w ww . 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.openmama.dbwriter.MamaMongodb.java
/** * @return Write concern for database writes *///from w w w.j a v a2 s. c o m private WriteConcern getWriteConcern(final String config) { switch (config.toLowerCase()) { case "none": case "errors_ignored": case "errorsignored": return WriteConcern.ERRORS_IGNORED; case "safe": case "acknowledged": return WriteConcern.ACKNOWLEDGED; case "normal": case "unacknowledged": return WriteConcern.UNACKNOWLEDGED; case "fsync_safe": case "fsyncsafe": case "fsynced": return WriteConcern.FSYNCED; case "journal_safe": case "journalsafe": case "journaled": return WriteConcern.JOURNALED; case "replicas_safe": case "replicassafe": case "replica_acknowledged": case "replicaacknowledged": return WriteConcern.REPLICA_ACKNOWLEDGED; case "majority": return WriteConcern.MAJORITY; default: logger.warning(String.format("%s writeTo concern not valid - using UNACKNOWLEDGED", config)); return WriteConcern.UNACKNOWLEDGED; } }