projects
/
fw
/
altos
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'branch-1.6' into debian
[fw/altos]
/
altoslib
/
AltosMapStore.java
diff --git
a/altoslib/AltosMapStore.java
b/altoslib/AltosMapStore.java
index c06384339eaf55f23580809d9528389597f86619..aed365ca175e07ea81abe05b7535b707227887dd 100644
(file)
--- a/
altoslib/AltosMapStore.java
+++ b/
altoslib/AltosMapStore.java
@@
-15,7
+15,7
@@
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/
-package org.altusmetrum.altoslib_
9
;
+package org.altusmetrum.altoslib_
10
;
import java.io.*;
import java.net.*;
import java.io.*;
import java.net.*;
@@
-35,6
+35,7
@@
public class AltosMapStore {
public synchronized void add_listener(AltosMapStoreListener listener) {
if (!listeners.contains(listener))
listeners.add(listener);
public synchronized void add_listener(AltosMapStoreListener listener) {
if (!listeners.contains(listener))
listeners.add(listener);
+ listener.notify_store(this, status);
}
public synchronized void remove_listener(AltosMapStoreListener listener) {
}
public synchronized void remove_listener(AltosMapStoreListener listener) {
@@
-110,7
+111,7
@@
public class AltosMapStore {
file.delete();
return AltosMapTile.bad_request;
}
file.delete();
return AltosMapTile.bad_request;
}
- return AltosMapTile.
success
;
+ return AltosMapTile.
fetched
;
}
static Object fetch_lock = new Object();
}
static Object fetch_lock = new Object();
@@
-118,42
+119,42
@@
public class AltosMapStore {
static final long forbidden_interval = 60l * 1000l * 1000l * 1000l;
static final long google_maps_ratelimit_ms = 1200;
static final long forbidden_interval = 60l * 1000l * 1000l * 1000l;
static final long google_maps_ratelimit_ms = 1200;
- static Object
load
er_lock = new Object();
+ static Object
fetch
er_lock = new Object();
static LinkedList<AltosMapStore> waiting = new LinkedList<AltosMapStore>();
static LinkedList<AltosMapStore> running = new LinkedList<AltosMapStore>();
static LinkedList<AltosMapStore> waiting = new LinkedList<AltosMapStore>();
static LinkedList<AltosMapStore> running = new LinkedList<AltosMapStore>();
- static final int concurrent_
load
ers = 128;
+ static final int concurrent_
fetch
ers = 128;
- static void start_
load
ers() {
- while (!waiting.isEmpty() && running.size() < concurrent_
load
ers) {
+ static void start_
fetch
ers() {
+ while (!waiting.isEmpty() && running.size() < concurrent_
fetch
ers) {
AltosMapStore s = waiting.remove();
running.add(s);
AltosMapStore s = waiting.remove();
running.add(s);
- Thread lt = s.make_
load
er_thread();
+ Thread lt = s.make_
fetch
er_thread();
lt.start();
}
}
lt.start();
}
}
- void finish_
load
er() {
- synchronized(
load
er_lock) {
+ void finish_
fetch
er() {
+ synchronized(
fetch
er_lock) {
running.remove(this);
running.remove(this);
- start_
load
ers();
+ start_
fetch
ers();
}
}
}
}
- void add_
load
er() {
- synchronized(
load
er_lock) {
+ void add_
fetch
er() {
+ synchronized(
fetch
er_lock) {
waiting.add(this);
waiting.add(this);
- start_
load
ers();
+ start_
fetch
ers();
}
}
}
}
- class
load
er implements Runnable {
+ class
fetch
er implements Runnable {
public void run() {
try {
if (file.exists()) {
public void run() {
try {
if (file.exists()) {
- notify_listeners(AltosMapTile.
success
);
+ notify_listeners(AltosMapTile.
fetched
);
return;
}
return;
}
@@
-170,7
+171,7
@@
public class AltosMapStore {
synchronized (fetch_lock) {
long startTime = System.nanoTime();
new_status = fetch_url();
synchronized (fetch_lock) {
long startTime = System.nanoTime();
new_status = fetch_url();
- if (new_status == AltosMapTile.
success
) {
+ if (new_status == AltosMapTile.
fetched
) {
long duration_ms = (System.nanoTime() - startTime) / 1000000;
if (duration_ms < google_maps_ratelimit_ms) {
try {
long duration_ms = (System.nanoTime() - startTime) / 1000000;
if (duration_ms < google_maps_ratelimit_ms) {
try {
@@
-186,17
+187,17
@@
public class AltosMapStore {
}
notify_listeners(new_status);
} finally {
}
notify_listeners(new_status);
} finally {
- finish_
load
er();
+ finish_
fetch
er();
}
}
}
}
}
}
- private Thread make_
load
er_thread() {
- return new Thread(new
load
er());
+ private Thread make_
fetch
er_thread() {
+ return new Thread(new
fetch
er());
}
}
- private void
load
() {
- add_
load
er();
+ private void
fetch
() {
+ add_
fetch
er();
}
private AltosMapStore (String url, File file) {
}
private AltosMapStore (String url, File file) {
@@
-204,10
+205,10
@@
public class AltosMapStore {
this.file = file;
if (file.exists())
this.file = file;
if (file.exists())
- status = AltosMapTile.
success
;
+ status = AltosMapTile.
fetched
;
else {
else {
- status = AltosMapTile.
load
ing;
-
load
();
+ status = AltosMapTile.
fetch
ing;
+
fetch
();
}
}
}
}