org.ifeth.sehr.client.api.driver
Class ConnectionDriver

java.lang.Object
  extended byorg.ifeth.sehr.client.api.driver.ConnectionDriver
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
ConnectionDriver_Template, LANDriver, RASDriver

public abstract class ConnectionDriver
extends java.lang.Object
implements java.lang.Runnable

Driver object that builds and handles a TCP/IP connection to a SEHR host.

This is the abstract driver class which becomes a concrete class by implementing your prefered driver for the client/server. The concrete class is used by SEHRConnectionDriver#SEHRConnectionDriver().

Because all physical drivers like LAN, RAS/DUN need their own connection technology this is a "wrapper" class acting in a tier between a concrete driver object and the SEHR system. The methods below don't contain any special code for starting a physical connection like dial up. It's upon you to implement a class of your choice to be used.

Author:
IFDarwin (concept of class loading), hansjhaase (adopting to SEHR), kaesebrot (RAS driver tests)

Nested Class Summary
 class ConnectionDriver.StatusNotification
           
 
Field Summary
static java.util.logging.Logger Log
           
 
Constructor Summary
ConnectionDriver()
           
 
Method Summary
 int connect()
          Connect to SEHR host and track information about layer #0 in SEHRConnection object
 boolean discardConnectionLayer(int idx)
          Removes (disconnects) a transport layer on level idx
 boolean disconnect()
          Disconnects completely from SEHR host
 ConnectionInfo getConnectionInfo(int idx)
          Get connection info of layer x
 SEHRConnection getConnectionLayer(int idx)
           
 java.util.Vector getConnectionLayers()
          (Vector-)List of SEHRConnection objects
 int getConnections()
           
 double getLastConTime()
           
 ConnectionDriver.StatusNotification getNotifiation()
           
 double getTotalConTime()
           
 int getTypeOfDriver()
           
 void initialize()
          Method to initialize the driver for monitoring its connections Note: If overriding this method don't forget to add super.initialize in your driver.
 int newConnection(SEHRConnection c)
          Called by driver objects when a new connection is made.
 void notifyListeners(SEHRConnection c, int status)
          Notifies all listeners that a connection is open or closed.
 void registerConnectionListener(ConnectionListener listener)
          Registers the given ConnectionListener When a connection is created or removed, all registered listeners will be notified.
abstract  void run()
          To be implemented by driver objects to create a monitoring thread.
 void setRASEntry(java.lang.String entry)
          Set the RAS entry to dial
 void setRASPassword(java.lang.String pw)
          Set the user's password to login at SEHR host
 void setRASUsername(java.lang.String username)
          Set the user to login at SEHR host, e.g. for a RAS connection
 void start()
          Starts listening for connections in a new thread.
 void stop()
          Stops the driver listening for new connections, and closes all existing Connections.
 double switchConnectionStatus(int cidx, int status)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

Log

public static java.util.logging.Logger Log
Constructor Detail

ConnectionDriver

public ConnectionDriver()
Method Detail

connect

public int connect()
Connect to SEHR host and track information about layer #0 in SEHRConnection object


initialize

public void initialize()
Method to initialize the driver for monitoring its connections

Note: If overriding this method don't forget to add super.initialize in your driver.


registerConnectionListener

public void registerConnectionListener(ConnectionListener listener)
Registers the given ConnectionListener

When a connection is created or removed, all registered listeners will be notified.


notifyListeners

public void notifyListeners(SEHRConnection c,
                            int status)
Notifies all listeners that a connection is open or closed.


setRASEntry

public void setRASEntry(java.lang.String entry)
Set the RAS entry to dial


setRASUsername

public void setRASUsername(java.lang.String username)
Set the user to login at SEHR host, e.g. for a RAS connection


setRASPassword

public void setRASPassword(java.lang.String pw)
Set the user's password to login at SEHR host


newConnection

public int newConnection(SEHRConnection c)
Called by driver objects when a new connection is made.


getConnectionLayer

public SEHRConnection getConnectionLayer(int idx)

getConnectionInfo

public ConnectionInfo getConnectionInfo(int idx)
Get connection info of layer x


discardConnectionLayer

public boolean discardConnectionLayer(int idx)
Removes (disconnects) a transport layer on level idx


disconnect

public boolean disconnect()
Disconnects completely from SEHR host


getConnections

public int getConnections()

getConnectionLayers

public java.util.Vector getConnectionLayers()
(Vector-)List of SEHRConnection objects


switchConnectionStatus

public double switchConnectionStatus(int cidx,
                                     int status)

getNotifiation

public ConnectionDriver.StatusNotification getNotifiation()

getTypeOfDriver

public int getTypeOfDriver()

getLastConTime

public double getLastConTime()

getTotalConTime

public double getTotalConTime()

run

public abstract void run()
To be implemented by driver objects to create a monitoring thread.

Driver must stop running when keepRunning() returns false and clean up all resources before exiting.

Specified by:
run in interface java.lang.Runnable

start

public void start()
           throws java.io.IOException
Starts listening for connections in a new thread. This continues until stop() is called.

Throws:
java.io.IOException

stop

public void stop()
Stops the driver listening for new connections, and closes all existing Connections.