Class PortBookKeeper
java.lang.Object
net.sf.colossus.webserver.PortBookKeeper
- All Implemented Interfaces:
IPortProvider
This class keeps track of which ports are currently occupied
by ongoing games and which are free for new games.
- Author:
- Clemens Katzer
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intNr of ports that are actually available for game serving (so, this value == 5 means there can be 5 games)private static final Loggerprivate final GameInfoA placeholder for the bookkeping table, if it's somehow used but we don't know by what or whomBookkeeping which (game) ports are currently in useprivate final intprivate final inttotal nr of ports we are allowed to use according to options file; but only every 2nd is used as a game port -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate Stringintprivate voidintgetFreePort(GameInfo gi) private GameInfogetGameAtPort(int portNr) private intindexForRealPort(int portNumber) private booleanisPortInUse(int portNr) private voidmarkPortFree(int portNr) private voidmarkPortUsed(int portNr, GameInfo gi) private intrealPortForIndex(int portIndex) private voidvoidreleasePort(GameInfo gi) private booleantestThatPortReallyFree(int port) Check that it's really free, as expected, log a warning if notprivate booleantestWhetherPortFree(int port) Just check it, whether it's free or not
-
Field Details
-
LOGGER
-
portRangeFrom
private final int portRangeFrom -
totalPorts
private final int totalPortstotal nr of ports we are allowed to use according to options file; but only every 2nd is used as a game port -
gamePorts
private final int gamePortsNr of ports that are actually available for game serving (so, this value == 5 means there can be 5 games) -
portInUse
-
NOT_A_REAL_GAME
A placeholder for the bookkeping table, if it's somehow used but we don't know by what or whom
-
-
Constructor Details
-
PortBookKeeper
public PortBookKeeper(int portRangeStart, int availablePorts)
-
-
Method Details
-
realPortForIndex
private int realPortForIndex(int portIndex) -
indexForRealPort
private int indexForRealPort(int portNumber) -
markPortUsed
-
markPortFree
private void markPortFree(int portNr) -
getGameAtPort
-
isPortInUse
private boolean isPortInUse(int portNr) -
getFreePort
- Specified by:
getFreePortin interfaceIPortProvider
-
countFreePorts
public int countFreePorts() -
testThatPortReallyFree
private boolean testThatPortReallyFree(int port) Check that it's really free, as expected, log a warning if not -
testWhetherPortFree
private boolean testWhetherPortFree(int port) Just check it, whether it's free or not -
ensureSomeFreePortsRemain
private void ensureSomeFreePortsRemain() -
reCheckPorts
private void reCheckPorts() -
releasePort
-
buildPortTableReport
-
getStatus
-