Switch touch queue to concurrent map - remove synchronize
This commit is contained in:
parent
0169de4d7b
commit
cde0e8b4db
2 changed files with 28 additions and 23 deletions
|
|
@ -11,6 +11,7 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
import java.util.concurrent.Callable;
|
import java.util.concurrent.Callable;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.ExecutionException;
|
import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
import java.util.concurrent.RejectedExecutionException;
|
import java.util.concurrent.RejectedExecutionException;
|
||||||
|
|
@ -87,19 +88,21 @@ public class MapManager {
|
||||||
private static final int POOL_SIZE = 3;
|
private static final int POOL_SIZE = 3;
|
||||||
|
|
||||||
/* Touch event queues */
|
/* Touch event queues */
|
||||||
private static class TouchEvent implements Comparable<TouchEvent> {
|
private static class TouchEvent {
|
||||||
int x, y, z;
|
int x, y, z;
|
||||||
String world;
|
String world;
|
||||||
String reason;
|
String reason;
|
||||||
@Override
|
@Override
|
||||||
public int compareTo(TouchEvent te) {
|
public int hashCode() {
|
||||||
if(x < te.x) return -1;
|
return (x << 16) ^ (y << 24) ^ z;
|
||||||
if(x > te.x) return 1;
|
}
|
||||||
if(y < te.y) return -1;
|
@Override
|
||||||
if(y > te.y) return 1;
|
public boolean equals(Object o) {
|
||||||
if(z < te.z) return -1;
|
if(this == o) return true;
|
||||||
if(z > te.z) return 1;
|
TouchEvent te = (TouchEvent)o;
|
||||||
return world.compareTo(te.world);
|
if((x != te.x) || (y != te.y) || (z != te.z) || (world.equals(te.world) == false))
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private static class TouchVolumeEvent {
|
private static class TouchVolumeEvent {
|
||||||
|
|
@ -108,7 +111,7 @@ public class MapManager {
|
||||||
String world;
|
String world;
|
||||||
String reason;
|
String reason;
|
||||||
}
|
}
|
||||||
private TreeSet<TouchEvent> touch_events = new TreeSet<TouchEvent>();
|
private ConcurrentHashMap<TouchEvent, Object> touch_events = new ConcurrentHashMap<TouchEvent, Object>();
|
||||||
private LinkedList<TouchVolumeEvent> touch_volume_events = new LinkedList<TouchVolumeEvent>();
|
private LinkedList<TouchVolumeEvent> touch_volume_events = new LinkedList<TouchVolumeEvent>();
|
||||||
private Object touch_lock = new Object();
|
private Object touch_lock = new Object();
|
||||||
|
|
||||||
|
|
@ -1051,9 +1054,7 @@ public class MapManager {
|
||||||
evt.y = y;
|
evt.y = y;
|
||||||
evt.z = z;
|
evt.z = z;
|
||||||
evt.reason = reason;
|
evt.reason = reason;
|
||||||
synchronized(touch_lock) {
|
touch_events.putIfAbsent(evt, reason);
|
||||||
touch_events.add(evt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void touchVolume(String wname, int minx, int miny, int minz, int maxx, int maxy, int maxz, String reason) {
|
public void touchVolume(String wname, int minx, int miny, int minz, int maxx, int maxy, int maxz, String reason) {
|
||||||
|
|
@ -1410,16 +1411,20 @@ public class MapManager {
|
||||||
* Process touch events
|
* Process touch events
|
||||||
*/
|
*/
|
||||||
private void processTouchEvents() {
|
private void processTouchEvents() {
|
||||||
TreeSet<TouchEvent> te = null;
|
ArrayList<TouchEvent> te = null;
|
||||||
LinkedList<TouchVolumeEvent> tve = null;
|
ArrayList<TouchVolumeEvent> tve = null;
|
||||||
synchronized(touch_lock) {
|
|
||||||
if(touch_events.isEmpty() == false) {
|
if(touch_events.isEmpty() == false) {
|
||||||
te = touch_events;
|
te = new ArrayList<TouchEvent>(touch_events.keySet());
|
||||||
touch_events = new TreeSet<TouchEvent>();
|
for(int i = 0; i < te.size(); i++) {
|
||||||
|
touch_events.remove(te.get(i));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized(touch_lock) {
|
||||||
if(touch_volume_events.isEmpty() == false) {
|
if(touch_volume_events.isEmpty() == false) {
|
||||||
tve = touch_volume_events;
|
tve = new ArrayList<TouchVolumeEvent>(touch_volume_events);
|
||||||
touch_volume_events = new LinkedList<TouchVolumeEvent>();
|
touch_volume_events.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
DynmapWorld world = null;
|
DynmapWorld world = null;
|
||||||
|
|
|
||||||
|
|
@ -61,7 +61,7 @@ public class SnapshotCache {
|
||||||
snapcache.reverselookup.remove(rec.ref);
|
snapcache.reverselookup.remove(rec.ref);
|
||||||
rec.ref.clear();
|
rec.ref.clear();
|
||||||
}
|
}
|
||||||
processRefQueue();
|
//processRefQueue();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Invalidate cached snapshot, if in cache
|
* Invalidate cached snapshot, if in cache
|
||||||
|
|
@ -77,7 +77,7 @@ public class SnapshotCache {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processRefQueue();
|
//processRefQueue();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Look for chunk snapshot in cache
|
* Look for chunk snapshot in cache
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue