public class PortBookKeeper extends java.lang.Object implements IPortProvider
Modifier and Type | Field and Description |
---|---|
private int |
gamePorts
Nr of ports that are actually available for game serving
(so, this value == 5 means there can be 5 games)
|
private static java.util.logging.Logger |
LOGGER |
private GameInfo |
NOT_A_REAL_GAME
A placeholder for the bookkeping table, if it's somehow used but we
don't know by what or whom
|
private java.util.ArrayList<GameInfo> |
portInUse
Bookkeeping which (game) ports are currently in use
|
private int |
portRangeFrom |
private int |
totalPorts
total nr of ports we are allowed to use according to options file;
but only every 2nd is used as a game port
|
Constructor and Description |
---|
PortBookKeeper(int portRangeStart,
int availablePorts) |
Modifier and Type | Method and Description |
---|---|
private java.lang.String |
buildPortTableReport() |
int |
countFreePorts() |
private void |
ensureSomeFreePortsRemain() |
int |
getFreePort(GameInfo gi) |
private GameInfo |
getGameAtPort(int portNr) |
java.lang.String |
getStatus() |
private int |
indexForRealPort(int portNumber) |
private boolean |
isPortInUse(int portNr) |
private void |
markPortFree(int portNr) |
private void |
markPortUsed(int portNr,
GameInfo gi) |
private int |
realPortForIndex(int portIndex) |
private void |
reCheckPorts() |
void |
releasePort(GameInfo gi) |
private boolean |
testThatPortReallyFree(int port)
Check that it's really free, as expected, log a warning if not
|
private boolean |
testWhetherPortFree(int port)
Just check it, whether it's free or not
|
private static final java.util.logging.Logger LOGGER
private final int portRangeFrom
private final int totalPorts
private final int gamePorts
private final java.util.ArrayList<GameInfo> portInUse
private final GameInfo NOT_A_REAL_GAME
private int realPortForIndex(int portIndex)
private int indexForRealPort(int portNumber)
private void markPortUsed(int portNr, GameInfo gi)
private void markPortFree(int portNr)
private GameInfo getGameAtPort(int portNr)
private boolean isPortInUse(int portNr)
public int getFreePort(GameInfo gi)
getFreePort
in interface IPortProvider
public int countFreePorts()
private boolean testThatPortReallyFree(int port)
private boolean testWhetherPortFree(int port)
private void ensureSomeFreePortsRemain()
private void reCheckPorts()
public void releasePort(GameInfo gi)
private java.lang.String buildPortTableReport()
public java.lang.String getStatus()