mirror of
https://github.com/webbukkit/dynmap.git
synced 2025-01-01 13:37:40 +01:00
Merge branch 'master' into HEAD
This commit is contained in:
commit
ae190b3c57
@ -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) {
|
||||
listeners.add(l);
|
||||
public void addListener(Listener<T> l) {
|
||||
synchronized(lock) {
|
||||
listeners.add(l);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void removeListener(Listener<T> l) {
|
||||
listeners.remove(l);
|
||||
public void removeListener(Listener<T> l) {
|
||||
synchronized(lock) {
|
||||
listeners.remove(l);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void trigger(T t) {
|
||||
for (Listener<T> l : listeners) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@ -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