From 8363aa4310d6bc162fce07b34d1be4e1d6af947c Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Wed, 10 Sep 2014 17:51:56 -0500 Subject: [PATCH] Rolled back "Replaced Network Change Event Pipeline, should be more effective." it broke things. --- me/cache/NetworkMonitor.java | 99 ++++++++++++++++++------------------ 1 file changed, 49 insertions(+), 50 deletions(-) diff --git a/me/cache/NetworkMonitor.java b/me/cache/NetworkMonitor.java index 00dcd454..dfccffc9 100644 --- a/me/cache/NetworkMonitor.java +++ b/me/cache/NetworkMonitor.java @@ -1,11 +1,14 @@ package appeng.me.cache; +import java.util.Iterator; import java.util.LinkedList; +import java.util.Map.Entry; import java.util.Set; import appeng.api.networking.events.MENetworkStorageEvent; import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.MEMonitorHandler; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEStack; @@ -23,7 +26,18 @@ public class NetworkMonitor> extends MEMonitorHandler public void forceUpdate() { hasChanged = true; - sendEvent = true; + + Iterator, Object>> i = getListeners(); + while (i.hasNext()) + { + Entry, Object> o = i.next(); + IMEMonitorHandlerReceiver recv = o.getKey(); + + if ( recv.isValid( o.getValue() ) ) + recv.onListUpdate(); + else + i.remove(); + } } public NetworkMonitor(GridStorageCache cache, StorageChannel chan) { @@ -32,27 +46,45 @@ public class NetworkMonitor> extends MEMonitorHandler myChannel = chan; } - final private LinkedList> changes = new LinkedList(); - - class ChangeRecord> - { - - public ChangeRecord(G diff2, BaseActionSource src2) { - diff = diff2; - src = src2; - } - - G diff; - BaseActionSource src; - - }; + final static public LinkedList depth = new LinkedList(); @Override protected void postChange(T diff, BaseActionSource src) { + if ( depth.contains( this ) ) + return; + + depth.push( this ); + sendEvent = true; - hasChanged = true; - changes.add( new ChangeRecord( diff, src ) ); + super.postChange( diff, src ); + + if ( myGridCache.interestManager.containsKey( diff ) ) + { + Set list = myGridCache.interestManager.get( diff ); + if ( !list.isEmpty() ) + { + IItemList myStorageList = getStorageList(); + + IAEStack fullStack = myStorageList.findPrecise( diff ); + if ( fullStack == null ) + { + fullStack = diff.copy(); + fullStack.setStackSize( 0 ); + } + + myGridCache.interestManager.enableTransactions(); + + for (ItemWatcher iw : list) + iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() ); + + myGridCache.interestManager.disableTransactions(); + } + } + + Object last = depth.pop(); + if ( last != this ) + throw new RuntimeException( "Invalid Access to Networked Storage API detected." ); } public void onTick() @@ -60,39 +92,6 @@ public class NetworkMonitor> extends MEMonitorHandler if ( sendEvent ) { sendEvent = false; - - ChangeRecord cr; - while ( (cr=changes.poll()) != null ) - { - T diff = cr.diff; - BaseActionSource src = cr.src; - - IItemList myStorageList = getStorageList(); - - postChangeToListeners( diff, src ); - - if ( myGridCache.interestManager.containsKey( diff ) ) - { - Set list = myGridCache.interestManager.get( diff ); - if ( !list.isEmpty() ) - { - IAEStack fullStack = myStorageList.findPrecise( diff ); - if ( fullStack == null ) - { - fullStack = diff.copy(); - fullStack.setStackSize( 0 ); - } - - myGridCache.interestManager.enableTransactions(); - - for (ItemWatcher iw : list) - iw.getHost().onStackChange( myStorageList, fullStack, diff, src, getChannel() ); - - myGridCache.interestManager.disableTransactions(); - } - } - } - myGridCache.myGrid.postEvent( new MENetworkStorageEvent( this, myChannel ) ); } }