db.getAtomicLong("checksum").set(checksum);
db.getAtomicLong("checksum").set(checksum);
checksum = db.getAtomicLong("checksum").get();
public void applyDiffs(List<Diff> workQueue) { try { SAXParserFactory factory = SAXParserFactory.newInstance(); factory.setNamespaceAware(true); SAXParser saxParser = factory.newSAXParser(); DefaultHandler handler = new OSMChangeParser(osm); for (Diff state : workQueue) { LOG.info("Applying {} update for {}", state.timescale, getDateString(state.timestamp * 1000)); InputStream inputStream = new GZIPInputStream(state.url.openStream()); saxParser.parse(inputStream, handler); // Move the DB timestamp forward to that of the update that was applied osm.timestamp.set(state.timestamp); // Record the last update applied so we can jump straight to the next one lastApplied = state; } } catch (Exception e) { e.printStackTrace(); } }
/** * @return a chronologically ordered list of all diffs at the given timescale with a timestamp after * the database timestamp. */ public List<Diff> findDiffs (String timescale) { List<Diff> workQueue = new ArrayList<Diff>(); Diff latest = fetchState(timescale, 0); // Only check specific updates if the overall state for this timescale implies there are new ones. if (latest.timestamp > osm.timestamp.get()) { // Working backward, find all updates that are dated after the current database timestamp. for (int seq = latest.sequenceNumber; seq > 0; seq--) { Diff diff = fetchState(timescale, seq); if (diff.timestamp <= osm.timestamp.get()) break; workQueue.add(diff); } } LOG.info("Found {} {}-scale updates.", workQueue.size(), timescale); // Put the updates in chronological order before returning them return Lists.reverse(workQueue); }
/** * Atomically adds the given value to the current value. * * @param delta the value to add * @return the previous value */ public final long getAndAdd(long delta) { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current + delta; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** Write the contents of this OSM MapDB out to an OSM entity sink (from OSMEntitySource interface). */ @Override public void copyTo (OSMEntitySink sink) throws IOException { sink.setReplicationTimestamp(timestamp.get()); sink.writeBegin(); if (timestamp.get() > 0) { sink.setReplicationTimestamp(timestamp.get()); } for (Map.Entry<Long, Node> nodeEntry : this.nodes.entrySet()) { sink.writeNode(nodeEntry.getKey(), nodeEntry.getValue()); } for (Map.Entry<Long, Way> wayEntry : this.ways.entrySet()) { sink.writeWay(wayEntry.getKey(), wayEntry.getValue()); } for (Map.Entry<Long, Relation> relationEntry : this.relations.entrySet()) { sink.writeRelation(relationEntry.getKey(), relationEntry.getValue()); } sink.writeEnd(); }
/** * Atomically increments by one the current value. * * @return the updated value */ public final long incrementAndGet() { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current + 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
/** * Atomically sets to the given value and returns the old value. * * @param newValue the new value * @return the previous value */ public final long getAndSet(long newValue) { //$DELAY$ while (true) { //$DELAY$ long current = get(); //$DELAY$ if (compareAndSet(current, newValue)) { //$DELAY$ return current; } } }
/** * Atomically adds the given value to the current value. * * @param delta the value to add * @return the updated value */ public final long addAndGet(long delta) { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current + delta; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
/** * Atomically decrements by one the current value. * * @return the previous value */ public final long getAndDecrement() { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current - 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** * Atomically increments by one the current value. * * @return the previous value */ public final long getAndIncrement() { //$DELAY$ while (true) { //$DELAY$ long current = get(); long next = current + 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return current; } } }
/** * Atomically decrements by one the current value. * * @return the updated value */ public final long decrementAndGet() { //$DELAY$ for (;;) { //$DELAY$ long current = get(); long next = current - 1; //$DELAY$ if (compareAndSet(current, next)) { //$DELAY$ return next; } } }
public float floatValue() { return (float)get(); }
public long getCurrentCount() { return id.get() - INITIAL_VALUE; }
public long getNextId() { return id.getAndIncrement(); }
/** * This is the main entry point. Give it an OSM database and it will keep it up to date in a new thread. */ public static Thread spawnUpdateThread(OSM osm) { Thread updateThread = new Thread(new Updater(osm)); Instant initialTimestamp = Instant.ofEpochSecond(osm.timestamp.get()); if (initialTimestamp.isBefore(MIN_REPLICATION_INSTANT) || initialTimestamp.isAfter(MAX_REPLICATION_INSTANT)) { LOG.error("OSM database timestamp seems incorrect: {}", initialTimestamp.toString()); LOG.error("Not running the minutely updater thread."); } else { updateThread.start(); } return updateThread; }
public int intValue() { return (int)get(); }
public long longValue() { return get(); }