Applied-Energistics-2-tiler.../src/main/java/appeng/me/GridNode.java

707 lines
15 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-09-24 02:26:27 +02:00
package appeng.me;
2014-09-24 02:26:27 +02:00
import java.util.Collections;
import java.util.Comparator;
import java.util.Deque;
2014-09-24 02:26:27 +02:00
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.Callable;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
2014-09-24 02:26:27 +02:00
import net.minecraft.world.World;
import appeng.api.exceptions.FailedConnection;
import appeng.api.networking.GridFlags;
import appeng.api.networking.GridNotification;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridBlock;
import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridConnection;
import appeng.api.networking.IGridConnectionVisitor;
2014-09-24 02:26:27 +02:00
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.networking.IGridVisitor;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.pathing.IPathingGrid;
import appeng.api.util.AEColor;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
2014-09-24 02:26:27 +02:00
import appeng.api.util.DimensionalCoord;
import appeng.api.util.IReadOnlyCollection;
import appeng.core.WorldSettings;
import appeng.hooks.TickHandler;
import appeng.me.pathfinding.IPathItem;
import appeng.util.ReadOnlyCollection;
2014-09-24 02:26:27 +02:00
public class GridNode implements IGridNode, IPathItem
{
2015-01-01 22:13:10 +01:00
private static final MENetworkChannelsChanged EVENT = new MENetworkChannelsChanged();
private static final int[] CHANNEL_COUNT = new int[] { 0, 8, 32 };
2014-09-24 02:26:27 +02:00
private final List<IGridConnection> connections = new LinkedList<IGridConnection>();
private final IGridBlock gridProxy;
// old power draw, used to diff
public double previousDraw = 0.0;
public long lastSecurityKey = -1;
public int playerID = -1;
private GridStorage myStorage = null;
private Grid myGrid;
private Object visitorIterationNumber = null;
2014-09-24 02:26:27 +02:00
// connection criteria
private int compressedData = 0;
private int usedChannels = 0;
private int lastUsedChannels = 0;
2014-09-24 02:26:27 +02:00
public GridNode( IGridBlock what )
2014-09-24 02:26:27 +02:00
{
this.gridProxy = what;
2014-09-24 02:26:27 +02:00
}
public IGridBlock getGridProxy()
2014-09-24 02:26:27 +02:00
{
return this.gridProxy;
2014-09-24 02:26:27 +02:00
}
public Grid getMyGrid()
2014-09-24 02:26:27 +02:00
{
return this.myGrid;
2014-09-24 02:26:27 +02:00
}
public int usedChannels()
2014-09-24 02:26:27 +02:00
{
return this.lastUsedChannels;
2014-09-24 02:26:27 +02:00
}
public Class<? extends IGridHost> getMachineClass()
2014-09-24 02:26:27 +02:00
{
return this.getMachine().getClass();
2014-09-24 02:26:27 +02:00
}
public void addConnection( IGridConnection gridConnection )
2014-09-24 02:26:27 +02:00
{
this.connections.add( gridConnection );
if( gridConnection.hasDirection() )
2015-04-29 02:30:53 +02:00
{
this.gridProxy.onGridNotification( GridNotification.ConnectionsChanged );
2015-04-29 02:30:53 +02:00
}
final IGridNode gn = this;
2014-09-24 02:26:27 +02:00
Collections.sort( this.connections, new ConnectionComparator( gn ) );
2014-09-24 02:26:27 +02:00
}
public void removeConnection( IGridConnection gridConnection )
2014-09-24 02:26:27 +02:00
{
this.connections.remove( gridConnection );
if( gridConnection.hasDirection() )
2015-04-29 02:30:53 +02:00
{
this.gridProxy.onGridNotification( GridNotification.ConnectionsChanged );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
public boolean hasConnection( IGridNode otherSide )
2014-09-24 02:26:27 +02:00
{
for( IGridConnection gc : this.connections )
2014-09-24 02:26:27 +02:00
{
if( gc.a() == otherSide || gc.b() == otherSide )
2015-04-29 02:30:53 +02:00
{
return true;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
return false;
2014-09-24 02:26:27 +02:00
}
public void validateGrid()
2014-09-24 02:26:27 +02:00
{
GridSplitDetector gsd = new GridSplitDetector( this.getInternalGrid().getPivot() );
this.beginVisit( gsd );
if( !gsd.pivotFound )
{
IGridVisitor gp = new GridPropagator( new Grid( this ) );
this.beginVisit( gp );
}
2014-09-24 02:26:27 +02:00
}
public Grid getInternalGrid()
2014-09-24 02:26:27 +02:00
{
if( this.myGrid == null )
2015-04-29 02:30:53 +02:00
{
this.myGrid = new Grid( this );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
return this.myGrid;
2014-09-24 02:26:27 +02:00
}
@Override
public void beginVisit( IGridVisitor g )
2014-09-24 02:26:27 +02:00
{
Object tracker = new Object();
2014-09-28 22:20:14 +02:00
LinkedList<GridNode> nextRun = new LinkedList<GridNode>();
2014-09-24 02:26:27 +02:00
nextRun.add( this );
this.visitorIterationNumber = tracker;
2014-09-24 02:26:27 +02:00
if( g instanceof IGridConnectionVisitor )
2014-09-24 02:26:27 +02:00
{
2014-09-28 22:20:14 +02:00
LinkedList<IGridConnection> nextConn = new LinkedList<IGridConnection>();
IGridConnectionVisitor gcv = (IGridConnectionVisitor) g;
2014-09-24 02:26:27 +02:00
while( !nextRun.isEmpty() )
2014-09-24 02:26:27 +02:00
{
while( !nextConn.isEmpty() )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
gcv.visitConnection( nextConn.poll() );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2015-05-09 00:04:44 +02:00
Iterable<GridNode> thisRun = nextRun;
2014-09-28 22:20:14 +02:00
nextRun = new LinkedList<GridNode>();
2014-09-24 02:26:27 +02:00
for( GridNode n : thisRun )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
n.visitorConnection( tracker, g, nextRun, nextConn );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
}
else
{
while( !nextRun.isEmpty() )
2014-09-24 02:26:27 +02:00
{
2015-05-09 00:04:44 +02:00
Iterable<GridNode> thisRun = nextRun;
2014-09-28 22:20:14 +02:00
nextRun = new LinkedList<GridNode>();
2014-09-24 02:26:27 +02:00
for( GridNode n : thisRun )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
n.visitorNode( tracker, g, nextRun );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
}
}
@Override
public void updateState()
2014-09-24 02:26:27 +02:00
{
EnumSet<GridFlags> set = this.gridProxy.getFlags();
this.compressedData = set.contains( GridFlags.CANNOT_CARRY ) ? 0 : ( set.contains( GridFlags.DENSE_CAPACITY ) ? 2 : 1 );
this.compressedData |= ( this.gridProxy.getGridColor().ordinal() << 3 );
2015-06-16 02:44:59 +02:00
for( EnumFacing dir : this.gridProxy.getConnectableSides() )
2015-04-29 02:30:53 +02:00
{
this.compressedData |= ( 1 << ( dir.ordinal() + 8 ) );
2015-04-29 02:30:53 +02:00
}
this.FindConnections();
this.getInternalGrid();
}
@Override
public IGridHost getMachine()
{
return this.gridProxy.getMachine();
}
@Override
public IGrid getGrid()
{
return this.myGrid;
}
public void setGrid( Grid grid )
{
if( this.myGrid == grid )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
if( this.myGrid != null )
2014-09-24 02:26:27 +02:00
{
this.myGrid.remove( this );
if( this.myGrid.isEmpty() )
2014-09-24 02:26:27 +02:00
{
this.myGrid.saveState();
2014-09-24 02:26:27 +02:00
for( IGridCache c : grid.getCaches().values() )
2015-04-29 02:30:53 +02:00
{
c.onJoin( this.myGrid.getMyStorage() );
2015-04-29 02:30:53 +02:00
}
}
}
2014-09-24 02:26:27 +02:00
this.myGrid = grid;
this.myGrid.add( this );
}
2014-09-24 02:26:27 +02:00
@Override
public void destroy()
{
while( !this.connections.isEmpty() )
{
// not part of this network for real anymore.
if( this.connections.size() == 1 )
2015-04-29 02:30:53 +02:00
{
this.setGridStorage( null );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
IGridConnection c = this.connections.listIterator().next();
GridNode otherSide = (GridNode) c.getOtherSide( this );
otherSide.getInternalGrid().setPivot( otherSide );
c.destroy();
2014-09-24 02:26:27 +02:00
}
if( this.myGrid != null )
2015-04-29 02:30:53 +02:00
{
this.myGrid.remove( this );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
@Override
public World getWorld()
2014-09-24 02:26:27 +02:00
{
return this.gridProxy.getLocation().getWorld();
}
@Override
2015-06-16 02:44:59 +02:00
public EnumSet<AEPartLocation> getConnectedSides()
{
2015-06-16 02:44:59 +02:00
EnumSet<AEPartLocation> set = EnumSet.noneOf( AEPartLocation.class );
for( IGridConnection gc : this.connections )
2015-04-29 02:30:53 +02:00
{
set.add( gc.getDirection( this ) );
2015-04-29 02:30:53 +02:00
}
return set;
}
@Override
public IReadOnlyCollection<IGridConnection> getConnections()
{
return new ReadOnlyCollection<IGridConnection>( this.connections );
}
@Override
public IGridBlock getGridBlock()
{
return this.gridProxy;
}
@Override
public boolean isActive()
{
IGrid g = this.getGrid();
if( g != null )
2014-09-24 02:26:27 +02:00
{
IPathingGrid pg = g.getCache( IPathingGrid.class );
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
return this.meetsChannelRequirements() && eg.isNetworkPowered() && !pg.isNetworkBooting();
}
return false;
}
2014-09-24 02:26:27 +02:00
@Override
public void loadFromNBT( String name, NBTTagCompound nodeData )
{
if( this.myGrid == null )
{
NBTTagCompound node = nodeData.getCompoundTag( name );
this.playerID = node.getInteger( "p" );
this.lastSecurityKey = node.getLong( "k" );
this.setGridStorage( WorldSettings.getInstance().getGridStorage( node.getLong( "g" ) ) );
}
else
2015-04-29 02:30:53 +02:00
{
throw new IllegalStateException( "Loading data after part of a grid, this is invalid." );
2015-04-29 02:30:53 +02:00
}
}
2014-09-24 02:26:27 +02:00
@Override
public void saveToNBT( String name, NBTTagCompound nodeData )
{
if( this.myStorage != null )
{
NBTTagCompound node = new NBTTagCompound();
2014-09-24 02:26:27 +02:00
node.setInteger( "p", this.playerID );
node.setLong( "k", this.lastSecurityKey );
node.setLong( "g", this.myStorage.getID() );
nodeData.setTag( name, node );
2014-09-24 02:26:27 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
nodeData.removeTag( name );
2015-04-29 02:30:53 +02:00
}
}
@Override
public boolean meetsChannelRequirements()
{
return( !this.gridProxy.getFlags().contains( GridFlags.REQUIRE_CHANNEL ) || this.getUsedChannels() > 0 );
}
@Override
public boolean hasFlag( GridFlags flag )
{
return this.gridProxy.getFlags().contains( flag );
}
@Override
public int getPlayerID()
{
return this.playerID;
}
@Override
public void setPlayerID( int playerID )
{
if( playerID >= 0 )
2015-04-29 02:30:53 +02:00
{
this.playerID = playerID;
2015-04-29 02:30:53 +02:00
}
}
public int getUsedChannels()
{
return this.usedChannels;
2014-09-24 02:26:27 +02:00
}
public void FindConnections()
{
if( !this.gridProxy.isWorldAccessible() )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
2015-06-16 02:44:59 +02:00
EnumSet<AEPartLocation> newSecurityConnections = EnumSet.noneOf( AEPartLocation.class );
2014-09-24 02:26:27 +02:00
DimensionalCoord dc = this.gridProxy.getLocation();
2015-06-16 02:44:59 +02:00
for( AEPartLocation f : AEPartLocation.SIDE_LOCATIONS )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
IGridHost te = this.findGridHost( dc.getWorld(), dc.x + f.xOffset, dc.y + f.yOffset, dc.z + f.zOffset );
if( te != null )
2014-09-24 02:26:27 +02:00
{
GridNode node = (GridNode) te.getGridNode( f.getOpposite() );
if( node == null )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
continue;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
boolean isValidConnection = this.canConnect( node, f ) && node.canConnect( this, f.getOpposite() );
IGridConnection con = null; // find the connection for this
// direction..
for( IGridConnection c : this.getConnections() )
2014-09-24 02:26:27 +02:00
{
if( c.getDirection( this ) == f )
2014-09-24 02:26:27 +02:00
{
con = c;
break;
}
}
if( con != null )
2014-09-24 02:26:27 +02:00
{
2014-09-28 20:56:16 +02:00
IGridNode os = con.getOtherSide( this );
if( os == node )
2014-09-24 02:26:27 +02:00
{
// if this connection is no longer valid, destroy it.
if( !isValidConnection )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
con.destroy();
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
else
{
con.destroy();
// throw new GridException( "invalid state found, encountered connection to phantom block." );
}
}
else if( isValidConnection )
2014-09-24 02:26:27 +02:00
{
if( node.lastSecurityKey != -1 )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
newSecurityConnections.add( f );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
else
{
// construct a new connection between these two nodes.
try
{
new GridConnection( node, this, f.getOpposite() );
}
catch( FailedConnection e )
2014-09-24 02:26:27 +02:00
{
2015-01-01 22:13:10 +01:00
TickHandler.INSTANCE.addCallable( node.getWorld(), new MachineSecurityBreak( this ) );
2014-09-24 02:26:27 +02:00
return;
}
}
}
}
}
2015-06-16 02:44:59 +02:00
for( AEPartLocation f : newSecurityConnections )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
IGridHost te = this.findGridHost( dc.getWorld(), dc.x + f.xOffset, dc.y + f.yOffset, dc.z + f.zOffset );
if( te != null )
2014-09-24 02:26:27 +02:00
{
GridNode node = (GridNode) te.getGridNode( f.getOpposite() );
if( node == null )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
continue;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
// construct a new connection between these two nodes.
try
{
new GridConnection( node, this, f.getOpposite() );
}
catch( FailedConnection e )
2014-09-24 02:26:27 +02:00
{
2015-01-01 22:13:10 +01:00
TickHandler.INSTANCE.addCallable( node.getWorld(), new MachineSecurityBreak( this ) );
2014-09-24 02:26:27 +02:00
return;
}
}
}
}
private IGridHost findGridHost( World world, int x, int y, int z )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
BlockPos pos = new BlockPos(x,y,z);
if( world.isBlockLoaded( pos ) )
2014-09-24 02:26:27 +02:00
{
2015-06-16 02:44:59 +02:00
TileEntity te = world.getTileEntity( pos );
if( te instanceof IGridHost )
2015-04-29 02:30:53 +02:00
{
return (IGridHost) te;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
return null;
}
2015-06-16 02:44:59 +02:00
public boolean canConnect( GridNode from, AEPartLocation dir )
2014-09-24 02:26:27 +02:00
{
if( !this.isValidDirection( dir ) )
2015-04-29 02:30:53 +02:00
{
return false;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( !from.getColor().matches( this.getColor() ) )
2015-04-29 02:30:53 +02:00
{
return false;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
return true;
2014-09-24 02:26:27 +02:00
}
2015-06-16 02:44:59 +02:00
private boolean isValidDirection( AEPartLocation dir )
2014-09-24 02:26:27 +02:00
{
return ( this.compressedData & ( 1 << ( 8 + dir.ordinal() ) ) ) > 0;
2014-09-24 02:26:27 +02:00
}
public AEColor getColor()
2014-09-24 02:26:27 +02:00
{
return AEColor.values()[( this.compressedData >> 3 ) & 0x1F];
2014-09-24 02:26:27 +02:00
}
private void visitorConnection( Object tracker, IGridVisitor g, Deque<GridNode> nextRun, Deque<IGridConnection> nextConnections )
2014-09-24 02:26:27 +02:00
{
if( g.visitNode( this ) )
2014-09-24 02:26:27 +02:00
{
for( IGridConnection gc : this.getConnections() )
{
GridNode gn = (GridNode) gc.getOtherSide( this );
GridConnection gcc = (GridConnection) gc;
2014-09-24 02:26:27 +02:00
if( gcc.visitorIterationNumber != tracker )
{
gcc.visitorIterationNumber = tracker;
nextConnections.add( gc );
}
2014-09-24 02:26:27 +02:00
if( tracker == gn.visitorIterationNumber )
2015-04-29 02:30:53 +02:00
{
continue;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
gn.visitorIterationNumber = tracker;
2014-09-24 02:26:27 +02:00
nextRun.add( gn );
}
}
2014-09-24 02:26:27 +02:00
}
private void visitorNode( Object tracker, IGridVisitor g, Deque<GridNode> nextRun )
2014-09-24 02:26:27 +02:00
{
if( g.visitNode( this ) )
2014-09-24 02:26:27 +02:00
{
for( IGridConnection gc : this.getConnections() )
2014-09-24 02:26:27 +02:00
{
GridNode gn = (GridNode) gc.getOtherSide( this );
2014-09-24 02:26:27 +02:00
if( tracker == gn.visitorIterationNumber )
2015-04-29 02:30:53 +02:00
{
continue;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
gn.visitorIterationNumber = tracker;
2014-09-24 02:26:27 +02:00
nextRun.add( gn );
}
2014-09-24 02:26:27 +02:00
}
}
public GridStorage getGridStorage()
2014-09-24 02:26:27 +02:00
{
return this.myStorage;
2014-09-24 02:26:27 +02:00
}
public void setGridStorage( GridStorage s )
2014-09-24 02:26:27 +02:00
{
this.myStorage = s;
this.usedChannels = 0;
2014-09-24 02:26:27 +02:00
}
@Override
public IPathItem getControllerRoute()
2014-09-24 02:26:27 +02:00
{
if( this.connections.isEmpty() || this.getFlags().contains( GridFlags.CANNOT_CARRY ) )
2015-04-29 02:30:53 +02:00
{
return null;
2015-04-29 02:30:53 +02:00
}
return (IPathItem) this.connections.get( 0 );
2014-09-24 02:26:27 +02:00
}
@Override
public void setControllerRoute( IPathItem fast, boolean zeroOut )
2014-09-24 02:26:27 +02:00
{
if( zeroOut )
2015-04-29 02:30:53 +02:00
{
this.usedChannels = 0;
2015-04-29 02:30:53 +02:00
}
int idx = this.connections.indexOf( fast );
if( idx > 0 )
2014-09-24 02:26:27 +02:00
{
this.connections.remove( fast );
this.connections.add( 0, (IGridConnection) fast );
2014-09-24 02:26:27 +02:00
}
}
@Override
public boolean canSupportMoreChannels()
{
return this.getUsedChannels() < this.getMaxChannels();
2014-09-24 02:26:27 +02:00
}
public int getMaxChannels()
2014-09-24 02:26:27 +02:00
{
2015-01-01 22:13:10 +01:00
return CHANNEL_COUNT[this.compressedData & 0x03];
2014-09-24 02:26:27 +02:00
}
@Override
public IReadOnlyCollection<IPathItem> getPossibleOptions()
2014-09-24 02:26:27 +02:00
{
2015-05-09 00:00:52 +02:00
return (IReadOnlyCollection) this.getConnections();
2014-09-24 02:26:27 +02:00
}
@Override
public void incrementChannelCount( int usedChannels )
2014-09-24 02:26:27 +02:00
{
this.usedChannels += usedChannels;
2014-09-24 02:26:27 +02:00
}
@Override
public EnumSet<GridFlags> getFlags()
{
return this.gridProxy.getFlags();
2014-09-24 02:26:27 +02:00
}
@Override
public void finalizeChannels()
{
if( this.getFlags().contains( GridFlags.CANNOT_CARRY ) )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
return;
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
if( this.getLastUsedChannels() != this.getUsedChannels() )
2014-09-24 02:26:27 +02:00
{
this.lastUsedChannels = this.usedChannels;
2014-09-24 02:26:27 +02:00
if( this.getInternalGrid() != null )
2015-04-29 02:30:53 +02:00
{
2015-01-01 22:13:10 +01:00
this.getInternalGrid().postEventTo( this, EVENT );
2015-04-29 02:30:53 +02:00
}
2014-09-24 02:26:27 +02:00
}
}
public int getLastUsedChannels()
2014-09-24 02:26:27 +02:00
{
return lastUsedChannels;
2014-09-24 02:26:27 +02:00
}
private static class MachineSecurityBreak implements Callable<Void>
2014-09-24 02:26:27 +02:00
{
private final GridNode node;
2014-09-24 02:26:27 +02:00
public MachineSecurityBreak( GridNode node )
{
this.node = node;
}
@Override
public Void call() throws Exception
2014-09-24 02:26:27 +02:00
{
this.node.getMachine().securityBreak();
return null;
2014-09-24 02:26:27 +02:00
}
}
private static class ConnectionComparator implements Comparator<IGridConnection>
2014-09-24 02:26:27 +02:00
{
private final IGridNode gn;
public ConnectionComparator( IGridNode gn )
{
this.gn = gn;
}
@Override
public int compare( IGridConnection o1, IGridConnection o2 )
{
boolean preferredA = o1.getOtherSide( this.gn ).hasFlag( GridFlags.PREFERRED );
boolean preferredB = o2.getOtherSide( this.gn ).hasFlag( GridFlags.PREFERRED );
return preferredA == preferredB ? 0 : ( preferredA ? -1 : 1 );
}
2014-09-24 02:26:27 +02:00
}
}