jSyncManager Simple Java Server

org.jSyncManager.SJS
Class ConnectionManager

java.lang.Object
  extended by org.jSyncManager.SJS.ConnectionManager
All Implemented Interfaces:
java.lang.Runnable, ConnectionManagerInterface

 class ConnectionManager
extends java.lang.Object
implements java.lang.Runnable, ConnectionManagerInterface

The ConnectionManager class. This class handles the incoming connections for a single port, and passes them off to the associated Adapter class. This class extends Runnable, in order to make it easily threadable (although it's not a requirement, which may be useful if one were to use this code to build a single-port server in the future).

Version:
0.1
Author:
Brad BARCLAY <bbarclay@jsyncmanager.org>

Field Summary
protected  java.lang.Class adapterClass
          A field to store the class name for the adapter class this connection manager is associated with.
protected  java.net.InetAddress bindAddress
          A field to hold the IP address this connection manager should bind to.
protected  boolean listening
          A field to denote whether or not this connection manager is listening to the specified port.
protected  int port
          A field to store the TCP port to listen to for connections.
protected  java.util.Properties props
          A field to store the properties associated with this connection manager.
protected  java.lang.String serviceName
          A field to hold this connection managers service name.
 
Constructor Summary
ConnectionManager(org.w3c.dom.Element element)
          Constructs a new instance of the ConnectionManager based on the data in the specified DOM Element.
ConnectionManager(org.w3c.dom.Element element, java.lang.ThreadGroup parentTG)
          Constructs a new instance of the ConnectionManager based on the data in the specified DOM Element.
ConnectionManager(java.lang.String serviceName, java.lang.Class adapter, java.net.InetAddress bindAddress, int port, java.util.Properties properties)
          Constructs a new instance of the ConnectionManager for the specified adapter class and port.
ConnectionManager(java.lang.String serviceName, java.lang.Class adapter, int port)
          Constructs a new instance of the ConnectionManager for the specified adapter class and port, accepting connections from any/all adapters.
ConnectionManager(java.lang.String serviceName, java.lang.String adapter, int port)
          Constructs a new instance of the ConnectionManager for the specified adapter class and port, acceptiing connections from any/all adapters.
ConnectionManager(java.lang.String serviceName, java.lang.String adapter, java.lang.String bindAddress, int port, java.util.Properties properties)
          Constructs a new instance of the ConnectionManager for the specified adapter class and port.
 
Method Summary
 void disconnectionAlert()
          A method to inform the connection manager that a disconnection has occurred.
 java.net.SocketAddress getBindAddress()
          Retrieves the socket address the ServerSocket is bound to.
 org.w3c.dom.Element getElement()
          Retrieves the DOM Element that was used to create this object.
 java.lang.String getProperty(java.lang.String property)
          Retrieves the specified property from this connection manager.
 java.lang.String getServiceName()
          Returns this connection managers service name.
 java.lang.String getStatus()
          Retrieves a string describing the state of this connection manager.
 boolean isListening()
          Tests to see if this connection manager instance is listening on its port.
 void removeProperty(java.lang.String prop)
          Removes the specified property.
 void run()
          Runs this connection manager.
 void setProperty(java.lang.String property, java.lang.String value)
          Sets the specified property to the specified value.
 void stopListening()
          Tells this connection manager to stop listening on its port.
 java.lang.String toString()
          Returns this object as a human-readable descriptive String.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

adapterClass

protected java.lang.Class adapterClass
A field to store the class name for the adapter class this connection manager is associated with.


bindAddress

protected java.net.InetAddress bindAddress
A field to hold the IP address this connection manager should bind to.


props

protected java.util.Properties props
A field to store the properties associated with this connection manager.


serviceName

protected java.lang.String serviceName
A field to hold this connection managers service name.


listening

protected volatile boolean listening
A field to denote whether or not this connection manager is listening to the specified port.


port

protected int port
A field to store the TCP port to listen to for connections.

Constructor Detail

ConnectionManager

public ConnectionManager(java.lang.String serviceName,
                         java.lang.Class adapter,
                         java.net.InetAddress bindAddress,
                         int port,
                         java.util.Properties properties)
Constructs a new instance of the ConnectionManager for the specified adapter class and port.

Parameters:
serviceName - the name of this service.
adapter - the adapter class to use for communications.
bindAddress - the address object to bind to.
port - the port to listen to for incoming connections.
properties - the properties to associate with this connection manager.

ConnectionManager

public ConnectionManager(java.lang.String serviceName,
                         java.lang.Class adapter,
                         int port)
Constructs a new instance of the ConnectionManager for the specified adapter class and port, accepting connections from any/all adapters.

Parameters:
serviceName - the name of this service.
adapter - the adapter classname to use for communications.
port - the port to listen to for incoming connections.
Throws:
java.lang.ClassNotFoundException - thrown if the specified adapter class cannot be found.

ConnectionManager

public ConnectionManager(java.lang.String serviceName,
                         java.lang.String adapter,
                         java.lang.String bindAddress,
                         int port,
                         java.util.Properties properties)
                  throws java.lang.ClassNotFoundException,
                         java.net.UnknownHostException
Constructs a new instance of the ConnectionManager for the specified adapter class and port.

Parameters:
serviceName - the name of this service.
adapter - the adapter classname to use for communications.
bindAddress - the address object to bind to.
port - the port to listen to for incoming connections.
properties - the properties to associate with this connection manager.
Throws:
java.lang.ClassNotFoundException - thrown if the specified adapter class cannot be found.
java.net.UnknownHostException

ConnectionManager

public ConnectionManager(java.lang.String serviceName,
                         java.lang.String adapter,
                         int port)
                  throws java.lang.ClassNotFoundException
Constructs a new instance of the ConnectionManager for the specified adapter class and port, acceptiing connections from any/all adapters.

Parameters:
serviceName - the name of this service.
adapter - the adapter classname to use for communications.
port - the port to listen to for incoming connections.
Throws:
java.lang.ClassNotFoundException - thrown if the specified adapter class cannot be found.

ConnectionManager

public ConnectionManager(org.w3c.dom.Element element)
                  throws java.lang.Exception
Constructs a new instance of the ConnectionManager based on the data in the specified DOM Element. This element should conform to the "service" tag.

Parameters:
element - the element containing the service information.
Throws:
java.lang.Exception

ConnectionManager

public ConnectionManager(org.w3c.dom.Element element,
                         java.lang.ThreadGroup parentTG)
                  throws java.lang.Exception
Constructs a new instance of the ConnectionManager based on the data in the specified DOM Element. This element should conform to the "service" tag.

Parameters:
element - the element containing the service information.
parentTG - the parent thread group for this object.
Throws:
java.lang.Exception
Method Detail

run

public void run()
Runs this connection manager. Note that if you're running an instance of this object within a thread, you shouldn't call this directly. Instead, construct a new instance of java.lang.Thread with this object as its constructor parameter, and call your Thread instances start() method. Thread.start() automatically calls this Runnable's run() method.

Specified by:
run in interface java.lang.Runnable

isListening

public boolean isListening()
Tests to see if this connection manager instance is listening on its port.

Returns:
true if this instance is actively accepting connections, false otherwise.

stopListening

public void stopListening()
Tells this connection manager to stop listening on its port.


getServiceName

public java.lang.String getServiceName()
Returns this connection managers service name.

Returns:
this connection managers service name.

toString

public java.lang.String toString()
Returns this object as a human-readable descriptive String.

Overrides:
toString in class java.lang.Object
Returns:
this object as a human-readable descriptive String.

getProperty

public java.lang.String getProperty(java.lang.String property)
Retrieves the specified property from this connection manager.

Parameters:
property - the property name to retrieve.
Returns:
the associated property, or null if this property doesn't exist.

setProperty

public void setProperty(java.lang.String property,
                        java.lang.String value)
Sets the specified property to the specified value.

Parameters:
property - the property to set.
value - the value to set the property to.

removeProperty

public void removeProperty(java.lang.String prop)
Removes the specified property.

Parameters:
prop - the property to be removed.

getBindAddress

public java.net.SocketAddress getBindAddress()
Retrieves the socket address the ServerSocket is bound to.

Returns:
the socket address the ServerSocket is bound to.

getStatus

public java.lang.String getStatus()
Retrieves a string describing the state of this connection manager.

Returns:
a string describing the state of this connection manager.

getElement

public org.w3c.dom.Element getElement()
Retrieves the DOM Element that was used to create this object. This method returns null if this object wasn't instantiated via a DOM Element.

Returns:
the DOM Element that was used to create this object, or null if no Element was used in the creation of this object.

disconnectionAlert

public void disconnectionAlert()
A method to inform the connection manager that a disconnection has occurred.

Specified by:
disconnectionAlert in interface ConnectionManagerInterface

jSyncManager Simple Java Server

Copyright (c) 2004 Brad BARCLAY. All Rights Reserved.