List of usage examples for com.mongodb WriteConcern SAFE
WriteConcern SAFE
To view the source code for com.mongodb WriteConcern SAFE.
Click Source Link
Write operations that use this write concern will wait for acknowledgement from the primary server before returning.
From source file:org.jwebsocket.http.MongoDBConnectorsManager.java
License:Apache License
/** * * @param aSessionId/*from w w w.j a v a 2s . co m*/ * @param aConnectionId * @return * @throws Exception */ @Override public HTTPConnector add(String aSessionId, String aConnectionId) throws Exception { Assert.notNull(aConnectionId); Assert.notNull(aSessionId); if (null == mConnectors.findOne(new BasicDBObject().append(Attributes.CONNECTION_ID, aConnectionId))) { mConnectors.save(new BasicDBObject().append(Attributes.CONNECTION_ID, aConnectionId) .append(Attributes.SESSION_ID, aSessionId), WriteConcern.SAFE); } return getConnectorById(aConnectionId, true); }
From source file:org.jwebsocket.jms.mongodb.MongoDBClusterSynchronizer.java
License:Apache License
@Override public boolean getWorkerTurn(String aMessageId) { try {/*from w w w . ja va2s . c o m*/ mCollection.insert(new BasicDBObject().append(Attributes.MESSAGE_ID, aMessageId), WriteConcern.SAFE); return true; } catch (Exception lEx) { return false; } }
From source file:org.jwebsocket.jms.mongodb.MongoDBConnectorsManager.java
License:Apache License
@Override public JMSConnector add(String aConnectionId, String aConsumerId, String aReplySelector, String aSessionId) throws Exception { Assert.notNull(aConnectionId);//from www. j a v a 2 s.co m Assert.notNull(aReplySelector); if (null == mConnectors.findOne(new BasicDBObject().append(Attributes.CONSUMER_ID, aConsumerId))) { mConnectors.save(new BasicDBObject().append(Attributes.CONNECTION_ID, aConnectionId) .append(Attributes.CONSUMER_ID, aConsumerId).append(Attributes.REPLY_SELECTOR, aReplySelector) .append(Attributes.STATUS, ConnectorStatus.UP).append(Attributes.SESSION_ID, aSessionId), WriteConcern.SAFE); } return getConnectorById(aConnectionId); }
From source file:org.jwebsocket.jms.mongodb.MongoDBConnectorsManager.java
License:Apache License
@Override public void remove(String aConsumerId) throws Exception { mConnectors.remove(new BasicDBObject().append(Attributes.CONSUMER_ID, aConsumerId), WriteConcern.SAFE); }
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 . j a v a 2 s.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.mongeez.dao.MongeezDao.java
License:Apache License
private void addTypeToUntypedRecords() { DBObject q = new QueryBuilder().put("type").exists(false).get(); BasicDBObject o = new BasicDBObject("$set", new BasicDBObject("type", RecordType.changeSetExecution.name())); getMongeezCollection().update(q, o, false, true, WriteConcern.SAFE); }
From source file:org.mongeez.dao.MongeezDao.java
License:Apache License
private void loadConfigurationRecord() { DBObject q = new QueryBuilder().put("type").is(RecordType.configuration.name()).get(); DBObject configRecord = getMongeezCollection().findOne(q); if (configRecord == null) { if (getMongeezCollection().count() > 0L) { // We have pre-existing records, so don't assume that they support the latest features configRecord = new BasicDBObject().append("type", RecordType.configuration.name()) .append("supportResourcePath", false); } else {// w w w . java 2s .c o m configRecord = new BasicDBObject().append("type", RecordType.configuration.name()) .append("supportResourcePath", true); } getMongeezCollection().insert(configRecord, WriteConcern.SAFE); } Object supportResourcePath = configRecord.get("supportResourcePath"); changeSetAttributes = new ArrayList<ChangeSetAttribute>(); changeSetAttributes.add(ChangeSetAttribute.file); changeSetAttributes.add(ChangeSetAttribute.changeId); changeSetAttributes.add(ChangeSetAttribute.author); if (Boolean.TRUE.equals(supportResourcePath)) { changeSetAttributes.add(ChangeSetAttribute.resourcePath); } }
From source file:org.mongeez.dao.MongeezDao.java
License:Apache License
public void logChangeSet(ChangeSet changeSet) { BasicDBObject object = new BasicDBObject(); object.append("type", RecordType.changeSetExecution.name()); for (ChangeSetAttribute attribute : changeSetAttributes) { object.append(attribute.name(), attribute.getAttributeValue(changeSet)); }//from ww w . j ava 2 s . c o m object.append("date", DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(System.currentTimeMillis())); getMongeezCollection().insert(object, WriteConcern.SAFE); }
From source file:org.qi4j.entitystore.mongodb.MongoMapEntityStoreMixin.java
License:Apache License
private void loadConfiguration() throws UnknownHostException { configuration.refresh();// w w w.jav a 2 s . com 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.rhq.enterprise.server.plugins.drift.mongodb.MongoDBDriftServer.java
License:Open Source License
@Override public void initialize(ServerPluginContext context) throws Exception { connection = new Mongo("127.0.0.1"); morphia = new Morphia().map(MongoDBChangeSet.class).map(MongoDBChangeSetEntry.class).map(MongoDBFile.class); ds = morphia.createDatastore(connection, "rhq"); changeSetDAO = new ChangeSetDAO(morphia, connection, "rhq"); fileDAO = new FileDAO(ds.getDB()); // Note that a write concern of SAFE does not cause the write operation // to wait for the server to flush to disk which occurrs every one // minute by default. With journaled enabled however (which is the // default), we get the ability to recover from errors such as failure // to flush to disk. If we absolutely need to wait and ensure that the // write is successfully written to disk, we could use a write concern // of FSYNC_SAFE; however, this should be used very judiciously as it // will introduce a significant performance overhead on the server as // it forces a flush to disk on every write (from this connect). ds.setDefaultWriteConcern(WriteConcern.SAFE); }