edu.cuny.cat.comm
Class SocketBasedInfrastructureImpl

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

public class SocketBasedInfrastructureImpl
extends java.lang.Object
implements CatpInfrastructure, edu.cuny.config.param.Parameterizable

The class implements a socket-based infrastructure for catp.

It is similar to QueueBasedInfrastructureImpl 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 clients inside a single process.

Parameters

base.server
string (default: localhost)
(the domain name or IP address of the cat game server)
base.port
int (default: 9090)
(the port number the cat game server will be listening to)

Default Base

socket_based_infrastructure

Version:
$Revision: 1.22 $
Author:
Jinzhong Niu
See Also:
QueueBasedInfrastructureImpl, CallBasedInfrastructureImpl

Field Summary
static java.lang.String P_DEF_BASE
           
static java.lang.String P_PORT
           
static java.lang.String P_SERVER
           
protected  int port
           
protected  java.lang.String server
           
 
Constructor Summary
SocketBasedInfrastructureImpl()
           
 
Method Summary
protected  void allocatePort()
           
 void cleanUp()
          cleans up after finishing using this infrastructure.
 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.
static SocketBasedInfrastructureImpl getInstance()
           
 int getPort()
           
 java.lang.String getServer()
           
protected  void initialize()
           
 boolean isSynchronous()
           
 void setPort(int port)
          sets the port number of the catp server.
 void setServer(java.lang.String server)
          sets the domain name or ip address of the catp server.
 void setup(edu.cuny.config.param.ParameterDatabase parameters, edu.cuny.config.param.Parameter base)
           
 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

P_SERVER

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

P_PORT

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

port

protected int port

server

protected java.lang.String server
Constructor Detail

SocketBasedInfrastructureImpl

public SocketBasedInfrastructureImpl()
Method Detail

getInstance

public static SocketBasedInfrastructureImpl getInstance()

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

protected void initialize()

allocatePort

protected void allocatePort()

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

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

cleanUp

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

Specified by:
cleanUp in interface Infrastructure<CatpMessage>

getServer

public java.lang.String getServer()
Returns:
the domain name or ip address of the catp server.

setServer

public void setServer(java.lang.String server)
sets the domain name or ip address of the catp server.

Parameters:
server -

getPort

public int getPort()
Returns:
the port number of the catp server.

setPort

public void setPort(int port)
sets the port number of the catp server. By default, it is 9090.

Parameters:
port -

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