ocsf.client
Class ObservableClient

java.lang.Object
  |
  +--java.util.Observable
        |
        +--ocsf.client.ObservableClient

public class ObservableClient
extends java.util.Observable

This class acts as a subclass of AbstractClient and is also an Observable class. Each time a new message is received, observers are notified.


Field Summary
private  AdaptableClient service
          The service instance used to simulate multiple class inheritance.
 
Fields inherited from class java.util.Observable
changed, obs
 
Constructor Summary
ObservableClient(java.lang.String host, int port)
           
 
Method Summary
 void closeConnection()
          Closes the connection to the server.
protected  void connectionClosed()
          Hook method called after the connection has been closed.
protected  void connectionEstablished()
          Hook method called after a connection has been established.
protected  void connectionException(java.lang.Exception exception)
          Hook method called each time an exception is raised by the client listening thread.
 java.lang.String getHost()
           
 java.net.InetAddress getInetAddress()
           
 int getPort()
           
protected  void handleMessageFromServer(java.lang.Object message)
          This method is used to handle messages from the server.
 boolean isConnected()
           
 void openConnection()
          Opens the connections with the server.
 void sendToServer(java.lang.Object msg)
          Sends an object to the server.
 void setHost(java.lang.String host)
          Sets the server host for the next connection.
 void setPort(int port)
          Sets the server port number for the next connection.
 
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, registerNatives, toString, wait, wait, wait
 

Field Detail

service

private AdaptableClient service
The service instance used to simulate multiple class inheritance.
Constructor Detail

ObservableClient

public ObservableClient(java.lang.String host,
                        int port)
Method Detail

openConnection

public final void openConnection()
                          throws java.io.IOException
Opens the connections with the server.

closeConnection

public final void closeConnection()
                           throws java.io.IOException
Closes the connection to the server.

sendToServer

public final void sendToServer(java.lang.Object msg)
                        throws java.io.IOException
Sends an object to the server. This is the only way that methods should communicate with the server.
Parameters:
msg - The message to be sent.

isConnected

public final boolean isConnected()

getPort

public final int getPort()
Returns:
the port number.

setPort

public final void setPort(int port)
Sets the server port number for the next connection. Only has effect if the client is not currently connected.
Parameters:
port - the port number.

getHost

public final java.lang.String getHost()
Returns:
the host name.

setHost

public final void setHost(java.lang.String host)
Sets the server host for the next connection. Only has effect if the client is not currently connected.
Parameters:
host - the host name.

getInetAddress

public final java.net.InetAddress getInetAddress()
Returns:
the client's Inet address.

handleMessageFromServer

protected void handleMessageFromServer(java.lang.Object message)
This method is used to handle messages from the server. This method can be overriden but should always call notifyObservers().
Parameters:
message - The message received from the client.

connectionClosed

protected void connectionClosed()
Hook method called after the connection has been closed.

connectionException

protected void connectionException(java.lang.Exception exception)
Hook method called each time an exception is raised by the client listening thread.
Parameters:
exception - the exception raised.

connectionEstablished

protected void connectionEstablished()
Hook method called after a connection has been established.