edu.cuny.cat.comm
Class QueueBasedInfrastructureImpl

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

public class QueueBasedInfrastructureImpl
extends java.lang.Object
implements CatpInfrastructure

The class implements a queue-based message-passing infrastructure for catp.

It is similar to SocketBasedInfrastructureImpl in the sense that both are asynchronous. They differ in two aspects: QueueBasedInfrastructureImpl does not require network resources, thus for instance avoiding possible port conflicts as in SocketBasedInfrastructureImpl, but SocketBasedInfrastructureImpl supports the real distributed game playing over the Internet and is the only available infrastructure implementation for actual competitions while QueueBasedInfrastructureImpl implies multiple threads with each for the game server or one of the waitingClients inside a single process.

Default Base

queue_based_infrastructure

Version:
$Revision: 1.10 $
Author:
Jinzhong Niu
See Also:
SocketBasedInfrastructureImpl, CallBasedInfrastructureImpl

Field Summary
protected  java.util.Map<java.lang.Object,QueueBasedCatpConnection> connections
           
static java.lang.String P_DEF_BASE
           
protected  org.apache.commons.collections15.Buffer<QueueBasedCatpClientConnector> waitingClients
           
 
Constructor Summary
QueueBasedInfrastructureImpl()
           
 
Method Summary
 QueueBasedCatpConnection acceptClient(QueueBasedCatpServerConnector server)
           
 void cleanUp()
          cleans up after finishing using this infrastructure.
 void closeConnection(java.lang.Object connector)
           
 QueueBasedCatpConnection connectToServer(QueueBasedCatpClientConnector 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(QueueBasedCatpServerConnector server)
          frees the waiting ServerConnector.
static QueueBasedInfrastructureImpl 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<QueueBasedCatpClientConnector> waitingClients

connections

protected java.util.Map<java.lang.Object,QueueBasedCatpConnection> connections
Constructor Detail

QueueBasedInfrastructureImpl

public QueueBasedInfrastructureImpl()
Method Detail

getInstance

public static QueueBasedInfrastructureImpl 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 QueueBasedCatpClientConnector.

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 QueueBasedCatpServerConnector.

connectToServer

public QueueBasedCatpConnection connectToServer(QueueBasedCatpClientConnector client)

acceptClient

public QueueBasedCatpConnection acceptClient(QueueBasedCatpServerConnector server)
                                      throws ConnectionException
Throws:
ConnectionException

freeServerConnector

public void freeServerConnector(QueueBasedCatpServerConnector 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