net.sf.cscc
Class ServerConnectionManager

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

public class ServerConnectionManager
extends java.lang.Object

This is the server class of the two main classes ServerConnectionManager and ClientConnectionManager in this client server communication component. This class provides the functionality to connect and to exchange so-called data events between a remote server and a client over a specific TCP/IP port. A DataEvent is an event which sends specific data from a client to server, respectively from a server to the client.
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 be either get by a pull (the interested clients have to go and look for the data) or a push (the interested clients will be notified over a oberver 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-15 SM methods for setting and getting port number
/ Completion of method comments.
2003-05-17 SM Comments corrected
2003-05-20 TR Comments corrected
2003-06-23 SM Dispose method corrected, stops now the 
port listening thread.
2003-06-24 SM Some corrections of comments. 
2004-12-13 SM Some cleaning of unused things.
2006-11-28 SM Comments revised.

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


Constructor Summary
ServerConnectionManager(int portNumber)
          This constructor initializes the server connection manager.
 
Method Summary
 void addObserver(CommunicationEventObserver o)
          An observer which wants to be notified about communication events can register itself at the communication observer list.
 void addObserver(DataEventBaseObserver o)
          An observer which wants to be notified about new messages from clients can register itself at the observer list.
 void beginListening()
          This method is used to start the listening process of the server.
 void closeAllConnections()
          Closes all (currently active, ie. open) connections to the currently subscribed clients.
 void closeConnection(java.lang.Object clientId)
          Closes a connection to a client.
 void dispose()
          Releases all occupied ressources by this component, i.e. all the connections are closed, the listening on the TCP/IP port is stopped and the internally used threads are stopped.
 DataEvent getDataEvent()
          This method returns the oldest DataEvent object received from the server.
 int getPortNumber()
          Gets the currently set port number.
 boolean hasDataEvents()
          This method returns true, if there are data events in the incoming event queue.
 DataEvent receiveDataEvent()
          This method returns the oldest DataEvent object in the queue.
 void removeDataEvent()
          This method is used to remove manually the oldest event in the incoming event queue.
 void removeObserver(CommunicationEventObserver o)
          A communication observer which is already registered at the observer list, can be unregisterd with this method.
 void removeObserver(DataEventBaseObserver o)
          A data observer which is already registered at the observer list can be unregisterd with this method.
 void sendBroadCastEvent(DataEvent de)
          This method broadcasts an event to all connected clients.
 void sendDataEvent(DataEvent de, java.lang.Object clientId)
          This method sends a DataEvent object to a specific client having a given clientId.
 void setPortNumber(int portNumber)
          Sets the port number for the connection.
 void stopListening()
          This method stops the listener, listening for connection requests.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ServerConnectionManager

public ServerConnectionManager(int portNumber)
This constructor initializes the server connection manager.
Pre
portNumber >= 0
Post
outGoingMessages != null && inComingMessage != null && connectionRegistry != null && listener != null
Parameters:
portNumber - TCP/IP port where to listen for connection requests

Method Detail

stopListening

public void stopListening()
This method stops the listener, listening for connection requests.
Pre
true
Post
true


sendDataEvent

public void sendDataEvent(DataEvent de,
                          java.lang.Object clientId)
This method sends a DataEvent object to a specific client having a given clientId.
Pre
de != null && clientId != null
Post
true
Parameters:
de - DataEvent object which should be sent to the client.
clientId - Id of the client which should receive the data event.


receiveDataEvent

public DataEvent receiveDataEvent()
This method returns the oldest DataEvent object in the queue. After returning it, the DataEvent object is removed from the queue.
Pre
true
Post
true
Returns:
Returns a DataEvent from the incoming event queue.


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 result in returning the same event when calling this method a second time, 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


hasDataEvents

public boolean hasDataEvents()
This method returns true, if there are data events in the incoming event queue.
Pre
true
Post
true
Returns:
Returns true, if there is one or more data events in the incoming event queue.


sendBroadCastEvent

public void sendBroadCastEvent(DataEvent de)
This method broadcasts an event to all connected clients.
Pre
true
Post
true
Parameters:
de - DataEvent object which should be broadcasted to all clients.


addObserver

public void addObserver(DataEventBaseObserver o)
An observer which wants to be notified about new messages from clients can register itself at the observer list. It is notified automatically about the incoming data events (push model). The observer must implement the interface DataEventObserver or DataEventReceivingObserver, which are subinterfaces of DataEventBaseObserver.
Pre
o != null
Post
true
Parameters:
o - DataEventBaseObserver which wants to be notified if a new data event from a client is received.


addObserver

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


removeObserver

public void removeObserver(CommunicationEventObserver o)
A communication 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.


removeObserver

public void removeObserver(DataEventBaseObserver o)
A data 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 - DataEventBaseObserver which should be deleted from the observer list.


beginListening

public void beginListening()
This method is used to start the listening process of the server. The listening process listens at the given TCP/IP getPortNumber() for connection requests of the client.
Pre
true
Post
true


setPortNumber

public void setPortNumber(int portNumber)
Sets the port number for the connection. The set port number will be active the next time when beginListening() is called.
Pre
portNumber >= 0
Parameters:
portNumber - Number to use as port


getPortNumber

public int getPortNumber()
Gets the currently set port number.
Pre
true
Post
true
Returns:
Number of the TCP/IP port used for connections between client and server.


dispose

public void dispose()
Releases all occupied ressources by this component, i.e. all the connections are closed, the listening on the TCP/IP port is stopped and the internally used threads are stopped. This method should be called as soon as the ServerConnectionManager instance is not used any more.
Pre
true
Post
Test
Since:
Component version 1.1 / Class Version 1.11


closeConnection

public void closeConnection(java.lang.Object clientId)
Closes a connection to a client. The connection is uniquely identified by a given clientId. If the connection belonging to the clientId is not found, nothing happens.
Pre
clientId != null
Post
true
Parameters:
clientId - Identification object, which identifies the client connection uniquely.


closeAllConnections

public void closeAllConnections()
Closes all (currently active, ie. open) connections to the currently subscribed clients.
Pre
true
Post
true



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