@Override public void gotTimestamp(final String name, final int time, final int increment) { _put(name, new BSONTimestamp(time, increment)); }
@Override public BSONTimestamp decode(final BsonReader reader, final DecoderContext decoderContext) { BsonTimestamp timestamp = reader.readTimestamp(); return new BSONTimestamp(timestamp.getTime(), timestamp.getInc()); }
Integer ts = ((Number) b.get("$ts")).intValue(); Integer inc = ((Number) b.get("$inc")).intValue(); o = new BSONTimestamp(ts, inc); } else if (b.containsField("$timestamp")) { BSONObject tsObject = (BSONObject) b.get("$timestamp"); Integer ts = ((Number) tsObject.get("t")).intValue(); Integer inc = ((Number) tsObject.get("i")).intValue(); o = new BSONTimestamp(ts, inc); } else if (b.containsField("$code")) { if (b.containsField("$scope")) {
if (ctx != null) { long timestamp = Long.parseLong(ctx.toString()); timeStamp = new BSONTimestamp((int) (new Date(timestamp).getTime() / 1000), 1);
case TIMESTAMP: BsonTimestamp timestamp = reader.readTimestamp(); return new BSONTimestamp(timestamp.getTime(), timestamp.getInc()); case INT64: return reader.readInt64();
@Override public BasicDBObject createQuery(Object lastVal, String increasingField) { return new BasicDBObject(increasingField, new BasicDBObject("$gt", new BSONTimestamp((Integer)lastVal, 1))); } }, LITERAL {
public void __setstate__(final HashMap state) { // CHECKSTYLE:ON Object time = state.get("_Timestamp__time"); Object inc = state.get("_Timestamp__inc"); if (!((time instanceof Integer) && (inc instanceof Integer))) { throw new PickleException( "Excpected Integer for keys \"_Timestamp__time\" and " + "\"Timestamp__inc\", not a " + time.getClass().getName() + " and a " + inc.getClass().getName()); } value = new BSONTimestamp((Integer) time, (Integer) inc); }
public void gotTimestamp(String name, int time, int inc) { _put(name, new BSONTimestamp(time, inc)); }
public BSONTimestamp getLastTimestamp() { BufferedReader input = null; try{ File file = new File(OPLOG_LAST_FILENAME); if(!file.exists()){ return null; } input = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF8")); String line = input.readLine(); String[] parts = line.split("\\|"); return new BSONTimestamp(Integer.parseInt(parts[0]),Integer.parseInt(parts[1])); } catch(Exception e){ e.printStackTrace(); } finally{ if(input != null){ try{input.close();} catch(Exception e){} } } return null; }
private BSONTimestamp getStartingTimestamp() { Get get = new Get(_tailerID); Result res; try { res = _stateTable.get(get); } catch (IOException e) { log.error("Failed to get a starting timestamp for tailer ID: " + _tailerID); return null; } if (res.isEmpty()) { if(ConfigUtil.getSkipBacklog(_conf)) return new BSONTimestamp((int) (System.currentTimeMillis() / 1000L), 0); return null; } else { byte[] raw_optime = res.getValue(STATE_TABLE_COL_FAMILY, STATE_TABLE_COL_QUALIFIER_OPTIME); byte[] raw_inc = res.getValue(STATE_TABLE_COL_FAMILY, STATE_TABLE_COL_QUALIFIER_INC); _optime = Integer.parseInt(new String(raw_optime)); _inc = Integer.parseInt(new String(raw_inc)); _optimeSet = true; return new BSONTimestamp(_optime, _inc); } }
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(args[++i]); AFTER_TIMESTAMP = new BSONTimestamp((int)(date.getTime()/1000), 0); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(args[++i]); BEFORE_TIMESTAMP = new BSONTimestamp((int)(date.getTime()/1000), 0);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(args[++i]); AFTER_TIMESTAMP = new BSONTimestamp((int)(date.getTime()/1000), 0); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Date date = sdf.parse(args[++i]); BEFORE_TIMESTAMP = new BSONTimestamp((int)(date.getTime()/1000), 0);
@Override public BSONTimestamp decode(final BsonReader reader, final DecoderContext decoderContext) { BsonTimestamp timestamp = reader.readTimestamp(); return new BSONTimestamp(timestamp.getTime(), timestamp.getInc()); }
public void serialize(Object obj, StringBuilder buf) { BSONTimestamp t; if (obj instanceof Timestamp) { t = new BSONTimestamp((Timestamp) obj); } else { t = (BSONTimestamp) obj; } BasicBSONObject temp = new BasicBSONObject(); temp.put("$ts", Integer.valueOf(t.getTime())); temp.put("$inc", Integer.valueOf(t.getInc())); serializer.serialize(temp, buf); }
public void serialize(Object obj, StringBuilder buf) { BSONTimestamp t; if (obj instanceof Timestamp) { t = new BSONTimestamp((Timestamp) obj); } else { t = (BSONTimestamp) obj; } BasicBSONObject temp = new BasicBSONObject(); temp.put("$t", Integer.valueOf(t.getTime())); temp.put("$i", Integer.valueOf(t.getInc())); BasicBSONObject timestampObj = new BasicBSONObject(); timestampObj.put("$timestamp", temp); serializer.serialize(timestampObj, buf); }
/** * Creates the query to execute on the collection. * * @return the query */ private Bson createQuery() { // timestamps are used as offsets, saved as a concatenation of seconds and order Integer timestamp = 0; Integer order = 0; if(!start.equals("0")){ final String[] splitted = start.split("_"); timestamp = Integer.valueOf(splitted[0]); order = Integer.valueOf(splitted[1]); } Bson query = Filters.and( Filters.exists("fromMigrate", false), Filters.gt("ts", new BSONTimestamp(timestamp, order)), Filters.or( Filters.eq("op", "i"), Filters.eq("op", "u"), Filters.eq("op", "d") ), Filters.eq("ns", db) ); return query; } }
putNull(name); else if (val instanceof Timestamp) putTimestamp(name, new BSONTimestamp((Timestamp) val)); else if (val instanceof Date) putDate(name, (Date) val);
/** * Tests if {@code Timestamp} objects can be deserialized * @throws Exception if something goes wrong */ @Test public void timestamp() throws Exception { org.bson.types.BSONTimestamp ts = new org.bson.types.BSONTimestamp(1, 2); TC.T obj = generateAndParse(ts, TC.T.class); assertEquals(ts.getTime(), obj.obj.getTime()); assertEquals(ts.getInc(), obj.obj.getInc()); }
/** * Test if a complex BSON object containing various values can be * deserialized * @throws Exception if something goes wrong */ @Test public void parseComplex() throws Exception { BSONObject o = new BasicBSONObject(); o.put("Timestamp", new BSONTimestamp(0xAABB, 0xCCDD)); o.put("Symbol", new Symbol("Test")); o.put("ObjectId", org.bson.types.ObjectId.createFromLegacyFormat( Integer.MAX_VALUE, -2, Integer.MIN_VALUE)); Pattern p = Pattern.compile(".*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL | Pattern.MULTILINE | Pattern.UNICODE_CASE); o.put("Regex", p); Map<?, ?> data = parseBsonObject(o); assertEquals(new Timestamp(0xAABB, 0xCCDD), data.get("Timestamp")); assertEquals(new de.undercouch.bson4jackson.types.Symbol("Test"), data.get("Symbol")); ObjectId oid = (ObjectId)data.get("ObjectId"); assertEquals(Integer.MAX_VALUE, oid.getTime()); assertEquals(-2, oid.getMachine()); assertEquals(Integer.MIN_VALUE, oid.getInc()); Pattern p2 = (Pattern)data.get("Regex"); assertEquals(p.flags(), p2.flags()); assertEquals(p.pattern(), p2.pattern()); }
} else if (value instanceof Timestamp) { Timestamp ts = (Timestamp)value; value = new BSONTimestamp(ts.getTime(), ts.getInc()); } else if (value instanceof CodeWithScope) { CodeWithScope code = (CodeWithScope)value;