mirror of
https://github.com/webbukkit/dynmap.git
synced 2024-12-28 03:27:36 +01:00
Merge pull request #263 from mikeprimm/master
Cleanup event synchronize, so that web config request is more parallel
This commit is contained in:
commit
dcca317b2f
@ -1,21 +1,31 @@
|
||||
package org.dynmap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Event<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) {
|
||||
synchronized(lock) {
|
||||
listeners.add(l);
|
||||
}
|
||||
|
||||
public synchronized void removeListener(Listener<T> l) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
|
||||
public synchronized void trigger(T t) {
|
||||
for (Listener<T> l : listeners) {
|
||||
public void removeListener(Listener<T> l) {
|
||||
synchronized(lock) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
}
|
||||
|
||||
public void trigger(T t) {
|
||||
ArrayList<Listener<T>> iterlist;
|
||||
synchronized(lock) {
|
||||
iterlist = new ArrayList<Listener<T>>(listeners);
|
||||
}
|
||||
for (Listener<T> l : iterlist) {
|
||||
l.triggered(t);
|
||||
}
|
||||
}
|
||||
|
@ -188,6 +188,7 @@ public class MapManager {
|
||||
found.clear();
|
||||
rendered.clear();
|
||||
rendercnt = 0;
|
||||
timeaccum = 0;
|
||||
map_index++; /* Next map */
|
||||
if(map_index >= world.maps.size()) { /* Last one done? */
|
||||
sender.sendMessage("Full render of '" + world.world.getName() + "' finished.");
|
||||
|
@ -2,11 +2,11 @@ package org.dynmap;
|
||||
import java.io.File;
|
||||
import java.io.RandomAccessFile;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.io.IOException;
|
||||
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
|
||||
*
|
||||
@ -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 Object lock = new Object();
|
||||
private LRULinkedHashMap<TileHashFile, byte[]> tilehash = new LRULinkedHashMap<TileHashFile, byte[]>(MAX_CACHED_TILEHASHFILES);
|
||||
|
15
src/main/java/org/dynmap/utils/LRULinkedHashMap.java
Normal file
15
src/main/java/org/dynmap/utils/LRULinkedHashMap.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user