Buffer changes from Interest List.
This commit is contained in:
parent
a73109b62e
commit
d807812bc8
5 changed files with 334 additions and 246 deletions
|
@ -199,16 +199,14 @@ public class Grid implements IGrid
|
|||
}
|
||||
|
||||
public void update()
|
||||
{
|
||||
// are ther any nodes left?
|
||||
if ( pivot != null )
|
||||
{
|
||||
for (IGridCache gc : caches.values())
|
||||
{
|
||||
// are there any nodes left?
|
||||
if ( pivot != null )
|
||||
gc.onUpdateTick();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Iterable<GridCacheWrapper> getCacheWrappers()
|
||||
{
|
||||
|
|
4
me/cache/GridStorageCache.java
vendored
4
me/cache/GridStorageCache.java
vendored
|
@ -25,6 +25,7 @@ import appeng.api.storage.data.IAEFluidStack;
|
|||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.me.helpers.StorageInterestManager;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
import appeng.me.storage.NetworkInventoryHandler;
|
||||
|
||||
|
@ -34,7 +35,8 @@ import com.google.common.collect.SetMultimap;
|
|||
public class GridStorageCache implements IStorageGrid
|
||||
{
|
||||
|
||||
public SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
final private SetMultimap<IAEStack, ItemWatcher> interests = HashMultimap.create();
|
||||
final public StorageInterestManager interestManager = new StorageInterestManager( interests );
|
||||
|
||||
final HashSet<ICellContainer> activeCellContainers = new HashSet();
|
||||
final HashSet<ICellContainer> inactiveCellContainers = new HashSet();
|
||||
|
|
8
me/cache/NetworkMonitor.java
vendored
8
me/cache/NetworkMonitor.java
vendored
|
@ -59,9 +59,9 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||
sendEvent = true;
|
||||
super.postChange( diff, src );
|
||||
|
||||
if ( myGridCache.interests.containsKey( diff ) )
|
||||
if ( myGridCache.interestManager.containsKey( diff ) )
|
||||
{
|
||||
Set<ItemWatcher> list = myGridCache.interests.get( diff );
|
||||
Set<ItemWatcher> list = myGridCache.interestManager.get( diff );
|
||||
if ( !list.isEmpty() )
|
||||
{
|
||||
IItemList<T> myStorageList = getStorageList();
|
||||
|
@ -73,8 +73,12 @@ public class NetworkMonitor<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||
fullStack.setStackSize( 0 );
|
||||
}
|
||||
|
||||
myGridCache.interestManager.enableTransactions();
|
||||
|
||||
for (ItemWatcher iw : list)
|
||||
iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() );
|
||||
|
||||
myGridCache.interestManager.disableTransactions();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
84
me/helpers/StorageInterestManager.java
Normal file
84
me/helpers/StorageInterestManager.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
package appeng.me.helpers;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.me.storage.ItemWatcher;
|
||||
|
||||
import com.google.common.collect.SetMultimap;
|
||||
|
||||
public class StorageInterestManager {
|
||||
|
||||
class SavedTransactions {
|
||||
public final boolean put;
|
||||
public final IAEStack stack;
|
||||
public final ItemWatcher iw;
|
||||
|
||||
public SavedTransactions( boolean putOperation, IAEStack myStack, ItemWatcher watcher )
|
||||
{
|
||||
put = putOperation;
|
||||
stack = myStack;
|
||||
iw = watcher;
|
||||
}
|
||||
};
|
||||
|
||||
private final SetMultimap<IAEStack, ItemWatcher> container;
|
||||
private LinkedList<SavedTransactions> transactions = null;
|
||||
|
||||
public StorageInterestManager(SetMultimap<IAEStack, ItemWatcher> interests) {
|
||||
container = interests;
|
||||
}
|
||||
|
||||
public void enableTransactions()
|
||||
{
|
||||
transactions = new LinkedList();
|
||||
}
|
||||
|
||||
public void disableTransactions()
|
||||
{
|
||||
LinkedList<SavedTransactions> myActions = transactions;
|
||||
transactions = null;
|
||||
|
||||
for ( SavedTransactions t : myActions )
|
||||
{
|
||||
if ( t.put )
|
||||
put( t.stack, t.iw );
|
||||
else
|
||||
remove( t.stack, t.iw );
|
||||
}
|
||||
}
|
||||
|
||||
public boolean containsKey( IAEStack stack )
|
||||
{
|
||||
return container.containsKey( stack );
|
||||
}
|
||||
|
||||
public Set<ItemWatcher> get( IAEStack stack )
|
||||
{
|
||||
return container.get( stack );
|
||||
}
|
||||
|
||||
public boolean put( IAEStack stack, ItemWatcher iw )
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.put( stack, iw );
|
||||
}
|
||||
|
||||
public boolean remove( IAEStack stack, ItemWatcher iw )
|
||||
{
|
||||
if ( transactions != null )
|
||||
{
|
||||
transactions.add( new SavedTransactions( true, stack, iw ) );
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return container.remove( stack, iw );
|
||||
}
|
||||
|
||||
}
|
|
@ -42,7 +42,7 @@ public class ItemWatcher implements IStackWatcher
|
|||
@Override
|
||||
public void remove()
|
||||
{
|
||||
gsc.interests.remove( myLast, watcher );
|
||||
gsc.interestManager.remove( myLast, watcher );
|
||||
interestIterator.remove();
|
||||
}
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ItemWatcher implements IStackWatcher
|
|||
if ( myInterests.contains( e ) )
|
||||
return false;
|
||||
|
||||
return myInterests.add( e.copy() ) && gsc.interests.put( e, this );
|
||||
return myInterests.add( e.copy() ) && gsc.interestManager.put( e, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -88,7 +88,7 @@ public class ItemWatcher implements IStackWatcher
|
|||
Iterator<IAEStack> i = myInterests.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
gsc.interests.remove( i.next(), this );
|
||||
gsc.interestManager.remove( i.next(), this );
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ public class ItemWatcher implements IStackWatcher
|
|||
@Override
|
||||
public boolean remove(Object o)
|
||||
{
|
||||
return myInterests.remove( o ) && gsc.interests.remove( o, this );
|
||||
return myInterests.remove( o ) && gsc.interestManager.remove( (IAEStack)o, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue