jSyncManager Simple Java Server

org.jSyncManager.SJS.API
Class AbstractAdapter

java.lang.Object
  extended by java.lang.Thread
      extended by org.jSyncManager.SJS.API.AbstractAdapter
All Implemented Interfaces:
java.lang.Runnable
Direct Known Subclasses:
AbstractRequestResponseAdapter

public abstract class AbstractAdapter
extends java.lang.Thread

The Abstract Adapter class. This class is the parent class of all Adapter classes. It provides the basic I/O and data mechanisms.

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

Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
protected  java.util.Properties props
          The properties held by the connection manager instance.
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
AbstractAdapter()
          Constructs a new instance of this abstract adapter.
 
Method Summary
protected  boolean connectionPermitted(java.net.InetAddress address)
          A method for testing wether or not the connection should be permitted.
protected  void disconnect()
          Process any disconnection details.
protected  ConnectionManagerInterface getConnectionManagerInterface()
          Retrieves a handle to the configuration manager interface object.
protected  java.net.InetAddress getInetAddress()
          Retrieves the internet address object for the connected host.
protected  LogManager getLogManager()
          Retrieves a handle to the current log manager.
protected  java.lang.String getProperty(java.lang.String name)
          Gets the specified property from the properties object passed from the Connection Manager.
protected abstract  void processConnection(java.io.InputStream in, java.io.OutputStream out)
          The processConnection method.
 void processConnection(java.net.Socket socket, java.util.Properties props, ConnectionManagerInterface cm)
          The processConnection method.
 void run()
          Runs the logic for this adapter in a seperate thread.
 void setLogManager(LogManager log)
          Set the log manager to use for loging messages.
static void setThreadGroup(java.lang.ThreadGroup group)
          Statically set the thread group all new instances should be created in.
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

props

protected java.util.Properties props
The properties held by the connection manager instance.

Constructor Detail

AbstractAdapter

public AbstractAdapter()
Constructs a new instance of this abstract adapter.

Method Detail

processConnection

protected abstract void processConnection(java.io.InputStream in,
                                          java.io.OutputStream out)
                                   throws java.lang.Exception
The processConnection method. This method is called when a connection for this adapter type is received. Subclasses need to implement this method in order to do anything useful.

Parameters:
in - the InputStream object for communications.
out - the OutputStream object for communications.
Throws:
java.lang.Exception - any checked exception not caught and handled by the adapter.

processConnection

public void processConnection(java.net.Socket socket,
                              java.util.Properties props,
                              ConnectionManagerInterface cm)
The processConnection method. This is the publically accessable interface to the adapter. The connection manager will call this method to initialize the communication session.

Parameters:
socket - the Socket for the connection.
props - the Properties object for this adapter instance.
cm - the ConnectionManagerInterface to use for connection manager message passing.

run

public void run()
Runs the logic for this adapter in a seperate thread.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class java.lang.Thread
See Also:
Thread

getProperty

protected java.lang.String getProperty(java.lang.String name)
Gets the specified property from the properties object passed from the Connection Manager.

Parameters:
name - the name of the property to retrieve.
Returns:
the value for the property, or null if it doesn't exist.

connectionPermitted

protected boolean connectionPermitted(java.net.InetAddress address)
A method for testing wether or not the connection should be permitted. Subclasses may implement this method to provide connection control, such as from specific IPs. The default implementation permits all connections.

Parameters:
address - the InetAddress object associated with this connection.
Returns:
true if this client is permitted to connect, false otherwise. Default is true.

setThreadGroup

public static void setThreadGroup(java.lang.ThreadGroup group)
Statically set the thread group all new instances should be created in.

Parameters:
group - the ThreadGroup to use for all instances of this class.

setLogManager

public void setLogManager(LogManager log)
Set the log manager to use for loging messages.

Parameters:
log - the log manaer to use.

getLogManager

protected LogManager getLogManager()
Retrieves a handle to the current log manager.

Returns:
a handle to the current log manager.

getConnectionManagerInterface

protected ConnectionManagerInterface getConnectionManagerInterface()
Retrieves a handle to the configuration manager interface object.

Returns:
a handle to the configuration manager interface object.

disconnect

protected void disconnect()
Process any disconnection details.


getInetAddress

protected java.net.InetAddress getInetAddress()
Retrieves the internet address object for the connected host. This method acts as a proxy to Socket.getInetAddress().

Returns:
the internet address object for the connected host, or null if there is no socket connection (ie unit testing).

jSyncManager Simple Java Server

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