net.sf.colossus.webserver
Class PortBookKeeper

java.lang.Object
  extended by net.sf.colossus.webserver.PortBookKeeper
All Implemented Interfaces:
IPortProvider

public class PortBookKeeper
extends java.lang.Object
implements 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
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 Summary
PortBookKeeper(int portRangeStart, int availablePorts)
           
 
Method Summary
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOGGER

private static final java.util.logging.Logger LOGGER

portRangeFrom

private final int portRangeFrom

totalPorts

private final 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


gamePorts

private final int gamePorts
Nr of ports that are actually available for game serving (so, this value == 5 means there can be 5 games)


portInUse

private final java.util.ArrayList<GameInfo> portInUse
Bookkeeping which (game) ports are currently in use


NOT_A_REAL_GAME

private final 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

Constructor Detail

PortBookKeeper

public PortBookKeeper(int portRangeStart,
                      int availablePorts)
Method Detail

realPortForIndex

private int realPortForIndex(int portIndex)

indexForRealPort

private int indexForRealPort(int portNumber)

markPortUsed

private void markPortUsed(int portNr,
                          GameInfo gi)

markPortFree

private void markPortFree(int portNr)

getGameAtPort

private GameInfo getGameAtPort(int portNr)

isPortInUse

private boolean isPortInUse(int portNr)

getFreePort

public int getFreePort(GameInfo gi)
Specified by:
getFreePort in interface IPortProvider

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

public void releasePort(GameInfo gi)

buildPortTableReport

private java.lang.String buildPortTableReport()

getStatus

public java.lang.String getStatus()