Changed TreeMap to a threadsafe implementation

This commit is contained in:
yueh
2014-10-09 16:37:25 +02:00
parent 97758d6f61
commit fdd1a362d6
2 changed files with 8 additions and 6 deletions
@@ -5,9 +5,10 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.NavigableMap; import java.util.NavigableMap;
import java.util.TreeMap; import java.util.concurrent.ConcurrentSkipListMap;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import appeng.api.AEApi; import appeng.api.AEApi;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
@@ -49,7 +50,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
final InventoryAdaptor adaptor; final InventoryAdaptor adaptor;
final TreeMap<Integer, CachedItemStack> memory; private final NavigableMap<Integer, CachedItemStack> memory;
final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList(); final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>(); final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object>();
@@ -71,7 +72,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>
public MEMonitorIInventory(InventoryAdaptor adaptor) public MEMonitorIInventory(InventoryAdaptor adaptor)
{ {
this.adaptor = adaptor; this.adaptor = adaptor;
memory = new TreeMap<Integer, CachedItemStack>(); memory = new ConcurrentSkipListMap<Integer, CachedItemStack>();
} }
@Override @Override
@@ -5,7 +5,8 @@ import java.util.Comparator;
import java.util.Iterator; import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import appeng.api.config.AccessRestriction; import appeng.api.config.AccessRestriction;
import appeng.api.config.Actionable; import appeng.api.config.Actionable;
@@ -40,12 +41,12 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
final SecurityCache security; final SecurityCache security;
// final TreeMultimap<Integer, IMEInventoryHandler<T>> priorityInventory; // final TreeMultimap<Integer, IMEInventoryHandler<T>> priorityInventory;
final TreeMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory; private final NavigableMap<Integer, List<IMEInventoryHandler<T>>> priorityInventory;
public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) { public NetworkInventoryHandler(StorageChannel chan, SecurityCache security) {
myChannel = chan; myChannel = chan;
this.security = security; this.security = security;
priorityInventory = new TreeMap<Integer, List<IMEInventoryHandler<T>>>( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter ); priorityInventory = new ConcurrentSkipListMap<Integer, List<IMEInventoryHandler<T>>>( prioritySorter ); // TreeMultimap.create( prioritySorter, hashSorter );
} }
public void addNewStorage(IMEInventoryHandler<T> h) public void addNewStorage(IMEInventoryHandler<T> h)