Err too much.
This commit is contained in:
Vendored
+63
-33
@@ -1,6 +1,5 @@
|
||||
package appeng.me.cache;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import appeng.api.networking.IGrid;
|
||||
@@ -8,7 +7,9 @@ import appeng.api.networking.IGridCache;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.IGridStorage;
|
||||
import appeng.parts.misc.PartP2PTunnel;
|
||||
import appeng.core.AELog;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.p2p.PartP2PTunnel;
|
||||
|
||||
import com.google.common.collect.LinkedHashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
@@ -16,8 +17,9 @@ import com.google.common.collect.Multimap;
|
||||
public class P2PCache implements IGridCache
|
||||
{
|
||||
|
||||
private HashMap<Long, PartP2PTunnel> inputs = new HashMap();
|
||||
private Multimap<Long, PartP2PTunnel> Tunnels = LinkedHashMultimap.create();
|
||||
final private HashMap<Long, PartP2PTunnel> inputs = new HashMap();
|
||||
final private Multimap<Long, PartP2PTunnel> outputs = LinkedHashMultimap.create();
|
||||
final private TunnelCollection NullColl = new TunnelCollection<PartP2PTunnel>( null, null );
|
||||
|
||||
final IGrid myGrid;
|
||||
|
||||
@@ -25,50 +27,78 @@ public class P2PCache implements IGridCache
|
||||
myGrid = g;
|
||||
}
|
||||
|
||||
public void updateFreq(PartP2PTunnel t, long NewFreq)
|
||||
{
|
||||
outputs.remove( t.freq, t );
|
||||
inputs.remove( t.freq );
|
||||
|
||||
t.freq = NewFreq;
|
||||
|
||||
if ( t.output )
|
||||
outputs.put( t.freq, t );
|
||||
else
|
||||
inputs.put( t.freq, t );
|
||||
|
||||
AELog.info( "update-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
updateTunnel( t.freq, t.output );
|
||||
updateTunnel( t.freq, !t.output );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addNode(IGrid grid, IGridNode node, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnel )
|
||||
reset( grid );
|
||||
{
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
AELog.info( "add-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
|
||||
if ( t.output )
|
||||
outputs.put( t.freq, t );
|
||||
else
|
||||
inputs.put( t.freq, t );
|
||||
|
||||
updateTunnel( t.freq, !t.output );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeNode(IGrid grid, IGridNode node, IGridHost machine)
|
||||
{
|
||||
if ( machine instanceof PartP2PTunnel )
|
||||
reset( grid );
|
||||
}
|
||||
|
||||
public void reset(IGrid grid)
|
||||
{
|
||||
|
||||
Tunnels.clear();
|
||||
inputs.clear();
|
||||
|
||||
for (IGridNode n : grid.getMachines( PartP2PTunnel.class ))
|
||||
{
|
||||
PartP2PTunnel p = (PartP2PTunnel) n.getMachine();
|
||||
if ( p.freq > 0 )
|
||||
{
|
||||
if ( p.output )
|
||||
Tunnels.put( p.freq, p );
|
||||
else if ( inputs.containsKey( p.freq ) )
|
||||
p.output = true;
|
||||
else
|
||||
inputs.put( p.freq, p );
|
||||
}
|
||||
PartP2PTunnel t = (PartP2PTunnel) machine;
|
||||
AELog.info( "rmv-" + (t.output ? "output: " : "input: ") + t.freq );
|
||||
|
||||
if ( t.output )
|
||||
outputs.remove( t.freq, t );
|
||||
else
|
||||
inputs.remove( t.freq );
|
||||
|
||||
updateTunnel( t.freq, !t.output );
|
||||
}
|
||||
|
||||
for (PartP2PTunnel p : inputs.values())
|
||||
p.onChange();
|
||||
|
||||
for (PartP2PTunnel p : Tunnels.values())
|
||||
p.onChange();
|
||||
}
|
||||
|
||||
public Collection<PartP2PTunnel> getOutputs(long freq)
|
||||
private void updateTunnel(long freq, boolean updateOutputs)
|
||||
{
|
||||
return Tunnels.get( freq );
|
||||
if ( updateOutputs )
|
||||
{
|
||||
for (PartP2PTunnel p : outputs.values())
|
||||
p.onChange();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (PartP2PTunnel p : inputs.values())
|
||||
p.onChange();
|
||||
}
|
||||
}
|
||||
|
||||
public TunnelCollection<PartP2PTunnel> getOutputs(long freq, Class<? extends PartP2PTunnel> c)
|
||||
{
|
||||
PartP2PTunnel in = inputs.get( freq );
|
||||
if ( in == null )
|
||||
return NullColl;
|
||||
|
||||
return inputs.get( freq ).getCollection( outputs.get( freq ) );
|
||||
}
|
||||
|
||||
public PartP2PTunnel getInput(long freq)
|
||||
|
||||
Reference in New Issue
Block a user