Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.enhydra.servlet.connectionMethods.EnhydraDirector
Class EnhydraDirectorConnectionMethod  view EnhydraDirectorConnectionMethod download EnhydraDirectorConnectionMethod.java

java.lang.Object
  extended byorg.enhydra.servlet.connectionMethods.StandardConnectionMethod
      extended byorg.enhydra.servlet.connectionMethods.EnhydraDirector.EnhydraDirectorConnectionMethod
All Implemented Interfaces:
org.enhydra.servlet.connectionMethods.ConnectionMethod, java.lang.Runnable, java.io.Serializable

public class EnhydraDirectorConnectionMethod
extends org.enhydra.servlet.connectionMethods.StandardConnectionMethod
implements java.lang.Runnable

The Enhydra connection method.

Receives and handles requests using the Enhydra Protocol. The protocol is loosely based on the proposed Apache JServ 2.1 protocol, which uses a packet transmission scheme to allow a more rich set of communcation features between web servers and Enhydra. These features include:

Round robin load balancing.

Persistent connections.

Connection Pools.

Callbacks to the front-end web server.

Version:
$Revision: 1.4.2.2.2.1 $

Field Summary
static java.lang.String AUTH_KEY
           
protected  java.lang.String authKey
          The authentication key for this connection.
protected  int backlog
          The backlog parameter for the server socket.
static java.lang.String BIND_ADDR
           
protected  java.lang.String bindAddress
          IP address to bind to.
private  java.net.InetAddress bindInetAddress
          IP address to bind to.
static java.lang.String CLIENT_TIMEOUT
           
protected  int clientTimeout
          The maximum time for a thread to keep a socket connection to the client for.
protected  java.lang.String cmType
           
protected  com.lutris.util.CircularQueue connections
          The queue for incoming connections.
private static boolean debug
          debug flag.
private static java.lang.String DEFAULT_AUTH_KEY
          No authentication by default.
private static java.lang.String DEFAULT_BIND_ADDRESS
           
static int DEFAULT_CLIENT_TIMEOUT
           
static int DEFAULT_NUM_THREADS
           
private static int DEFAULT_PORT
           
private static java.lang.String DEFAULT_PREFIX_HINT
          No default prefix hint.
static int DEFAULT_QUEUE_SIZE
           
private static boolean DEFAULT_SESSION_AFFINITY
          Session affinity is 'on' by default.
static int DEFAULT_THREAD_TIMEOUT
           
private  java.lang.Thread dispatcher
          Thread handling the connections.
static java.lang.String ENHYDRADIRECTOR
           
protected  java.lang.ThreadGroup handlers
          The thread group for EnhydraDirectorHandler threads.
protected  java.net.ServerSocket listenerSocket
          The server socket.
protected  java.util.Vector liveThreads
          A list of references to all EnhydraDirectorHandler threads (active and waiting).
protected  com.lutris.logging.LogChannel logChannel
          The logging channel.
protected  int maxHandlers
          The maximum number of EnhydraDirectorHandler threads.
protected  int maxQueue
          The maximum size of the connection queue.
static java.lang.String NUM_THREADS
           
protected  int numWaiting
          The total number EnhydraDirectorHandler threads (active and waiting).
protected  int port
          The port number for this connection method instance to bind to.
static java.lang.String PORT
           
static java.lang.String PREFIX_HINT
           
protected  java.lang.String prefixHint
          The URL used on the external (i.e.
static java.lang.String QUEUE_SIZE
           
protected static java.lang.String SERVER_BUSY_MSG
           
static java.lang.String SESSION_AFFINITY
           
protected  boolean sessionAffinity
          The session affinity flag NOTE: This attribute is not settable through the multiserver administration screen.
static java.lang.String THREAD_TIMEOUT
           
protected  int threadTimeout
          The maximum time for an EnhydraDirectorHandler thread to wait for a connection.
static java.lang.String TYPE
           
 
Fields inherited from class org.enhydra.servlet.connectionMethods.StandardConnectionMethod
channelTable, filterManager, servletManager
 
Fields inherited from interface org.enhydra.servlet.connectionMethods.ConnectionMethod
disabledChannelHtml, errorHtml, noChannelHtml
 
Constructor Summary
EnhydraDirectorConnectionMethod()
          Default constructor used for dynamic connection method creation.
 
Method Summary
 boolean channelURLIsValid(java.lang.String channelID)
          This connection method returns invalid urls.
 void destroy()
          Shut down the connection method.
 boolean equivalent(org.enhydra.servlet.connectionMethods.ConnectionMethod compareObject)
          Compares the port number to determine equivalency
 java.lang.String getAuthKey()
          Get the authentication key for this connection.
 java.lang.String getBindAddress()
          Gets the current Bind address, if any.
 org.enhydra.servlet.connectionMethods.Channel getChannelByURLPrefix(java.lang.String url)
          Gets Channel data associated with a given URL Prefix.
 java.lang.String getChannelURL(java.lang.String channelID)
          Returns the URL that a user would use to connect to this channel.
 int getClientTimeout()
          Gets the client timeout associated with this connection method.
protected  java.net.Socket getConnection()
          Returns an socket from the connection queue.
protected  EnhydraDirectorConnection getEnhydraDirectorConnection()
           
 int getNumThreads()
          Gets the maximum number of handler threads associated with this connection method.
 int getPort()
          Gets the port associated with this connection method.
 java.lang.String getPrefixHint()
          getPrefixHint() and setPrefixHint().
 int getQueueSize()
          Gets the maximum queue size associated with this connection method.
 javax.servlet.Servlet getServlet(java.lang.String servletID)
          Gets a reference to the servlet associated with servletID.
 boolean getSessionAffinity()
          getSessionAffinity() and setSessionAffinity().
 int getThreadTimeout()
          Gets the thread timeout associated with this connection method.
 java.lang.String getType()
           
 void initialize(com.lutris.util.Config connectionConfig, java.lang.String id, org.enhydra.servlet.servletManager.ServletManager servletManager, org.enhydra.servlet.filter.FilterManager filterManager)
          Start up.
 void initialize(java.lang.String id, org.enhydra.servlet.servletManager.ServletManager servletManager, org.enhydra.servlet.filter.FilterManager filterManager)
          Saves the ServletManager and FilterManager for later use.
private  void logError(java.lang.String s)
          Utility for logging errors.
private  void logError(java.lang.String s, java.lang.Exception e)
          Utility for logging errors.
private  boolean putConnection(java.net.Socket s)
          Stores a socket in the connections queue.
 void run()
          Runs the EnhydraDirectorConnectionMethod.
 void setAuthKey(java.lang.String authKey)
          Set the authentication key for this connection.
 void setBindAddress(java.lang.String addr)
          Sets the current Bind address, if any.
 void setPort(int port)
           
 void setPrefixHint(java.lang.String hint)
           
 void setSessionAffinity(boolean sessionAffinity)
           
private  void threadManager()
           
private  void writeString(java.io.OutputStream out, java.lang.String s)
          utility for writing to clients before init().
 void writeToConfig(com.lutris.util.Config connectionConfig, java.lang.String base)
          Write out self into config fie
 
Methods inherited from class org.enhydra.servlet.connectionMethods.StandardConnectionMethod
addChannel, addTransactionFilter, deleteChannel, disableChannel, enableChannel, getChannelIDs, getChannelStatus, getTransactionFilterIDs, getUniqueChannelName, removeTransactionFilter, resetRequestCount
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ENHYDRADIRECTOR

public static final java.lang.String ENHYDRADIRECTOR
See Also:
Constant Field Values

TYPE

public static final java.lang.String TYPE
See Also:
Constant Field Values

PORT

public static final java.lang.String PORT
See Also:
Constant Field Values

BIND_ADDR

public static final java.lang.String BIND_ADDR
See Also:
Constant Field Values

PREFIX_HINT

public static final java.lang.String PREFIX_HINT
See Also:
Constant Field Values

SESSION_AFFINITY

public static final java.lang.String SESSION_AFFINITY
See Also:
Constant Field Values

AUTH_KEY

public static final java.lang.String AUTH_KEY
See Also:
Constant Field Values

NUM_THREADS

public static final java.lang.String NUM_THREADS
See Also:
Constant Field Values

QUEUE_SIZE

public static final java.lang.String QUEUE_SIZE
See Also:
Constant Field Values

THREAD_TIMEOUT

public static final java.lang.String THREAD_TIMEOUT
See Also:
Constant Field Values

CLIENT_TIMEOUT

public static final java.lang.String CLIENT_TIMEOUT
See Also:
Constant Field Values

DEFAULT_PORT

private static final int DEFAULT_PORT
See Also:
Constant Field Values

DEFAULT_BIND_ADDRESS

private static final java.lang.String DEFAULT_BIND_ADDRESS
See Also:
Constant Field Values

DEFAULT_PREFIX_HINT

private static final java.lang.String DEFAULT_PREFIX_HINT
No default prefix hint.

See Also:
Constant Field Values

DEFAULT_SESSION_AFFINITY

private static final boolean DEFAULT_SESSION_AFFINITY
Session affinity is 'on' by default.

See Also:
Constant Field Values

DEFAULT_AUTH_KEY

private static final java.lang.String DEFAULT_AUTH_KEY
No authentication by default.

See Also:
Constant Field Values

DEFAULT_NUM_THREADS

public static final int DEFAULT_NUM_THREADS
See Also:
Constant Field Values

DEFAULT_QUEUE_SIZE

public static final int DEFAULT_QUEUE_SIZE
See Also:
Constant Field Values

DEFAULT_THREAD_TIMEOUT

public static final int DEFAULT_THREAD_TIMEOUT
See Also:
Constant Field Values

DEFAULT_CLIENT_TIMEOUT

public static final int DEFAULT_CLIENT_TIMEOUT
See Also:
Constant Field Values

SERVER_BUSY_MSG

protected static final java.lang.String SERVER_BUSY_MSG
See Also:
Constant Field Values

cmType

protected java.lang.String cmType

port

protected int port
The port number for this connection method instance to bind to.


bindAddress

protected java.lang.String bindAddress
IP address to bind to.


bindInetAddress

private java.net.InetAddress bindInetAddress
IP address to bind to.


prefixHint

protected java.lang.String prefixHint
The URL used on the external (i.e. Apache) web server to get to this application.


sessionAffinity

protected boolean sessionAffinity
The session affinity flag NOTE: This attribute is not settable through the multiserver administration screen.


authKey

protected java.lang.String authKey
The authentication key for this connection.

If null or an empty string, then no authentication is required.


listenerSocket

protected java.net.ServerSocket listenerSocket
The server socket.


logChannel

protected com.lutris.logging.LogChannel logChannel
The logging channel.


dispatcher

private java.lang.Thread dispatcher
Thread handling the connections.


connections

protected com.lutris.util.CircularQueue connections
The queue for incoming connections.


maxQueue

protected int maxQueue
The maximum size of the connection queue.


handlers

protected java.lang.ThreadGroup handlers
The thread group for EnhydraDirectorHandler threads.


maxHandlers

protected int maxHandlers
The maximum number of EnhydraDirectorHandler threads.


threadTimeout

protected int threadTimeout
The maximum time for an EnhydraDirectorHandler thread to wait for a connection.


clientTimeout

protected int clientTimeout
The maximum time for a thread to keep a socket connection to the client for.


backlog

protected int backlog
The backlog parameter for the server socket.


numWaiting

protected int numWaiting
The total number EnhydraDirectorHandler threads (active and waiting).


liveThreads

protected java.util.Vector liveThreads
A list of references to all EnhydraDirectorHandler threads (active and waiting).


debug

private static final boolean debug
debug flag.

See Also:
Constant Field Values
Constructor Detail

EnhydraDirectorConnectionMethod

public EnhydraDirectorConnectionMethod()
Default constructor used for dynamic connection method creation.

Method Detail

destroy

public void destroy()
             throws org.enhydra.servlet.connectionMethods.ConnectionMethodException
Shut down the connection method. Releases the socket, so the port will be free for others to use.

Specified by:
destroy in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

initialize

public void initialize(com.lutris.util.Config connectionConfig,
                       java.lang.String id,
                       org.enhydra.servlet.servletManager.ServletManager servletManager,
                       org.enhydra.servlet.filter.FilterManager filterManager)
                throws org.enhydra.servlet.connectionMethods.ConnectionMethodException
Start up. Initially there are no channels. Parse the config file for connection information Saves the ServletManager and FilterManager for later use. This initialize is called from the ConnectionMethodManager when the multiserver is started. The config file contain all relevant connection information.

Specified by:
initialize in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

initialize

public void initialize(java.lang.String id,
                       org.enhydra.servlet.servletManager.ServletManager servletManager,
                       org.enhydra.servlet.filter.FilterManager filterManager)
                throws org.enhydra.servlet.connectionMethods.ConnectionMethodException
Saves the ServletManager and FilterManager for later use. This initialize is called from the multiserver admin, when a new connection is being added or modified. The config file does not necessarly contain all connection information so this method assumes connection attributes are/were set through the get/set method pairs (as part of the bean environment).

Specified by:
initialize in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

writeToConfig

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

Specified by:
writeToConfig in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

run

public void run()
Runs the EnhydraDirectorConnectionMethod.

Specified by:
run in interface java.lang.Runnable

threadManager

private void threadManager()

getEnhydraDirectorConnection

protected EnhydraDirectorConnection getEnhydraDirectorConnection()

getConnection

protected java.net.Socket getConnection()
Returns an socket from the connection queue.


putConnection

private boolean putConnection(java.net.Socket s)
Stores a socket in the connections queue.


getChannelByURLPrefix

public org.enhydra.servlet.connectionMethods.Channel getChannelByURLPrefix(java.lang.String url)
Gets Channel data associated with a given URL Prefix.


getServlet

public javax.servlet.Servlet getServlet(java.lang.String servletID)
Gets a reference to the servlet associated with servletID.


getChannelURL

public java.lang.String getChannelURL(java.lang.String channelID)
                               throws org.enhydra.servlet.connectionMethods.ConnectionMethodException
Returns the URL that a user would use to connect to this channel. XXX: This returns incorrect URL because it has no way to know where XXX: the web server is.

Specified by:
getChannelURL in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

channelURLIsValid

public boolean channelURLIsValid(java.lang.String channelID)
                          throws org.enhydra.servlet.connectionMethods.ConnectionMethodException
This connection method returns invalid urls.

Specified by:
channelURLIsValid in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

equivalent

public boolean equivalent(org.enhydra.servlet.connectionMethods.ConnectionMethod compareObject)
Compares the port number to determine equivalency

Specified by:
equivalent in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

getType

public java.lang.String getType()
Specified by:
getType in interface org.enhydra.servlet.connectionMethods.ConnectionMethod

getPort

public int getPort()
Gets the port associated with this connection method.


setPort

public void setPort(int port)

getBindAddress

public java.lang.String getBindAddress()
Gets the current Bind address, if any.


setBindAddress

public void setBindAddress(java.lang.String addr)
Sets the current Bind address, if any.


getPrefixHint

public java.lang.String getPrefixHint()
getPrefixHint() and setPrefixHint().


setPrefixHint

public void setPrefixHint(java.lang.String hint)

getSessionAffinity

public boolean getSessionAffinity()
getSessionAffinity() and setSessionAffinity().


setSessionAffinity

public void setSessionAffinity(boolean sessionAffinity)

getAuthKey

public java.lang.String getAuthKey()
Get the authentication key for this connection.

Returns null if authentication is not required of clients.


setAuthKey

public void setAuthKey(java.lang.String authKey)
Set the authentication key for this connection.

Set to null if authentication with clients is not needed.

We don't allow auth key of all whitespace because it is most likely the result of accidental data entry in an otherwise blank 'key' field.


getNumThreads

public int getNumThreads()
Gets the maximum number of handler threads associated with this connection method.


getQueueSize

public int getQueueSize()
Gets the maximum queue size associated with this connection method.


getClientTimeout

public int getClientTimeout()
Gets the client timeout associated with this connection method.


getThreadTimeout

public int getThreadTimeout()
Gets the thread timeout associated with this connection method.


writeString

private void writeString(java.io.OutputStream out,
                         java.lang.String s)
                  throws java.io.IOException
utility for writing to clients before init(). Used to send the server busy message.


logError

private void logError(java.lang.String s,
                      java.lang.Exception e)
Utility for logging errors. The logged message will include the port, connection method type and exception thrown.


logError

private void logError(java.lang.String s)
Utility for logging errors. The logged message will include the port, connection method type and exception thrown.