edu.cuny.cat.comm
Class CallBasedInfrastructureImpl

java.lang.Object
  extended by edu.cuny.cat.comm.CallBasedInfrastructureImpl
All Implemented Interfaces:
CatpInfrastructure, Infrastructure<CatpMessage>

public class CallBasedInfrastructureImpl
extends java.lang.Object
implements CatpInfrastructure

The class implements a method-invocation-based infrastructure for catp.

With this infrstructure implementation, both the game server and the clients share a single control thread, which also runs the game clock, unlike the multi-threading scheme in SocketBasedInfrastructureImpl and QueueBasedInfrastructureImpl. This implies that all parties run inside a single process, similar to what happens in JASA. This single-threading scheme overlooks the length of trading rounds, round breaks, day breaks, and the like, therefore is expected to be much faster than the asynchronous infrstructure implementations that have to configure with sufficiently long rounds to allow message passing among the game server and the clients.

It is worth noting that though there is a single control thread most of the game duration, a game client may have a separate thread to set itself up during the game initialization period.

Parameters

Default Base

call_based_infrastructure

Version:
$Revision: 1.8 $
Author:
Jinzhong Niu

Field Summary
protected  java.util.Map<java.lang.Object,CallBasedCatpConnection> connections
           
protected  edu.cuny.util.IdAllocator idAllocator
           
static java.lang.String P_DEF_BASE
           
protected  org.apache.commons.collections15.Buffer<CallBasedCatpClientConnector> waitingClients
           
 
Constructor Summary
CallBasedInfrastructureImpl()
           
 
Method Summary
 CallBasedCatpConnection acceptClient(CallBasedCatpServerConnector server)
           
 void cleanUp()
          cleans up after finishing using this infrastructure.
 void closeConnection(java.lang.Object connector)
           
 CallBasedCatpConnection connectToServer(CallBasedCatpClientConnector client)
           
 ClientConnector<CatpMessage> createClientConnector()
          can be invoked by a GameClient to create a ClientConnector so as to connect to a GameServer.
 ServerConnector<CatpMessage> createServerConnector()
          can be invoked by a GameServer to create a ServerConnector so as to be able to wait for connection requests from GameClients.
 void freeServerConnector(CallBasedCatpServerConnector server)
          frees the waiting ServerConnector.
static CallBasedInfrastructureImpl getInstance()
           
 boolean isSynchronous()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

P_DEF_BASE

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

waitingClients

protected org.apache.commons.collections15.Buffer<CallBasedCatpClientConnector> waitingClients

connections

protected java.util.Map<java.lang.Object,CallBasedCatpConnection> connections

idAllocator

protected edu.cuny.util.IdAllocator idAllocator
Constructor Detail

CallBasedInfrastructureImpl

public CallBasedInfrastructureImpl()
Method Detail

getInstance

public static CallBasedInfrastructureImpl getInstance()

createClientConnector

public ClientConnector<CatpMessage> createClientConnector()
Description copied from interface: Infrastructure
can be invoked by a GameClient to create a ClientConnector so as to connect to a GameServer.

Specified by:
createClientConnector in interface Infrastructure<CatpMessage>
Returns:
an instance of CallBasedCatpClientConnector.

createServerConnector

public ServerConnector<CatpMessage> createServerConnector()
Description copied from interface: Infrastructure
can be invoked by a GameServer to create a ServerConnector so as to be able to wait for connection requests from GameClients.

Specified by:
createServerConnector in interface Infrastructure<CatpMessage>
Returns:
an instance of CallBasedCatpServerConnector.

connectToServer

public CallBasedCatpConnection connectToServer(CallBasedCatpClientConnector client)

acceptClient

public CallBasedCatpConnection acceptClient(CallBasedCatpServerConnector server)
                                     throws ConnectionException
Throws:
ConnectionException

freeServerConnector

public void freeServerConnector(CallBasedCatpServerConnector server)
frees the waiting ServerConnector.

Parameters:
server - the waiting ServerConnector.

cleanUp

public void cleanUp()
Description copied from interface: Infrastructure
cleans up after finishing using this infrastructure.

Specified by:
cleanUp in interface Infrastructure<CatpMessage>

closeConnection

public void closeConnection(java.lang.Object connector)

isSynchronous

public boolean isSynchronous()
Specified by:
isSynchronous in interface Infrastructure<CatpMessage>
Returns:
true if the message passing based on this infrastructure is synchronous; false otherwise.

toString

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