n-to-n p2p

network monitor checks nesting by action source
This commit is contained in:
PrototypeTrousers
2021-10-28 23:49:16 -03:00
parent 3db8d0185f
commit 5e21101619
12 changed files with 268 additions and 96 deletions
+19 -20
View File
@@ -47,8 +47,8 @@ import java.util.Map.Entry;
public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
{
@Nonnull
private static final Deque<NetworkMonitor<?>> GLOBAL_DEPTH = Queues.newArrayDeque();
private static final Set<NetworkMonitor<?>> MONITORS = new HashSet<>();
private static final Set<NetworkMonitor<?>> NESTED_MONITORS = new HashSet<>();
private static final HashMap<IActionSource, Set<NetworkMonitor<?>>> sourceSetHashMap = new HashMap<>();
protected static boolean nested = false;
protected boolean isNested = false;
@@ -137,17 +137,16 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
return 0;
}
public long incGridCurrentCount(long count)
public void incGridCurrentCount( long count )
{
if( myChannel == AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ) )
{
return gridItemCount += count;
gridItemCount += count;
}
else if( myChannel == AEApi.instance().storage().getStorageChannel( IFluidStorageChannel.class ) )
{
return gridFluidCount += count;
gridFluidCount += count;
}
return 0;
}
@Nonnull
@@ -230,15 +229,16 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
protected void postChange( final boolean add, final Iterable<T> changes, final IActionSource src )
{
if( MONITORS.contains( this ) )
if( sourceSetHashMap.get( src ) != null && sourceSetHashMap.get( src ).contains( this ) )
{
NESTED_MONITORS.add( this );
nested = true;
return;
}
MONITORS.add( this );
GLOBAL_DEPTH.push( this );
sourceSetHashMap.putIfAbsent( src, new HashSet<>() );
sourceSetHashMap.get( src ).add( this );
this.sendEvent = true;
@@ -282,21 +282,20 @@ public class NetworkMonitor<T extends IAEStack<T>> implements IMEMonitor<T>
this.notifyListenersOfChange( changes, src );
final NetworkMonitor<?> last = GLOBAL_DEPTH.pop();
if( GLOBAL_DEPTH.isEmpty() )
sourceSetHashMap.get( src ).remove( this );
if( sourceSetHashMap.get( src ).isEmpty() )
{
for( NetworkMonitor<?> nm : MONITORS )
sourceSetHashMap.remove( src );
}
if( sourceSetHashMap.isEmpty() )
{
for( NetworkMonitor<?> nm : NESTED_MONITORS )
{
nm.setupForceUpdate();
}
nested = false;
MONITORS.clear();
}
if( last != this )
{
throw new IllegalStateException( "Invalid Access to Networked Storage API detected." );
NESTED_MONITORS.clear();
}
}