net.sf.colossus.webserver
Class PortBookKeeper

java.lang.Object
  extended by net.sf.colossus.webserver.PortBookKeeper

public class PortBookKeeper
extends java.lang.Object

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 availablePorts
          total nr of free ports according to options file; but only every 2nd is used as a game port
private  int freeGamePorts
          Nr of ports that are actually currently available for game serving (so, this value == 5 means there can be 5 games)
private static java.util.logging.Logger LOGGER
           
private  int portRangeFrom
           
private  boolean[] portUsed
          Bookkeeping which (game) ports are currently in use
 
Constructor Summary
PortBookKeeper(int portRangeFrom, int availablePorts)
           
 
Method Summary
private  void ensureSomeFreePortsRemain()
           
 int getFreeGamePortsCount()
           
 int getFreePort(java.lang.String purpose)
           
private  void reCheckPorts()
           
 void releasePort(int port, java.lang.String purpose)
           
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

availablePorts

private final int availablePorts
total nr of free ports according to options file; but only every 2nd is used as a game port


freeGamePorts

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


portUsed

private final boolean[] portUsed
Bookkeeping which (game) ports are currently in use

Constructor Detail

PortBookKeeper

public PortBookKeeper(int portRangeFrom,
                      int availablePorts)
Method Detail

getFreeGamePortsCount

public int getFreeGamePortsCount()

getFreePort

public int getFreePort(java.lang.String purpose)

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(int port,
                        java.lang.String purpose)