net.sf.cscc
Class ClientConnectionManager

java.lang.Object
  |
  +--net.sf.cscc.ClientConnectionManager

public class ClientConnectionManager
extends java.lang.Object

This is one of the two main classes (ServerConnectionManager and ClientConnectionManager) of the CSCC library which helps to connect and to exchange the so-called data events between a remote server and a client connected over a particular TCP/IP port. A DataEvent is an event which is the carrier for particular data which is sent from the client to server or from server to the client, respectively.
For doing so, a keep alive connection between the client and the server is kept. The incoming messages are enqueued in a queue and can either be got by a pull (the interessted clients have to go and look for the incoming data) or a push (the interessted clients will be notified over a observer pattern) mechanism.

Author
Silvio Meier (SM)

Copyright
Silvio Meier, Tobias Reinhard, 2003

History
2003-05-09 SM First Version
2003-05-14 SM working on additional methods and events,
correction of some comments.
2003-05-16 SM Null pointer bug removed (when reading port
number with closed connection)
2003-05-20 TR Comments corrected
2006-10-25 SM Comments revised.

Version
$Date: 2007/07/02 21:26:17 $, $Author: reode_orm $, $Revision: 1.2 $


Constructor Summary
ClientConnectionManager(int portNumber)
          The constructor initializes this object.
 
Method Summary
 void addObserver(CommunicationEventObserver o)
          An observer which wants to be notified about communication events can register itself at the communication observer list by this method.
 void addObserver(DataEventBaseObserver o)
          This method adds an observer to the data event observer list.
 void close()
          Closes the connection to the server.
 void closeConnection()
          Deprecated. Don't use this method anymore, use close() instead!
 DataEvent getDataEvent()
          This method returns the oldest DataEvent object received from the server.
 int getPortNumber()
          This method returns the currently set port number.
 boolean hasDataEvents()
          This method returns true, if any DataEvent objects are in the incoming data event queue.
 boolean isConnectionOpen()
          This method returns true if the connection to the server is currently open.
 boolean open(java.lang.String serverName)
          This method opens a new connection to a specified server.
 DataEvent receiveDataEvent()
          This method returns the oldest DataEvent object in the incoming event queue.
 void removeDataEvent()
          This method is used to remove manually the oldest event in the incoming event queue.
 void removeObserver(CommunicationEventObserver o)
          An communication event observer which is already registered at the observer list can be unregisterd with this method.
 void removeObserver(DataEventBaseObserver o)
          This method unregisters an observer from the data event observer list.
 void sendDataEvent(DataEvent de)
          This method sends a DataEvent object from the client to the server.
 void setPortNumber(int portNumber)
          Sets the port number for a connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClientConnectionManager

public ClientConnectionManager(int portNumber)
The constructor initializes this object. It prepares the ClientConnectionManager object. A conection is not opened when initializeing the connection manager, this has to be done by calling the method open(String serverName). The The client connection manager constructor take a port number as argument which denotes on which port the connection is opened to the server.
Pre
portNumber >= 0
Post
dataObservable != null && communicationObservable != null
Parameters:
portNumber - Number of the TCP/IP port where the connection should be established.

Method Detail

open

public boolean open(java.lang.String serverName)
This method opens a new connection to a specified server. The destination server is either specified by the ip address or by its internet DNS name.
Pre
serverName != null
Post
serverConnection != null
Parameters:
serverName - Name of the server to which the connection should be opened.


close

public void close()
Closes the connection to the server.
Pre
true
Post
!(isConnectionOpen())


isConnectionOpen

public boolean isConnectionOpen()
This method returns true if the connection to the server is currently open.
Pre
true
Post
true
Returns:
Returns true, if the server connection is currently open.


sendDataEvent

public void sendDataEvent(DataEvent de)
This method sends a DataEvent object from the client to the server. This happens asynchronous, i.e. the method returns immediately.
Pre
de != null
Post
true
Parameters:
de - DataEvent object which should be sent to the server.


getDataEvent

public DataEvent getDataEvent()
This method returns the oldest DataEvent object received from the server. The DataEvent object is left in the event queue that means, calling this method a second time results in returning the same event. This happens if, and only if the event was not removed in the meantime.
Pre
true
Post
true
Returns:
Returns the oldest DataEvent object in the event queue without removing it from the queue.


removeDataEvent

public void removeDataEvent()
This method is used to remove manually the oldest event in the incoming event queue.
Pre
true
Post
true


receiveDataEvent

public DataEvent receiveDataEvent()
This method returns the oldest DataEvent object in the incoming event queue. It removes the element after returning it from the event queue.
Pre
true
Post
true
Returns:
Returns the oldest DataEvent object and removes it from the event queue.


hasDataEvents

public boolean hasDataEvents()
This method returns true, if any DataEvent objects are in the incoming data event queue.
Pre
true
Post
true
Returns:
Returns true, if there are events in the event queue.


removeObserver

public void removeObserver(DataEventBaseObserver o)
This method unregisters an observer from the data event observer list. The observer list is used for the push model, i.e. the model, where observing components are notified about new DataEvent objects in the queue.
Pre
o != null
Post
true
Parameters:
o - DataEventBaseObserver which should be removed from the observer list.


removeObserver

public void removeObserver(CommunicationEventObserver o)
An communication event observer which is already registered at the observer list can be unregisterd with this method. If the given observer is not registered, nothing happens.
Pre
o != null
Post
true
Parameters:
o - CommunicationEventObserver which should be deleted from the observer list.


addObserver

public void addObserver(DataEventBaseObserver o)
This method adds an observer to the data event observer list. The observer list is used for the push model, i.e. the model, which notifies the observing components about new DataEvent objects in the queue.
Pre
o != null
Post
true
Parameters:
o - DataEventBaseObserver object which should be added to the observer list.


addObserver

public void addObserver(CommunicationEventObserver o)
An observer which wants to be notified about communication events can register itself at the communication observer list by this method. It is notified automatically about the occurring communication events. A communication event observer must implement the interface CommunicationEventObserver.
Pre
o != null
Post
false
Parameters:
o - CommunicationEventObserver which wants to be notified if a new data event from a client is received.


setPortNumber

public void setPortNumber(int portNumber)
Sets the port number for a connection. The newly set port number will be used as soon a new connection to the server is established.
Pre
portNumber >= 0
Post
this.portNubmer == portNumber
Parameters:
portNumber - The TCP/IP port number which is used to connect the next time to the server.


getPortNumber

public int getPortNumber()
This method returns the currently set port number. This port number is used to connect to the server.
Pre
true
Post
return == this.portNumber
Returns:
Returns the currently set TCP/IP port number which is used to connect to the server


closeConnection

public void closeConnection()
Deprecated. Don't use this method anymore, use close() instead!
This method closes the connection to the server.
Pre
true
Post
true



Copyright © 2003, Silvio Meier and Tobias Reinhard. All Rights Reserved.