Enhydra 5.1 API

org.enhydra.servlet.connectionMethods
Class StandardConnectionMethod

java.lang.Object
  |
  +--org.enhydra.servlet.connectionMethods.StandardConnectionMethod
All Implemented Interfaces:
ConnectionMethod, java.io.Serializable
Direct Known Subclasses:
EnhydraDirectorConnectionMethod, HttpConnectionMethod, HttpsConnectionMethod

public abstract class StandardConnectionMethod
extends java.lang.Object
implements ConnectionMethod

This is a sample implementation of a ConnectionMethod. It is an abstract class because this class does not actually recieve or generate requests. It does do all the channel managment. Implementations of ConnectionMethod should extend this object, unless there is a specific reason not to.

Classes that extend this class will need to implement the getChannelURL() and channelURLIsValid() functions. They will also need to ensure that they contain a thread that is started in the constructor or (prefered) initialize(), and stopped in destroy().

Author:
Andy John
See Also:
ConnectionMethod, Serialized Form

Field Summary
protected  ChannelTable channelTable
          Stores a set of ChannelTableEntries.
 FilterManager filterManager
          The FilterManager passed in to the initialize() method.
 ServletManager servletManager
          The ServletManager passed in to the initialize() method.
 
Fields inherited from interface org.enhydra.servlet.connectionMethods.ConnectionMethod
disabledChannelHtml, errorHtml, noChannelHtml
 
Constructor Summary
StandardConnectionMethod()
           
 
Method Summary
 void addChannel(java.lang.String channelID, java.lang.String URLPrefix, java.lang.String servletID)
          Add a new channel.
 void addTransactionFilter(java.lang.String channelID, java.lang.String filterID)
          Add a new Filter to the specified channel.
 void deleteChannel(java.lang.String channelID)
          Delete a channel.
 void destroy()
          Shut down the connection method.
 void disableChannel(java.lang.String channelID)
          Turn off the channel.
 void enableChannel(java.lang.String channelID)
          Turn on the channel.
 boolean equivalent(ConnectionMethod compareObject)
          Compares the connection specific attributes for equivalency
 java.lang.String[] getChannelIDs()
          Returns the identifier names of all the channels currently in the ConnectionMethod.
 ChannelStatus getChannelStatus(java.lang.String channelID)
          Get the current status of a channel.
 java.lang.String[] getTransactionFilterIDs(java.lang.String channelID)
          Get a list of all the filter names.
 java.lang.String getType()
           
 java.lang.String getUniqueChannelName()
          This returns a channel name that is not currently in use.
 void initialize(Config connectionConfig, java.lang.String id, ServletManager servletManager, FilterManager filterManager)
          Start up.
 void initialize(java.lang.String id, ServletManager servletManager, FilterManager filterManager)
          Start up.
 void removeTransactionFilter(java.lang.String channelID, java.lang.String filterID)
          Remove the given Filter from the specified channel.
 void resetRequestCount(java.lang.String channelID)
          Reset the specified channel's request count to zero.
 void writeToConfig(Config connectionConfig, java.lang.String base)
          Write out self into config fie
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.enhydra.servlet.connectionMethods.ConnectionMethod
channelURLIsValid, getChannelURL, getPort
 

Field Detail

servletManager

public ServletManager servletManager
The ServletManager passed in to the initialize() method. If you are extending this class, you should use this ServletManager to convert the servletID string to Servlets. The servletID strings are only valid in this ServletManager.

See Also:
ServletManager

filterManager

public FilterManager filterManager
The FilterManager passed in to the initialize() method. If you are extending this class, you should use this FilterManager to convert the filterID string to Filters. The filterID strings are only valid in this FilterManager.

See Also:
FilterManager

channelTable

protected ChannelTable channelTable
Stores a set of ChannelTableEntries. This is where all the information about the channels is stored. All the methods that modify the status of channels synchronize on this object.

Constructor Detail

StandardConnectionMethod

public StandardConnectionMethod()
Method Detail

initialize

public void initialize(Config connectionConfig,
                       java.lang.String id,
                       ServletManager servletManager,
                       FilterManager filterManager)
                throws ConnectionMethodException
Start up. Initially there are no channels. Saves the ServletManager for later use.

This will be called before any other method in this class.

Specified by:
initialize in interface ConnectionMethod
Parameters:
connectionConfig - The portion of the config file relevant to this connection method
id - The id associated with this connection method
servletManager - The ServletManager to use to convert servletIDs into Servlets.
filterManager - The FilterManager to use to convert filterIDs into Filters.
Throws:
ConnectionMethodException - If unable to start up. This class will not throw this exception, however classes which extend this class may.
See Also:
Filter

initialize

public void initialize(java.lang.String id,
                       ServletManager servletManager,
                       FilterManager filterManager)
                throws ConnectionMethodException
Start up. Initially there are no channels. Saves the ServletManager for later use.

This will be called before any other method in this class.

Specified by:
initialize in interface ConnectionMethod
Parameters:
id - The id associated with this connection method
servletManager - The ServletManager to use to convert servletIDs into Servlets.
filterManager - The FilterManager to use to convert filterIDs into Filters.
Throws:
ConnectionMethodException - If unable to start up. This class will not throw this exception, however classes which extend this class may.
See Also:
Filter

writeToConfig

public void writeToConfig(Config connectionConfig,
                          java.lang.String base)
                   throws ConfigException,
                          KeywordValueException
Write out self into config fie

Specified by:
writeToConfig in interface ConnectionMethod
Parameters:
base - The base key string
ConfigException
KeywordValueException

addChannel

public void addChannel(java.lang.String channelID,
                       java.lang.String URLPrefix,
                       java.lang.String servletID)
                throws ConnectionMethodException
Add a new channel. The new channel is not enabled, and has no Filters.

Specified by:
addChannel in interface ConnectionMethod
Parameters:
channelID - The symbolic name to use for this channel.
URLPrefix - If a request's URL starts with this string, it should be sent to the servlet identified by servletID. To obtain the servlet, use the ServletManager's get() method.
servletID - The servlet to send requests to. Use the ServletManager's get() method to get the servlet. Call get() for each request, do not save a reference to the servlet.
Throws:
ConnectionMethodException - If an error occurs, for example using an already existing channelID.
See Also:
ServletManager

getChannelStatus

public ChannelStatus getChannelStatus(java.lang.String channelID)
Get the current status of a channel.

Specified by:
getChannelStatus in interface ConnectionMethod
Parameters:
channelID - Which channel.
Returns:
The status of the channel, stored in a ChannelStatus object.
See Also:
ChannelStatus

deleteChannel

public void deleteChannel(java.lang.String channelID)
                   throws ConnectionMethodException
Delete a channel.

Specified by:
deleteChannel in interface ConnectionMethod
Parameters:
channelID - Which channel to remove.
Throws:
ConnectionMethodException - If an error occurs, for example if the channelID is not found.

getChannelIDs

public java.lang.String[] getChannelIDs()
Returns the identifier names of all the channels currently in the ConnectionMethod.

Specified by:
getChannelIDs in interface ConnectionMethod
Returns:
An array of Strings, the names of all the channels in the ConnectionMethod.

enableChannel

public void enableChannel(java.lang.String channelID)
                   throws ConnectionMethodException
Turn on the channel. Allows requests to be sent to the servlet.

Specified by:
enableChannel in interface ConnectionMethod
Parameters:
channelID - Which channel to enable.
Throws:
ConnectionMethodException - If an error occurs, for example if the channelID is not found.

disableChannel

public void disableChannel(java.lang.String channelID)
                    throws ConnectionMethodException
Turn off the channel. Incomming requests should be refused. No requests should be allowed through to the servlet.

Specified by:
disableChannel in interface ConnectionMethod
Parameters:
channelID - Which channel to disable.
Throws:
ConnectionMethodException - If an error occurs, for example if the channelID is not found.

resetRequestCount

public void resetRequestCount(java.lang.String channelID)
                       throws ConnectionMethodException
Reset the specified channel's request count to zero. The counter measures the number of requests processed by this channel.

Specified by:
resetRequestCount in interface ConnectionMethod
Parameters:
channelID - Which channel.
Throws:
ConnectionMethodException - If an error occurs, for example if the channelID is not found.

addTransactionFilter

public void addTransactionFilter(java.lang.String channelID,
                                 java.lang.String filterID)
                          throws ConnectionMethodException
Add a new Filter to the specified channel.

Specified by:
addTransactionFilter in interface ConnectionMethod
Parameters:
channelID - Which channel to add a Filter to.
filterID - The TransactionFilter to add. The filter is fetched from the FilterManager passed in to initialize() each time a request comes in.
Throws:
ConnectionMethodException - If the channel does not exist, or the filter name is already in use.
See Also:
Filter

removeTransactionFilter

public void removeTransactionFilter(java.lang.String channelID,
                                    java.lang.String filterID)
                             throws ConnectionMethodException
Remove the given Filter from the specified channel.

Specified by:
removeTransactionFilter in interface ConnectionMethod
Parameters:
channelID - Which channel to remove a Filter from.
Throws:
ConnectionMethodException - If the channel or the filter do not exist.
See Also:
Filter

getTransactionFilterIDs

public java.lang.String[] getTransactionFilterIDs(java.lang.String channelID)
                                           throws ConnectionMethodException
Get a list of all the filter names.

Specified by:
getTransactionFilterIDs in interface ConnectionMethod
Returns:
An array of filter names.
Throws:
ConnectionMethodException - If the channel ID does not exist.

getUniqueChannelName

public java.lang.String getUniqueChannelName()
This returns a channel name that is not currently in use. Use this when you want to programatically create a channel, and you don't care what it's name is. The name returned will not be in the list of current channels, and will not be returned on any other calls to this function.
The names will be of the form "channel".

Specified by:
getUniqueChannelName in interface ConnectionMethod
Returns:
A name that can be used with addChannel().

destroy

public void destroy()
             throws ConnectionMethodException
Shut down the connection method. This class simply throws out all the channels. If you extend this class, you will probably want to perform some actions to close down the external part of the connection and kill any threads you started.

After this call, none of these methods will be called again.

Specified by:
destroy in interface ConnectionMethod
Throws:
ConnectionMethodException - If an error occurs.

equivalent

public boolean equivalent(ConnectionMethod compareObject)
Compares the connection specific attributes for equivalency

Specified by:
equivalent in interface ConnectionMethod
Parameters:
compareObject - The object to compare this to
Throws:
ConnectionMethodException - If an error occurs.

getType

public java.lang.String getType()
Specified by:
getType in interface ConnectionMethod

Enhydra 5.1 API