List of usage examples for com.mongodb WriteConcern UNACKNOWLEDGED
WriteConcern UNACKNOWLEDGED
To view the source code for com.mongodb WriteConcern UNACKNOWLEDGED.
Click Source Link
From source file:io.sip3.tapir.salto.configuration.MongoConfiguration.java
License:Apache License
@Bean public MongoClientURI uri(@Value("${mongo.uri}") String uri) { return new MongoClientURI(uri, MongoClientOptions.builder().writeConcern(WriteConcern.UNACKNOWLEDGED)); }
From source file:it.wami.map.mongodeploy.OsmSaxHandler.java
License:Apache License
private void saveTag(String key, String value) { if (Arrays.asList(Tag.TYPES).contains(key)) { Tag tag = new Tag(); tag.setKeyValue(key, value);//www. j av a 2s . c o m Map<String, String> pair = new HashMap<String, String>(); pair.put(key, value); if (pairList.contains(pair)) return; pairList.add(pair); DBCollection coll = db.getCollection(COLL_TAGS); //if(coll.find(new BasicDBObject(key, value)).count() > 0) //return; try { // this speed up the proccess coll.insert(tag, WriteConcern.UNACKNOWLEDGED); } catch (IllegalArgumentException e) { e.printStackTrace(); } } }
From source file:it.wami.map.mongodeploy.OsmSaxHandler.java
License:Apache License
/** * Save the array in mongoDB./* ww w. j a v a 2s . c om*/ * @param obj the entry * @param collection */ private void saveEntry(List<DBObject> obj, String collection) { DBCollection coll = db.getCollection(collection); try { // this speed up the proccess synchronized (obj) { try { coll.insert(obj, WriteConcern.UNACKNOWLEDGED); } catch (MongoInternalException e) { recover(coll, obj); } nodesQueue.clear(); waysQueue.clear(); relationsQueue.clear(); tagsQueue.clear(); } } catch (IllegalArgumentException e) { e.printStackTrace(); } }
From source file:it.wami.map.mongodeploy.OsmSaxHandler.java
License:Apache License
/** * Try to recover the objects that can be saved inside the DB. * /* w ww .ja v a2 s . c o m*/ * @param coll {@link DBCollection} the target collection. * @param list {@link List}<{@link DBObject}> the list of objs to save inside the DB. */ private void recover(DBCollection coll, List<DBObject> list) { for (DBObject o : list) { try { coll.insert(o, WriteConcern.UNACKNOWLEDGED); } catch (MongoInternalException e) { System.err.println(o.get("_id")); o.removeField("loc"); coll.insert(o, WriteConcern.UNACKNOWLEDGED); } } }
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;//ww w .java2 s .co 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 w w w .j a v a2 s . co 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.graylog2.metrics.MongoDbMetricsReporter.java
License:Open Source License
@Override public void report(SortedMap<String, Gauge> gauges, SortedMap<String, Counter> counters, SortedMap<String, Histogram> histograms, SortedMap<String, Meter> meters, SortedMap<String, Timer> timers) { final Date timestamp = new Date(clock.getTime()); List<DBObject> docs = Lists.newArrayListWithExpectedSize( gauges.size() + counters.size() + histograms.size() + meters.size() + timers.size()); collectGaugeReports(docs, gauges, timestamp); collectCounterReports(docs, counters, timestamp); collectHistogramReports(docs, histograms, timestamp); collectMeterReports(docs, meters, timestamp); collectTimerReports(docs, timers, timestamp); try {// w w w .java2 s.co m final DBCollection collection = mongoConnection.getDatabase().getCollection("graylog2_metrics"); // don't hang on to the data for too long. final BasicDBObject indexField = new BasicDBObject("timestamp", 1); final BasicDBObject indexOptions = new BasicDBObject("expireAfterSeconds", 5 * 60); collection.createIndex(indexField, indexOptions); collection.insert(docs, WriteConcern.UNACKNOWLEDGED); } catch (Exception e) { LOG.warn("Unable to write graylog2 metrics to mongodb. Ignoring this error.", e); } }
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 www .j a v a 2s . com 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 ww w . j a va 2 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; } }
From source file:org.semispace.semimeter.dao.mongo.SemiMeterDaoMongo.java
License:Apache License
@Override public void performInsertion(final Collection<Item> items) { DBCollection meterCollection = mongoTemplate.getCollection("meter"); DBCollection sumsCollection = mongoTemplate.getCollection("sums"); for (Item item : items) { //some time calculations Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(item.getWhen()); cal.set(Calendar.MILLISECOND, 0); long second = cal.getTimeInMillis(); cal.set(Calendar.SECOND, 0); long minute = cal.getTimeInMillis(); cal.set(Calendar.MINUTE, 0); long hour = cal.getTimeInMillis(); cal.setTimeInMillis(item.getWhen()); BasicDBObject query = new BasicDBObject(); PathElements pathElements = MeterHit.calcPath(item.getPath(), "/"); query.append("id", integerForCompatibilityReasonOrString(pathElements.getE4())); query.append("sectionId", integerForCompatibilityReasonOrString(pathElements.getE3())); query.append("publicationId", integerForCompatibilityReasonOrString(pathElements.getE2())); query.append("type", pathElements.getE1()); StringBuilder sb = new StringBuilder(); sb.append("{ '$inc': "); sb.append(" { 'day.count' : " + item.getAccessNumber() + ", "); sb.append(" 'day.last15minutes' : " + item.getAccessNumber() + ", "); sb.append(" 'day.last180minutes' : " + item.getAccessNumber() + ", "); sb.append(" 'day.hours." + hour + ".count' : " + item.getAccessNumber() + ", "); sb.append(// w w w . j a v a 2 s . c om " 'day.hours." + hour + ".minutes." + minute + ".count' : " + item.getAccessNumber() + " "); sb.append("}}"); DBObject update = (DBObject) JSON.parse(sb.toString()); meterCollection.update(query, update, true, false, WriteConcern.UNACKNOWLEDGED); query = new BasicDBObject(); BasicDBObject time = new BasicDBObject(); query.append("time", time); time.append("ts", minute); time.append("year", cal.get(Calendar.YEAR)); time.append("month", cal.get(Calendar.MONTH)); time.append("day", cal.get(Calendar.DAY_OF_MONTH)); time.append("hour", cal.get(Calendar.HOUR_OF_DAY)); time.append("minute", cal.get(Calendar.MINUTE)); sb = new StringBuilder(); sb.append(" { '$inc': "); sb.append("{ 'total' : ").append(item.getAccessNumber()); if (pathElements.getE1().equals("article")) { sb.append(", 'article' : ").append(item.getAccessNumber()); } else if (pathElements.getE1().equals("album")) { sb.append(", 'album' : ").append(item.getAccessNumber()); } else if (pathElements.getE1().equals("video")) { sb.append(", 'video' : ").append(item.getAccessNumber()); } else { sb.append(", 'other' : ").append(item.getAccessNumber()); } sb.append(" } }"); update = (DBObject) JSON.parse(sb.toString()); sumsCollection.update(query, update, true, false, WriteConcern.UNACKNOWLEDGED); } }