Merge pull request #277 from yueh/fix-276

Changed TreeMap to a threadsafe implementation
This commit is contained in:
FireBall1725 2014-10-13 08:32:55 -04:00
commit 88570117bc
3 changed files with 44 additions and 32 deletions

View file

@ -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

View file

@ -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)

View file

@ -1,20 +1,30 @@
package appeng.util.item; package appeng.util.item;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import com.google.common.collect.Lists;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import appeng.api.config.FuzzyMode; import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEFluidStack; import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack; import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList; import appeng.api.storage.data.IItemList;
import com.google.common.collect.Lists;
public final class ItemList<StackType extends IAEStack> implements IItemList<StackType> public final class ItemList<StackType extends IAEStack> implements IItemList<StackType>
{ {
private final TreeMap<StackType, StackType> records = new TreeMap<StackType, StackType>(); private final NavigableMap<StackType, StackType> records = new ConcurrentSkipListMap<StackType, StackType>();
private final Class<? extends IAEStack> clz; private final Class<? extends IAEStack> clz;
// private int currentPriority = Integer.MIN_VALUE; // private int currentPriority = Integer.MIN_VALUE;