server.framework.network
Class ServerSocketCommunicator

java.lang.Object
  extended by server.framework.network.ServerSocketCommunicator
All Implemented Interfaces:
Communicator
Direct Known Subclasses:
TestModule

public class ServerSocketCommunicator
extends java.lang.Object
implements Communicator

The server implementation of the Communicator interface. Each player object has an assigned ServerSocketCommunicator object, that is used to communicate with the associated client. This class uses the player's SocketWrapper object to determine how messages are sent and received.

Author:
Martin Jarrett, Eivind Sorteberg

Nested Class Summary
protected  class ServerSocketCommunicator.ReceiverThread
          Thread responsible for listening to the connection, and detecting when new messages arrive.
protected  class ServerSocketCommunicator.SenderThread
          Thread that is responsible for sending messages to the socket's associated client.
 
Field Summary
protected  ServerSocketCommunicator.ReceiverThread receiverThread
           
protected  ServerSocketCommunicator.SenderThread senderThread
           
protected  AbstractServer server
           
protected  SocketWrapper socket
           
 
Constructor Summary
ServerSocketCommunicator(SocketWrapper socket, AbstractServer server)
          Creates a new ServerSocketCommunicator instance, and initialises the sender and receiver threads.
 
Method Summary
 void close()
          Closes the connection.
 boolean connect(java.lang.String[] addresses)
          Not implemented, since this is the server implementation.
 void disconnect(java.lang.String[] adresses)
          Not implemented.
 SocketWrapper getSocket()
           
 void notifyAboutMessageReceived(java.lang.Object message)
          Method that is called when the receiver thread receives a new message.
 void searchForNodes()
          Not implemented.
 void sendMessage(java.lang.Object message, boolean confirm)
          Notifies the sender thread that a new message is to be sent.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

senderThread

protected final ServerSocketCommunicator.SenderThread senderThread

receiverThread

protected ServerSocketCommunicator.ReceiverThread receiverThread

socket

protected SocketWrapper socket

server

protected AbstractServer server
Constructor Detail

ServerSocketCommunicator

public ServerSocketCommunicator(SocketWrapper socket,
                                AbstractServer server)
Creates a new ServerSocketCommunicator instance, and initialises the sender and receiver threads.

Parameters:
socket - The SocketWrapper to use for the communication.
server - The server model to notify when messages are received.
Method Detail

connect

public boolean connect(java.lang.String[] addresses)
Not implemented, since this is the server implementation.

Specified by:
connect in interface Communicator
Parameters:
addresses - Not used.
Returns:
Not used.

disconnect

public void disconnect(java.lang.String[] adresses)
Not implemented.

Specified by:
disconnect in interface Communicator
Parameters:
adresses - Not used.

sendMessage

public void sendMessage(java.lang.Object message,
                        boolean confirm)
Notifies the sender thread that a new message is to be sent.

Specified by:
sendMessage in interface Communicator
Parameters:
message - The message to send.
confirm - Not used in this implementation.

notifyAboutMessageReceived

public void notifyAboutMessageReceived(java.lang.Object message)
Method that is called when the receiver thread receives a new message. When this happens, the server model is notified about the event.

Specified by:
notifyAboutMessageReceived in interface Communicator
Parameters:
message - The message that has been received.

close

public void close()
Closes the connection.

Specified by:
close in interface Communicator

searchForNodes

public void searchForNodes()
Not implemented.

Specified by:
searchForNodes in interface Communicator

getSocket

public SocketWrapper getSocket()
Returns:
The SocketWrapper object associated with this communicator.