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:org.semispace.semimeter.dao.mongo.SemiMeterDaoMongo.java
License:Apache License
private void deleteOldMinutes(long before24h, long before180min, long before15min) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(before24h);//from w w w .j av a2s. c o m cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MINUTE, 0); long targetHour = cal.getTimeInMillis(); DBCollection meterCollection = mongoTemplate.getCollection("meter"); DBCursor result = meterCollection.find(new BasicDBObject(), new BasicDBObject("_id", 1)); while (result.hasNext()) { DBObject doc = result.next(); try { //start a new "session" for each document. not sure if this actually helps anything consistency-wise meterCollection.getDB().requestStart(); //and fetch actual object (result only contains _id's) doc = meterCollection.findOne(doc); // TODO Double check log.trace("cleaning document : {}", doc); DBObject day = (DBObject) doc.get("day"); //log.trace("day: {}", day); DBObject hours = (DBObject) day.get("hours"); //log.trace("hours: {}", hours); Set<String> hrSet = new HashSet<String>(); hrSet.addAll(hours.keySet()); boolean docChanged = false; if (hrSet.isEmpty()) { log.trace("no hours in document, remove it: {}", doc); meterCollection.remove(new BasicDBObject("_id", doc.get("_id")), WriteConcern.UNACKNOWLEDGED); } else { for (String h : hrSet) { long hourmillis = Long.valueOf(h); log.trace("checking hour: {}", hourmillis); if (hourmillis < targetHour) { if (log.isTraceEnabled()) { log.trace("removing hour " + h + " because it is older than target" + targetHour); } docChanged = true; DBObject obj = (DBObject) hours.get(h); day.put("count", (Integer) day.get("count") - (Integer) obj.get("count")); hours.removeField(h); } else if (hourmillis == targetHour) { log.trace("current hour is targetHour, check minutes"); DBObject currentHour = (DBObject) hours.get(h); DBObject minutes = (DBObject) currentHour.get("minutes"); Set<String> keys = new HashSet<String>(); keys.addAll(minutes.keySet()); for (String m : keys) { long minutemillis = Long.valueOf(m); log.trace("checking minute: {}", minutemillis); if (minutemillis < before24h) { if (log.isTraceEnabled()) { log.trace("removing minute " + minutemillis + " because it is older than " + before24h); } docChanged = true; DBObject obj = (DBObject) minutes.get(m); DBObject hourObj = (DBObject) hours.get(h); day.put("count", (Integer) day.get("count") - (Integer) obj.get("count")); hourObj.put("count", (Integer) hourObj.get("count") - (Integer) obj.get("count")); minutes.removeField(m); } } if (minutes.keySet().isEmpty()) { log.trace("no more minutes, removing hour {}", h); hours.removeField(h); docChanged = true; } } } } docChanged |= updateTrendCounters(doc, before180min, before15min); if (docChanged) { meterCollection.save(doc); } } finally { meterCollection.getDB().requestDone(); } } }
From source file:org.semispace.semimeter.dao.mongo.SemiMeterDaoMongo.java
License:Apache License
private void deleteOldSums(long when) { DBCollection sumsCollection = mongoTemplate.getCollection("sums"); DBCursor result = sumsCollection.find((DBObject) JSON.parse("{'time.ts': {'$lt': " + when + "}}")); while (result.hasNext()) { sumsCollection.remove(result.next(), WriteConcern.UNACKNOWLEDGED); }/*from w w w.j av a 2 s.c o m*/ }