ocsf.server
Class ObservableOriginatorServer

java.lang.Object
  |
  +--java.util.Observable
        |
        +--ocsf.server.ObservableServer
              |
              +--ocsf.server.ObservableOriginatorServer

public class ObservableOriginatorServer
extends ObservableServer

The ObservableOriginatorServer is a subclass of ObservableServer that sends OriginatorMessage instances to its observers. This class should be used when the observers need to know the orginator of the messages received. The originator is null when the message sent concerns the server. Project Name: OCSF (Object Client-Server Framework)

See Also:
OriginatorMessage

Field Summary
 
Fields inherited from class ocsf.server.ObservableServer
CLIENT_CONNECTED, CLIENT_DISCONNECTED, CLIENT_EXCEPTION, LISTENING_EXCEPTION, SERVER_CLOSED, SERVER_STARTED, SERVER_STOPPED
 
Constructor Summary
ObservableOriginatorServer(int port)
          Constructs a new server.
 
Method Summary
protected  void clientConnected(ocsf.server.ConnectionToClient client)
          Method called each time a new client connection is accepted.
protected  void clientDisconnected(ocsf.server.ConnectionToClient client)
          Method called each time a client connection is disconnected.
protected  void clientException(ocsf.server.ConnectionToClient client, java.lang.Throwable exception)
          Method called each time an exception is raised by a client connection.
protected  void handleMessageFromClient(java.lang.Object message, ocsf.server.ConnectionToClient client)
          This method is used to handle messages coming from the client.
protected  void listeningException(java.lang.Throwable exception)
          Method called each time an exception is raised while listening.
protected  void serverClosed()
          Method called each time the server is closed.
protected  void serverStarted()
          Method called each time the server is started.
protected  void serverStopped()
          Method called each time the server is stopped.
 
Methods inherited from class ocsf.server.ObservableServer
close, getClientConnections, getNumberOfClients, getPort, isListening, listen, sendToAllClients, setBacklog, setPort, setTimeout, stopListening
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObservableOriginatorServer

public ObservableOriginatorServer(int port)
Constructs a new server.

Parameters:
port - the port on which to listen.
Method Detail

handleMessageFromClient

protected void handleMessageFromClient(java.lang.Object message,
                                       ocsf.server.ConnectionToClient client)
This method is used to handle messages coming from the client. Observers are notfied by receiveing an instance of OriginatorMessage that contains both the message received and a reference to the client who sent the message.

Overrides:
handleMessageFromClient in class ObservableServer
Parameters:
message - The message received from the client.
client - The connection to the client.
See Also:
ObservableOriginatorServer

clientConnected

protected void clientConnected(ocsf.server.ConnectionToClient client)
Method called each time a new client connection is accepted. It notifies observers by sending an OriginatorMessage instance containing a reference to that client and the message defined by the static variable CLIENT_CONNECTED.

Overrides:
clientConnected in class ObservableServer
Parameters:
client - the connection connected to the client.

clientDisconnected

protected void clientDisconnected(ocsf.server.ConnectionToClient client)
Method called each time a client connection is disconnected. It notifies observers by sending an OriginatorMessage instance containing a reference to that client and the message defined by the static variable CLIENT_DISCONNECTED.

Overrides:
clientDisconnected in class ObservableServer
Parameters:
client - the connection connected to the client.

clientException

protected void clientException(ocsf.server.ConnectionToClient client,
                               java.lang.Throwable exception)
Method called each time an exception is raised by a client connection. It notifies observers by sending an OriginatorMessage instance containing a reference to that client and the message defined by the static variable CLIENT_EXCEPTION to which is appended the exception message.

Overrides:
clientException in class ObservableServer
Parameters:
client - the client that raised the exception.
exception - the exception raised.

listeningException

protected void listeningException(java.lang.Throwable exception)
Method called each time an exception is raised while listening. It notifies observers by sending an OriginatorMessage instance containing the message defined by the static variable LISTENING_EXCEPTION to which is appended the exception message. The originator is set to null.

Overrides:
listeningException in class ObservableServer
Parameters:
exception - the exception raised.

serverStarted

protected void serverStarted()
Method called each time the server is started. It notifies observers by sending an OriginatorMessage instance containing the message defined by the static variable SERVER_STARTED. The originator is set to null.

Overrides:
serverStarted in class ObservableServer

serverStopped

protected void serverStopped()
Method called each time the server is stopped. It notifies observers by sending an OriginatorMessage instance containing the message defined by the static variable SERVER_STOPPED. The originator is set to null.

Overrides:
serverStopped in class ObservableServer

serverClosed

protected void serverClosed()
Method called each time the server is closed. It notifies observers by sending an OriginatorMessage instance containing the message defined by the static variable SERVER_CLOSED. The originator is set to null.

Overrides:
serverClosed in class ObservableServer