edu.cuny.cat.server
Class GameClock

java.lang.Object
  extended by edu.cuny.cat.server.GameClock
All Implemented Interfaces:
edu.cuny.config.param.Parameterizable, java.lang.Runnable

public class GameClock
extends java.lang.Object
implements edu.cuny.config.param.Parameterizable, java.lang.Runnable

This class implements a clock for a cat game.

The clock runs tick (second) by tick. A certain number of ticks makes a trading round, and a certain number of rounds makes a trading day. A cat game lasts one or more days. There is a game initialization period before the first day begins in a game and a day initialization before the first round begins in a day. Days are separated by day breaks and rounds by round breaks.

This game clock also allows a simulation of multiple games in a row by specifying iterations > 1.

The clock triggers time-related game events and notifies listeners of them, including SimulationStartedEvent, SimulationOverEvent, GameStartingEvent, GameStartedEvent, GameOverEvent, DayOpeningEvent, DayOpenedEvent, DayClosedEvent, RoundOpenedEvent, RoundClosingEvent, and RoundClosedEvent.

Parameters

base.iterations
int >=1 (1 by default)
(number of games to run in a row, solely used in a simulation)
base.gamelen
int >=1 (20 by default)
(number of days in a game)
base.daylen
int >=1 (50 by default)
(number of rounds in a day)
base.roundlen
int >=1 (10000 by default)
(number of ticks in a round)
base.roundclosinglen
int >=1 (500 by default)
(number of ticks for a closing round to be closed)
base.gamebreak
int >=1 (1000 by default)
(the length of game break in terms of ticks)
base.daybreak
int >=1 (5 by default)
(the length of a day break in terms of ticks)
base.roundbreak
int >=1 (100 by default)
(the length of a round break in terms of ticks)
base.gameinit
int >=1 (2000 by default)
(the length of game initialization period in terms of ticks)
base.dayinit
int >=1 (2000 by default)
(the length of a day initialization in terms of ticks)
base.synctimeout
int >=1 (60000 by default)
(the number of seconds the clock waits for all clients to respond to a timing event)

Version:
$Revision: 1.53 $
Author:
Jinzhong Niu

Field Summary
protected  int day
           
protected  int dayBreak
           
protected  int dayInitLen
           
protected  int dayLen
           
protected static int DEFAULT_SYNCTIMEOUT
           
protected  java.util.LinkedList<AuctionEventListener> eventListeners
           
protected  int gameBreak
           
protected  int gameInitLen
           
protected  int gameLen
           
protected  CatpInfrastructure infrast
           
protected  int iterations
           
protected  boolean logging
           
protected  boolean paused
           
protected  Registry registry
           
protected  int round
           
protected  long round_start
           
protected  int roundBreak
           
protected  int roundClosingLen
           
protected  int roundLen
           
protected  edu.cuny.util.SyncTask syncClientListTask
           
protected  edu.cuny.util.SyncTask syncFeeTask
           
protected  edu.cuny.util.SyncTask syncRegisterTask
           
protected  edu.cuny.util.SyncTask syncTask
           
protected  int syncTimeout
           
protected  java.lang.Thread thread
           
 
Constructor Summary
GameClock()
           
 
Method Summary
 void addAuctionEventListener(AuctionEventListener listener)
           
 void clearListeners()
           
protected  void dispose()
           
protected  void fireEvent(AuctionEvent event)
           
 int getDay()
           
 int getDayBreak()
           
 int getDayLen()
           
 int getGameLen()
           
 int getRound()
           
 int getRoundBreak()
           
 int getRoundLen()
           
 java.lang.Thread getThread()
           
 int getTick()
           
 int[] getTime()
           
 java.lang.String getTimeText()
           
 void initialize()
           
 boolean isActive()
           
 void pause()
          notifies the clock to pause.
 void removeAuctionEventListener(AuctionEventListener listener)
           
 void resume()
          notifies the clock to resume running.
 void run()
          Makes this clock start to tick, not meaning the game is starting.
 void setup(edu.cuny.config.param.ParameterDatabase parameters, edu.cuny.config.param.Parameter base)
           
 void start()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_SYNCTIMEOUT

protected static final int DEFAULT_SYNCTIMEOUT
See Also:
Constant Field Values

syncTimeout

protected int syncTimeout

iterations

protected int iterations

gameLen

protected int gameLen

dayLen

protected int dayLen

roundLen

protected int roundLen

gameBreak

protected int gameBreak

dayBreak

protected int dayBreak

roundClosingLen

protected int roundClosingLen

roundBreak

protected int roundBreak

gameInitLen

protected int gameInitLen

dayInitLen

protected int dayInitLen

logging

protected boolean logging

day

protected int day

round

protected int round

round_start

protected long round_start

eventListeners

protected java.util.LinkedList<AuctionEventListener> eventListeners

thread

protected java.lang.Thread thread

paused

protected boolean paused

syncTask

protected edu.cuny.util.SyncTask syncTask

syncRegisterTask

protected edu.cuny.util.SyncTask syncRegisterTask

syncFeeTask

protected edu.cuny.util.SyncTask syncFeeTask

syncClientListTask

protected edu.cuny.util.SyncTask syncClientListTask

registry

protected Registry registry

infrast

protected CatpInfrastructure infrast
Constructor Detail

GameClock

public GameClock()
Method Detail

setup

public void setup(edu.cuny.config.param.ParameterDatabase parameters,
                  edu.cuny.config.param.Parameter base)
Specified by:
setup in interface edu.cuny.config.param.Parameterizable

initialize

public void initialize()

dispose

protected void dispose()

isActive

public boolean isActive()

run

public void run()
Makes this clock start to tick, not meaning the game is starting.

Specified by:
run in interface java.lang.Runnable

getTime

public int[] getTime()

getTimeText

public java.lang.String getTimeText()

getDay

public int getDay()

getRound

public int getRound()

getTick

public int getTick()

getGameLen

public int getGameLen()

getDayLen

public int getDayLen()

getRoundLen

public int getRoundLen()

getDayBreak

public int getDayBreak()

getRoundBreak

public int getRoundBreak()

addAuctionEventListener

public void addAuctionEventListener(AuctionEventListener listener)

removeAuctionEventListener

public void removeAuctionEventListener(AuctionEventListener listener)

clearListeners

public void clearListeners()

fireEvent

protected void fireEvent(AuctionEvent event)

start

public void start()

pause

public void pause()
notifies the clock to pause.


resume

public void resume()
notifies the clock to resume running.


getThread

public java.lang.Thread getThread()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object