Merge pull request #263 from mikeprimm/master

Cleanup event synchronize, so that web config request is more parallel
This commit is contained in:
mikeprimm 2011-07-09 16:17:08 -07:00
commit dcca317b2f
4 changed files with 34 additions and 19 deletions

View File

@ -1,21 +1,31 @@
package org.dynmap; package org.dynmap;
import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
public class Event<T> { public class Event<T> {
private List<Listener<T>> listeners = new LinkedList<Listener<T>>(); private List<Listener<T>> listeners = new LinkedList<Listener<T>>();
private Object lock = new Object();
public synchronized void addListener(Listener<T> l) { public void addListener(Listener<T> l) {
listeners.add(l); synchronized(lock) {
listeners.add(l);
}
} }
public synchronized void removeListener(Listener<T> l) { public void removeListener(Listener<T> l) {
listeners.remove(l); synchronized(lock) {
listeners.remove(l);
}
} }
public synchronized void trigger(T t) { public void trigger(T t) {
for (Listener<T> l : listeners) { ArrayList<Listener<T>> iterlist;
synchronized(lock) {
iterlist = new ArrayList<Listener<T>>(listeners);
}
for (Listener<T> l : iterlist) {
l.triggered(t); l.triggered(t);
} }
} }

View File

@ -188,6 +188,7 @@ public class MapManager {
found.clear(); found.clear();
rendered.clear(); rendered.clear();
rendercnt = 0; rendercnt = 0;
timeaccum = 0;
map_index++; /* Next map */ map_index++; /* Next map */
if(map_index >= world.maps.size()) { /* Last one done? */ if(map_index >= world.maps.size()) { /* Last one done? */
sender.sendMessage("Full render of '" + world.world.getName() + "' finished."); sender.sendMessage("Full render of '" + world.world.getName() + "' finished.");

View File

@ -2,11 +2,11 @@ package org.dynmap;
import java.io.File; import java.io.File;
import java.io.RandomAccessFile; import java.io.RandomAccessFile;
import java.util.Arrays; import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import java.io.IOException; import java.io.IOException;
import java.util.zip.CRC32; import java.util.zip.CRC32;
import org.dynmap.utils.LRULinkedHashMap;
/** /**
* Image hash code manager - used to reduce compression and notification of updated tiles that do not actually yield new content * Image hash code manager - used to reduce compression and notification of updated tiles that do not actually yield new content
* *
@ -97,17 +97,6 @@ public class TileHashManager {
} }
} }
public static class LRULinkedHashMap<T, K> extends LinkedHashMap<T, K> {
private int limit;
public LRULinkedHashMap(int lim) {
super(16, (float)0.75, true);
limit = lim;
}
protected boolean removeEldestEntry(Map.Entry<T, K> last) {
return(size() >= limit);
}
}
private static final int MAX_CACHED_TILEHASHFILES = 25; private static final int MAX_CACHED_TILEHASHFILES = 25;
private Object lock = new Object(); private Object lock = new Object();
private LRULinkedHashMap<TileHashFile, byte[]> tilehash = new LRULinkedHashMap<TileHashFile, byte[]>(MAX_CACHED_TILEHASHFILES); private LRULinkedHashMap<TileHashFile, byte[]> tilehash = new LRULinkedHashMap<TileHashFile, byte[]>(MAX_CACHED_TILEHASHFILES);

View File

@ -0,0 +1,15 @@
package org.dynmap.utils;
import java.util.LinkedHashMap;
import java.util.Map;
public class LRULinkedHashMap<T, K> extends LinkedHashMap<T, K> {
private int limit;
public LRULinkedHashMap(int lim) {
super(16, (float)0.75, true);
limit = lim;
}
protected boolean removeEldestEntry(Map.Entry<T, K> last) {
return(size() >= limit);
}
}