edu.cuny.cat
Class GameClient

java.lang.Object
  extended by edu.cuny.cat.GameClient
All Implemented Interfaces:
ConnectionListener<CatpMessage>, AuctionEventListener, edu.cuny.config.param.Parameterizable, java.lang.Runnable, java.util.Observer
Direct Known Subclasses:
MarketClient, TraderClient

public abstract class GameClient
extends java.lang.Object
implements edu.cuny.config.param.Parameterizable, java.lang.Runnable, ConnectionListener<CatpMessage>, AuctionEventListener, java.util.Observer

A generic class featuring the common behavior of market (specialist) clients and trader clients.

Parameters

base.type
string beginning with SELLER, BUYER, or SEPECIALIST
the type of client
base.id
string
the id the client wants to be assigned (optional)
base.conntrialmax
int >=1 (1000 by default)
the maximum number of attempts to connect to server
base.logging
boolean (false by default)
whether to generate logging info
base.report
class, inherits GameReport
a report collecting information on activiites on this market

Default Base

game_client

Version:
$Revision: 1.72 $
Author:
Jinzhong Niu

Nested Class Summary
protected  class GameClient.CheckInSession
           
protected  class GameClient.DayClosedSession
           
protected  class GameClient.GameOverSession
           
protected  class GameClient.GameStartedSession
           
protected  class GameClient.GameStartingSession
           
protected  class GameClient.OracleSession
          a session deals with all unexpected request.
protected  class GameClient.PostAskSession
           
protected  class GameClient.PostBidSession
           
protected  class GameClient.PostClientListSession
           
protected  class GameClient.PostFeeSession
           
protected  class GameClient.PostProfitSession
           
protected  class GameClient.PostSession
           
protected  class GameClient.PostShoutSession
           
protected  class GameClient.PostSpecialistSession
           
protected  class GameClient.PostTraderSession
           
protected  class GameClient.PostTransactionSession
           
protected  class GameClient.RoundClosedSession
           
protected  class GameClient.RoundClosingSession
           
protected  class GameClient.RoundOpenedSession
           
protected  class GameClient.SubscribeToSpecialistSession
           
protected  class GameClient.SyncSession
          For a failed client to reconnect in and synchronize with the game.
 
Field Summary
protected  ClientConnector<CatpMessage> clientConnector
           
protected  java.lang.String clientId
          the id of this client.
protected  ReactiveConnection<CatpMessage> connection
           
protected  int connTrialMax
          the maximal number of connection attempts to make
protected  Dispatcher dispatcher
          receives and processes event-dispatching tasks.
protected  edu.cuny.event.EventEngine eventEngine
           
protected  java.util.LinkedList<AuctionEventListener> eventListeners
           
protected  CatpInfrastructure infrast
           
protected  boolean logging
           
static java.lang.String P_CONNECTION_TRIAL_MAX
           
static java.lang.String P_DEF_BASE
           
static java.lang.String P_ID
           
static java.lang.String P_LOGGING
           
static java.lang.String P_REPORT
           
static java.lang.String P_TYPE
           
protected  edu.cuny.prng.GlobalPRNG prng
           
protected  org.apache.commons.collections15.Buffer<CatpProactiveSession> proactiveSessions
          self-initiated on-going sessions on current trading day.
protected  CatpReactiveSession[] reactiveSessions
          sessions that are possibly initiated by the server at the moment.
protected  ClientRegistry registry
           
protected  GameReport report
          data report.
protected  java.lang.String tag
          the current catp tag that is used to validate the timestamp of messages.
protected  java.lang.String type
          the type of this client.
 
Constructor Summary
GameClient()
          constructors and setup
 
Method Summary
 void addAuctionEventListener(AuctionEventListener listener)
          auction listener related
protected  void addEventDispatchingTask(AuctionEvent event)
           
 void addReport(GameReport newReport)
          Add a new market data report.
protected  void checkAndUpdateMatchedShout(Shout matchedShout, Shout recordedShout)
          checks the information in a matched shout against the existing record.
protected  void cleanUpDaily()
           
protected  void cleanUpGamely()
           
protected  void clearPendingProactiveSessions()
           
protected  void close()
           
protected  void connectToServer()
          connection related
protected static Shout createMatchedShoutSimple(java.lang.String shoutId, int quantity, double price, boolean isBid, Specialist specialist)
          creates a shout with a matched state.
protected abstract  ClientRegistry createRegistry()
           
protected  void dectedAndRunReactiveSessions(CatpRequest request, CatpReactiveSession[] sessions)
           
protected  void dispatchEvent(AuctionEvent event)
           
protected abstract  CatpReactiveSession getDayOpenedSessionInstance()
           
protected abstract  CatpReactiveSession getDayOpeningSessionInstance()
           
 java.lang.String getId()
           
 GameReport getReport()
           
 java.lang.String getType()
           
protected  void loginfo(java.lang.String msg)
           
 void messageArrived(CatpMessage msg)
          message processing related
protected abstract  void postTransactionReceived(Transaction transaction)
          This method should be implemented by TraderClient and MarketClient respectively to check the validity of the posted transaction.
protected  void printDayInfo(int day)
           
protected  void printGameInfo()
           
protected  void printRoundInfo(int round)
           
protected  void processEventDispatchingTasks()
           
 void removeAuctionEventListener(AuctionEventListener listener)
           
protected  void reportDynamics(java.lang.String info)
          debugging
 void reportDynamics(java.lang.String clientId, java.lang.String info)
           
 void run()
           
protected  void setExpectedReactiveSession(CatpReactiveSession session)
           
protected  void setExpectedReactiveSessions(CatpReactiveSession[] sessions)
           
 void setId(java.lang.String clientId)
           
 void setReport(GameReport newReport)
           
 void setType(java.lang.String type)
           
 void setup(edu.cuny.config.param.ParameterDatabase parameters, edu.cuny.config.param.Parameter base)
           
protected  void showSessions(java.lang.Object[] sessions)
           
protected  void startProactiveSession(CatpProactiveSession session)
          session related
protected  void testMarketTimeout()
           
protected  void testTimeout()
           
protected  void testTraderTimeout()
           
 java.lang.String toString()
          others
 void update(java.util.Observable o, java.lang.Object arg)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.cuny.cat.event.AuctionEventListener
eventOccurred
 

Field Detail

P_CONNECTION_TRIAL_MAX

public static final java.lang.String P_CONNECTION_TRIAL_MAX
See Also:
Constant Field Values

P_TYPE

public static final java.lang.String P_TYPE
See Also:
Constant Field Values

P_ID

public static final java.lang.String P_ID
See Also:
Constant Field Values

P_LOGGING

public static final java.lang.String P_LOGGING
See Also:
Constant Field Values

P_REPORT

public static final java.lang.String P_REPORT
See Also:
Constant Field Values

P_DEF_BASE

public static final java.lang.String P_DEF_BASE
See Also:
Constant Field Values

clientConnector

protected ClientConnector<CatpMessage> clientConnector

connection

protected ReactiveConnection<CatpMessage> connection

connTrialMax

protected int connTrialMax
the maximal number of connection attempts to make


dispatcher

protected Dispatcher dispatcher
receives and processes event-dispatching tasks.


eventListeners

protected java.util.LinkedList<AuctionEventListener> eventListeners

proactiveSessions

protected org.apache.commons.collections15.Buffer<CatpProactiveSession> proactiveSessions
self-initiated on-going sessions on current trading day.


reactiveSessions

protected CatpReactiveSession[] reactiveSessions
sessions that are possibly initiated by the server at the moment.


type

protected java.lang.String type
the type of this client.


clientId

protected java.lang.String clientId
the id of this client.


registry

protected ClientRegistry registry

report

protected GameReport report
data report.


tag

protected java.lang.String tag
the current catp tag that is used to validate the timestamp of messages.


logging

protected boolean logging

infrast

protected CatpInfrastructure infrast

eventEngine

protected edu.cuny.event.EventEngine eventEngine

prng

protected edu.cuny.prng.GlobalPRNG prng
Constructor Detail

GameClient

public GameClient()
constructors and setup

Method Detail

createRegistry

protected abstract ClientRegistry createRegistry()

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

cleanUpGamely

protected void cleanUpGamely()

cleanUpDaily

protected void cleanUpDaily()

getId

public java.lang.String getId()

setId

public void setId(java.lang.String clientId)

getType

public java.lang.String getType()

setType

public void setType(java.lang.String type)

addReport

public void addReport(GameReport newReport)
Add a new market data report.

Parameters:
newReport - The new report to add.

setReport

public void setReport(GameReport newReport)

getReport

public GameReport getReport()

connectToServer

protected void connectToServer()
connection related


close

protected void close()

run

public void run()
Specified by:
run in interface java.lang.Runnable

startProactiveSession

protected void startProactiveSession(CatpProactiveSession session)
session related


setExpectedReactiveSession

protected void setExpectedReactiveSession(CatpReactiveSession session)

setExpectedReactiveSessions

protected void setExpectedReactiveSessions(CatpReactiveSession[] sessions)

dectedAndRunReactiveSessions

protected void dectedAndRunReactiveSessions(CatpRequest request,
                                            CatpReactiveSession[] sessions)

clearPendingProactiveSessions

protected void clearPendingProactiveSessions()

getDayOpeningSessionInstance

protected abstract CatpReactiveSession getDayOpeningSessionInstance()

getDayOpenedSessionInstance

protected abstract CatpReactiveSession getDayOpenedSessionInstance()

createMatchedShoutSimple

protected static Shout createMatchedShoutSimple(java.lang.String shoutId,
                                                int quantity,
                                                double price,
                                                boolean isBid,
                                                Specialist specialist)
creates a shout with a matched state.

Parameters:
shoutId -
quantity -
price -
isBid -
specialist -
Returns:
the matched shout.

checkAndUpdateMatchedShout

protected void checkAndUpdateMatchedShout(Shout matchedShout,
                                          Shout recordedShout)
checks the information in a matched shout against the existing record.

Parameters:
matchedShout - the matched shout
recordedShout - the existing record of the matched shout, which is from the local registry

postTransactionReceived

protected abstract void postTransactionReceived(Transaction transaction)
This method should be implemented by TraderClient and MarketClient respectively to check the validity of the posted transaction.

Parameters:
transaction - the posted transaction

addAuctionEventListener

public void addAuctionEventListener(AuctionEventListener listener)
auction listener related


removeAuctionEventListener

public void removeAuctionEventListener(AuctionEventListener listener)

dispatchEvent

protected void dispatchEvent(AuctionEvent event)

addEventDispatchingTask

protected void addEventDispatchingTask(AuctionEvent event)

processEventDispatchingTasks

protected void processEventDispatchingTasks()

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Specified by:
update in interface java.util.Observer

messageArrived

public void messageArrived(CatpMessage msg)
message processing related

Specified by:
messageArrived in interface ConnectionListener<CatpMessage>

toString

public java.lang.String toString()
others

Overrides:
toString in class java.lang.Object

reportDynamics

protected void reportDynamics(java.lang.String info)
debugging


reportDynamics

public void reportDynamics(java.lang.String clientId,
                           java.lang.String info)

showSessions

protected void showSessions(java.lang.Object[] sessions)

printGameInfo

protected void printGameInfo()

printDayInfo

protected void printDayInfo(int day)

printRoundInfo

protected void printRoundInfo(int round)

loginfo

protected void loginfo(java.lang.String msg)

testMarketTimeout

protected void testMarketTimeout()

testTraderTimeout

protected void testTraderTimeout()

testTimeout

protected void testTimeout()