Basic reformat, hit once, hope never again
This commit is contained in:
+103
-102
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.me.cache;
|
||||
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
@@ -37,37 +38,38 @@ import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
import appeng.parts.p2p.PartP2PTunnelME;
|
||||
|
||||
|
||||
public class P2PCache implements IGridCache
|
||||
{
|
||||
|
||||
final IGrid myGrid;
|
||||
final private HashMap<Long, PartP2PTunnel> inputs = new HashMap<Long, PartP2PTunnel>();
|
||||
final private Multimap<Long, PartP2PTunnel> outputs = LinkedHashMultimap.create();
|
||||
final private TunnelCollection NullColl = new TunnelCollection<PartP2PTunnel>( null, null );
|
||||
|
||||
final IGrid myGrid;
|
||||
|
||||
public P2PCache(IGrid g) {
|
||||
public P2PCache( IGrid g )
|
||||
{
|
||||
this.myGrid = g;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete(MENetworkBootingStatusChange bootStatus)
|
||||
public void bootComplete( MENetworkBootingStatusChange bootStatus )
|
||||
{
|
||||
ITickManager tm = this.myGrid.getCache( ITickManager.class );
|
||||
for (PartP2PTunnel me : this.inputs.values())
|
||||
for( PartP2PTunnel me : this.inputs.values() )
|
||||
{
|
||||
if ( me instanceof PartP2PTunnelME )
|
||||
if( me instanceof PartP2PTunnelME )
|
||||
tm.wakeDevice( me.getGridNode() );
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootComplete(MENetworkPowerStatusChange power)
|
||||
public void bootComplete( MENetworkPowerStatusChange power )
|
||||
{
|
||||
ITickManager tm = this.myGrid.getCache( ITickManager.class );
|
||||
for (PartP2PTunnel me : this.inputs.values())
|
||||
for( PartP2PTunnel me : this.inputs.values() )
|
||||
{
|
||||
if ( me instanceof PartP2PTunnelME )
|
||||
if( me instanceof PartP2PTunnelME )
|
||||
tm.wakeDevice( me.getGridNode() );
|
||||
}
|
||||
}
|
||||
@@ -78,17 +80,101 @@ public class P2PCache implements IGridCache
|
||||
|
||||
}
|
||||
|
||||
public void updateFreq(PartP2PTunnel t, long NewFreq)
|
||||
@Override
|
||||
public void removeNode( IGridNode node, IGridHost machine )
|
||||
{
|
||||
if ( this.outputs.containsValue( t ) )
|
||||
if( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
return;
|
||||
}
|
||||
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq
|
||||
// );
|
||||
|
||||
if( t.output )
|
||||
this.outputs.remove( t.freq, t );
|
||||
else
|
||||
this.inputs.remove( t.freq );
|
||||
|
||||
this.updateTunnel( t.freq, !t.output, false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode( IGridNode node, IGridHost machine )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
return;
|
||||
}
|
||||
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq
|
||||
// );
|
||||
|
||||
if( t.output )
|
||||
this.outputs.put( t.freq, t );
|
||||
else
|
||||
this.inputs.put( t.freq, t );
|
||||
|
||||
this.updateTunnel( t.freq, !t.output, false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSplit( IGridStorage storageB )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin( IGridStorage storageB )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateGridStorage( IGridStorage storage )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void updateTunnel( long freq, boolean updateOutputs, boolean configChange )
|
||||
{
|
||||
for( PartP2PTunnel p : this.outputs.get( freq ) )
|
||||
{
|
||||
if( configChange )
|
||||
p.onTunnelConfigChange();
|
||||
p.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
PartP2PTunnel in = this.inputs.get( freq );
|
||||
if( in != null )
|
||||
{
|
||||
if( configChange )
|
||||
in.onTunnelConfigChange();
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateFreq( PartP2PTunnel t, long NewFreq )
|
||||
{
|
||||
if( this.outputs.containsValue( t ) )
|
||||
this.outputs.remove( t.freq, t );
|
||||
|
||||
if ( this.inputs.containsValue( t ) )
|
||||
if( this.inputs.containsValue( t ) )
|
||||
this.inputs.remove( t.freq );
|
||||
|
||||
t.freq = NewFreq;
|
||||
|
||||
if ( t.output )
|
||||
if( t.output )
|
||||
this.outputs.put( t.freq, t );
|
||||
else
|
||||
this.inputs.put( t.freq, t );
|
||||
@@ -99,106 +185,21 @@ public class P2PCache implements IGridCache
|
||||
this.updateTunnel( t.freq, !t.output, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(IGridNode node, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if ( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
return;
|
||||
}
|
||||
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq
|
||||
// );
|
||||
|
||||
if ( t.output )
|
||||
this.outputs.put( t.freq, t );
|
||||
else
|
||||
this.inputs.put( t.freq, t );
|
||||
|
||||
this.updateTunnel( t.freq, !t.output, false );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode(IGridNode node, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnel )
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnelME )
|
||||
{
|
||||
if ( !node.hasFlag( GridFlags.REQUIRE_CHANNEL ) )
|
||||
return;
|
||||
}
|
||||
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
// AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq
|
||||
// );
|
||||
|
||||
if ( t.output )
|
||||
this.outputs.remove( t.freq, t );
|
||||
else
|
||||
this.inputs.remove( t.freq );
|
||||
|
||||
this.updateTunnel( t.freq, !t.output, false );
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTunnel(long freq, boolean updateOutputs, boolean configChange)
|
||||
{
|
||||
for (PartP2PTunnel p : this.outputs.get( freq ))
|
||||
{
|
||||
if ( configChange )
|
||||
p.onTunnelConfigChange();
|
||||
p.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
PartP2PTunnel in = this.inputs.get( freq );
|
||||
if ( in != null )
|
||||
{
|
||||
if ( configChange )
|
||||
in.onTunnelConfigChange();
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
}
|
||||
|
||||
public TunnelCollection<PartP2PTunnel> getOutputs(long freq, Class<? extends PartP2PTunnel> c)
|
||||
public TunnelCollection<PartP2PTunnel> getOutputs( long freq, Class<? extends PartP2PTunnel> c )
|
||||
{
|
||||
PartP2PTunnel in = this.inputs.get( freq );
|
||||
if ( in == null )
|
||||
if( in == null )
|
||||
return this.NullColl;
|
||||
|
||||
TunnelCollection<PartP2PTunnel> out = this.inputs.get( freq ).getCollection( this.outputs.get( freq ), c );
|
||||
if ( out == null )
|
||||
if( out == null )
|
||||
return this.NullColl;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
public PartP2PTunnel getInput(long freq)
|
||||
public PartP2PTunnel getInput( long freq )
|
||||
{
|
||||
return this.inputs.get( freq );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSplit(IGridStorage storageB)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onJoin(IGridStorage storageB)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populateGridStorage(IGridStorage storage)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user