edu.cuny.cat.server
Class ConnectionAdaptor

java.lang.Object
  extended by edu.cuny.cat.server.ConnectionAdaptor
All Implemented Interfaces:
ConnectionListener<CatpMessage>, MessageHandler<CatpMessage>, AuctionEventListener, java.util.Observer

public final class ConnectionAdaptor
extends java.lang.Object
implements AuctionEventListener, ConnectionListener<CatpMessage>, MessageHandler<CatpMessage>, java.util.Observer

Each instance of this class is created by ConnectionManager on behalf of a game server to deal with requests and responses from/to a game client.

Version:
$Revision: 1.145 $
Author:
Jinzhong Niu

Field Summary
protected  ChargeValidator chargeValidator
           
protected  AccountHolder client
           
protected  GameClock clock
           
protected  ReactiveConnection<CatpMessage> connection
           
protected  GameController controller
           
protected  edu.cuny.event.EventEngine eventEngine
           
protected  boolean failed
          for debug only.
protected static org.apache.log4j.Logger logger
           
protected  ConnectionManager manager
           
protected  java.util.Map<java.lang.String,edu.cuny.cat.server.ConnectionAdaptor.ShoutFromTraderSession> pendingRequestSessions
           
protected  org.apache.commons.collections15.Buffer<CatpProactiveSession> proactiveSessions
           
protected  CatpReactiveSession[] reactiveSessions
           
protected  Registry registry
           
protected  ShoutValidator shoutValidator
           
protected  int state
           
static java.lang.String tag
           
protected  TimeoutController timeController
           
protected  TransactionValidator transactionValidator
           
protected  ValuationPolicy valuer
           
 
Constructor Summary
ConnectionAdaptor(ConnectionManager manager, Connection<CatpMessage> conn)
           
 
Method Summary
protected  int calculateState(int newState)
           
protected  void clearPendingProactiveSessions()
           
protected  void clearPendingRequestSessions()
           
protected  void debug(java.lang.String s)
           
protected  void dispatchEvent(AuctionEvent event, java.util.Collection<java.lang.String> receiverIdColl)
           
protected  void dispatchIncomingMessage(CatpMessage msg)
           
protected  void dispatchOutgoingMessage(CatpMessage msg, Session<CatpMessage> session)
           
 void eventOccurred(AuctionEvent event)
          receives notification of control messages from GameView, or messages from somewhere else, i.e.
 AccountHolder getClient()
           
 java.lang.String getClientId()
           
 ReactiveConnection<CatpMessage> getConnection()
           
 int getState()
           
 ValuationPolicy getValuer()
           
 void handleMessage(CatpMessage msg)
           
 boolean isSeller()
           
 boolean isSpecialist()
           
 boolean isTrader()
           
 void messageArrived(CatpMessage msg)
           
protected  void processAvailableMarketsAnnounced(AvailableMarketsAnnouncedEvent event)
           
protected  void processAvailableTradersAnnounced(AvailableTradersAnnouncedEvent event)
           
protected  void processDayClosed(DayClosedEvent event)
           
protected  void processDayOpenedEvent(DayOpenedEvent event)
           
protected  void processDayOpening(DayOpeningEvent event)
           
protected  void processFeesAnnounced(FeesAnnouncedEvent event)
           
protected  void processGameOver(GameOverEvent event)
           
protected  void processGameStarted(GameStartedEvent event)
           
protected  void processGameStarting(GameStartingEvent event)
           
protected  void processRegistration(RegistrationEvent event)
           
protected  void processRoundClosed(RoundClosedEvent event)
           
protected  void processRoundClosing(RoundClosingEvent event)
           
protected  void processRoundOpened(RoundOpenedEvent event)
           
protected  void processShoutPlaced(ShoutPlacedEvent event)
          notifies a trader that its shout is placed.
protected  void processShoutPosted(ShoutPostedEvent event)
          This notifies a subscriber of a placed shout.
protected  void processShoutReceived(ShoutReceivedEvent event)
          NOTE: this method is used to let a specialist know a shout is received towards it.
protected  void processShoutRejected(ShoutRejectedEvent event)
           
protected  void processSimulationOver(SimulationOverEvent event)
           
protected  void processSimulationStarted(SimulationStartedEvent event)
           
protected  void processSubscription(SubscriptionEvent event)
           
protected  void processTransactionExecuted(TransactionExecutedEvent event)
          notifieds traders that their shouts are matched in the transaction.
protected  void processTransactionPosted(TransactionPostedEvent event)
          notifies subscribers of transactions.
 void setValuer(ValuationPolicy valuer)
           
protected  void showReactiveSessions()
           
 void timeout(TimableCatpProactiveSession session)
          processes timeout event from TimeController on sessions.
 void update(java.util.Observable o, java.lang.Object arg)
          to observe the results of dispatching events to other clients.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected static org.apache.log4j.Logger logger

eventEngine

protected edu.cuny.event.EventEngine eventEngine

manager

protected ConnectionManager manager

controller

protected GameController controller

connection

protected ReactiveConnection<CatpMessage> connection

registry

protected Registry registry

clock

protected GameClock clock

shoutValidator

protected ShoutValidator shoutValidator

transactionValidator

protected TransactionValidator transactionValidator

chargeValidator

protected ChargeValidator chargeValidator

timeController

protected TimeoutController timeController

proactiveSessions

protected org.apache.commons.collections15.Buffer<CatpProactiveSession> proactiveSessions

reactiveSessions

protected CatpReactiveSession[] reactiveSessions

pendingRequestSessions

protected java.util.Map<java.lang.String,edu.cuny.cat.server.ConnectionAdaptor.ShoutFromTraderSession> pendingRequestSessions

client

protected AccountHolder client

valuer

protected ValuationPolicy valuer

state

protected int state

tag

public static java.lang.String tag

failed

protected boolean failed
for debug only.

Constructor Detail

ConnectionAdaptor

public ConnectionAdaptor(ConnectionManager manager,
                         Connection<CatpMessage> conn)
Method Detail

getClient

public AccountHolder getClient()

isTrader

public boolean isTrader()

isSeller

public boolean isSeller()

isSpecialist

public boolean isSpecialist()

setValuer

public void setValuer(ValuationPolicy valuer)

getValuer

public ValuationPolicy getValuer()

processGameStarting

protected void processGameStarting(GameStartingEvent event)

processAvailableTradersAnnounced

protected void processAvailableTradersAnnounced(AvailableTradersAnnouncedEvent event)

processAvailableMarketsAnnounced

protected void processAvailableMarketsAnnounced(AvailableMarketsAnnouncedEvent event)

processGameStarted

protected void processGameStarted(GameStartedEvent event)

processGameOver

protected void processGameOver(GameOverEvent event)

processDayOpening

protected void processDayOpening(DayOpeningEvent event)

processDayOpenedEvent

protected void processDayOpenedEvent(DayOpenedEvent event)

processDayClosed

protected void processDayClosed(DayClosedEvent event)

processRoundOpened

protected void processRoundOpened(RoundOpenedEvent event)

processRoundClosing

protected void processRoundClosing(RoundClosingEvent event)

processRoundClosed

protected void processRoundClosed(RoundClosedEvent event)

processRegistration

protected void processRegistration(RegistrationEvent event)

processSubscription

protected void processSubscription(SubscriptionEvent event)

processFeesAnnounced

protected void processFeesAnnounced(FeesAnnouncedEvent event)

processShoutPlaced

protected void processShoutPlaced(ShoutPlacedEvent event)
notifies a trader that its shout is placed.

Parameters:
event -

processShoutPosted

protected void processShoutPosted(ShoutPostedEvent event)
This notifies a subscriber of a placed shout.

Parameters:
event -

processShoutReceived

protected void processShoutReceived(ShoutReceivedEvent event)
NOTE: this method is used to let a specialist know a shout is received towards it.


processShoutRejected

protected void processShoutRejected(ShoutRejectedEvent event)

processTransactionExecuted

protected void processTransactionExecuted(TransactionExecutedEvent event)
notifieds traders that their shouts are matched in the transaction.

Parameters:
event -

processTransactionPosted

protected void processTransactionPosted(TransactionPostedEvent event)
notifies subscribers of transactions.

Parameters:
event -

processSimulationStarted

protected void processSimulationStarted(SimulationStartedEvent event)

processSimulationOver

protected void processSimulationOver(SimulationOverEvent event)

eventOccurred

public void eventOccurred(AuctionEvent event)
receives notification of control messages from GameView, or messages from somewhere else, i.e. other adaptors.

Specified by:
eventOccurred in interface AuctionEventListener

messageArrived

public void messageArrived(CatpMessage msg)
Specified by:
messageArrived in interface ConnectionListener<CatpMessage>

handleMessage

public void handleMessage(CatpMessage msg)
Specified by:
handleMessage in interface MessageHandler<CatpMessage>

dispatchEvent

protected void dispatchEvent(AuctionEvent event,
                             java.util.Collection<java.lang.String> receiverIdColl)

dispatchOutgoingMessage

protected void dispatchOutgoingMessage(CatpMessage msg,
                                       Session<CatpMessage> session)

dispatchIncomingMessage

protected void dispatchIncomingMessage(CatpMessage msg)

timeout

public void timeout(TimableCatpProactiveSession session)
processes timeout event from TimeController on sessions.


calculateState

protected int calculateState(int newState)

getState

public int getState()

getClientId

public java.lang.String getClientId()

getConnection

public ReactiveConnection<CatpMessage> getConnection()

showReactiveSessions

protected void showReactiveSessions()

clearPendingRequestSessions

protected void clearPendingRequestSessions()

clearPendingProactiveSessions

protected void clearPendingProactiveSessions()

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
to observe the results of dispatching events to other clients.

Specified by:
update in interface java.util.Observer
Parameters:
o -
arg - the AuctionEvent attempted to dispatch

debug

protected void debug(java.lang.String s)