/** * 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; }
/** * Returns the String representation of the current value. * @return the String representation of the current value. */ public java.lang.String toString() { return java.lang.Long.toString(get()); }
/** * @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); }
/** 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 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 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 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 int intValue() { return (int)get(); }
public long longValue() { return get(); }
protected Long latestIndexUpdateTime() { // note that if the field doest not exist, this will return 0 return db.getAtomicLong(LAST_SUCCESSFUL_UPDATE).get(); }
protected Long latestIndexUpdateTime() { // note that if the field doest not exist, this will return 0 return db.getAtomicLong(LAST_SUCCESSFUL_UPDATE).get(); }
public double doubleValue() { return (double)get(); }
private void writeLatestUpdateTime( long updateTime ) { Atomic.Long atomicLong = db.getAtomicLong(LAST_SUCCESSFUL_UPDATE); long latestValue = atomicLong.get(); if (latestValue < updateTime) { atomicLong.compareAndSet(latestValue, updateTime); } } }
private void writeLatestUpdateTime( long updateTime ) { Atomic.Long atomicLong = db.getAtomicLong(LAST_SUCCESSFUL_UPDATE); long latestValue = atomicLong.get(); if (latestValue < updateTime) { atomicLong.compareAndSet(latestValue, updateTime); } } }
private GTFSFeed (DB db) { this.db = db; agency = db.getTreeMap("agency"); feedInfo = db.getTreeMap("feed_info"); routes = db.getTreeMap("routes"); trips = db.getTreeMap("trips"); stop_times = db.getTreeMap("stop_times"); frequencies = db.getTreeSet("frequencies"); transfers = db.getTreeMap("transfers"); stops = db.getTreeMap("stops"); fares = db.getTreeMap("fares"); services = db.getTreeMap("services"); shape_points = db.getTreeMap("shape_points"); feedId = db.getAtomicString("feed_id").get(); checksum = db.getAtomicLong("checksum").get(); errors = db.getTreeSet("errors"); }