|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.enhydra.servlet.connectionMethods.EnhydraDirector.EnhydraDirectorProtocol
Field Summary | |
protected boolean |
active
Whether or not this connection is active. |
protected int |
clientMajor
Client side protocol major version. |
protected int |
clientMinor
Client side protocol minor version. |
protected org.apache.commons.logging.Log |
log
Logging channel |
protected static int |
MAJOR_VERSION
|
protected static int |
MAX_AUTHDATA_LENGTH
|
protected static int |
MAX_FUNCDATA_LENGTH
|
protected static int |
MAX_SMALL_PACKET_LENGTH
|
protected static int |
MINOR_VERSION
|
protected static int |
PKT_HEADER_SIZE
|
protected static int |
PKT_OPENFLAGS_HEADERCB
|
protected static int |
PKT_OPENFLAGS_OPENCB
|
protected static int |
PKT_SUBTYPE_AUTH_CLI
|
protected static int |
PKT_SUBTYPE_AUTH_FAIL
|
protected static int |
PKT_SUBTYPE_AUTH_OK
|
protected static int |
PKT_SUBTYPE_AUTH_SVR
|
protected static int |
PKT_SUBTYPE_CTRL_CLI_ACTIVATE
|
protected static int |
PKT_SUBTYPE_CTRL_CLI_CLOSE
|
protected static int |
PKT_SUBTYPE_CTRL_CLI_DEACTIVATE
|
protected static int |
PKT_SUBTYPE_CTRL_SVR_REFRESH
|
protected static int |
PKT_SUBTYPE_FUNC_CALL
|
protected static int |
PKT_SUBTYPE_FUNC_END
|
protected static int |
PKT_SUBTYPE_FUNC_FAIL
|
protected static int |
PKT_SUBTYPE_FUNC_OK
|
protected static int |
PKT_SUBTYPE_FUNC_ONEWAY
|
protected static int |
PKT_SUBTYPE_HEADER_COOKIE
|
protected static int |
PKT_SUBTYPE_HEADER_HEADER
|
protected static int |
PKT_SUBTYPE_HEADER_HTTP
|
protected static int |
PKT_SUBTYPE_HEADER_LAST
|
protected static int |
PKT_SUBTYPE_PROTO_CLOSE
|
protected static int |
PKT_SUBTYPE_PROTO_FATAL
|
protected static int |
PKT_SUBTYPE_PROTO_VERSION
|
protected static int |
PKT_SUBTYPE_REQ_DATA
|
protected static int |
PKT_SUBTYPE_REQ_LASTDATA
|
protected static int |
PKT_SUBTYPE_RESP_DATA
|
protected static int |
PKT_SUBTYPE_RESP_END
|
protected static int |
PKT_SUBTYPE_RESP_ERROR
|
protected static int |
PKT_SUBTYPE_RESP_LOGS
|
protected static int |
PKT_SUBTYPE_RESP_WARNING
|
protected static int |
PKT_TYPE_AUTH
|
protected static int |
PKT_TYPE_CTRL_CLI
|
protected static int |
PKT_TYPE_CTRL_SVR
|
protected static int |
PKT_TYPE_FUNC
|
protected static int |
PKT_TYPE_HEADER
|
protected static int |
PKT_TYPE_PROTO
|
protected static int |
PKT_TYPE_REQ
|
protected static int |
PKT_TYPE_RESP
|
protected int |
state
The current state of this connection's state machine. |
protected static int |
STATE_CHECK_AUTH
|
protected static int |
STATE_CLOSED
|
protected static int |
STATE_HAVE_HEADERS
|
protected static int |
STATE_NEWCONNECT
|
protected static int |
STATE_OPEN
|
protected static int |
STATE_OPENING
|
protected static int |
STATE_PROCESSING_ENTITY_FUNC
|
protected static int |
STATE_PROCESSING_FUNC
|
protected static int |
STATE_PROCESSING_HEADER
|
protected static int |
STATE_PROCESSING_REQUEST
|
protected static int |
STATE_RECEIVING_ENTITY
|
protected static int |
STATE_RECEIVING_HEADERS
|
protected static int |
STATE_WAIT_AUTH
|
protected static int |
STATE_WAIT_ENTITY_CALLBACK
|
protected static int |
STATE_WAIT_HEADER_CALLBACK
|
protected static int |
STATE_WAIT_OPEN_CALLBACK
|
protected static int |
STATE_WAIT_VERSION
|
Constructor Summary | |
EnhydraDirectorProtocol(org.apache.commons.logging.Log chan)
Create a new EnhydraDirector connection object. |
Method Summary | |
void |
activate()
Complete connection establishment after authentication. |
void |
authenticate()
Causes the authentication challenge to be sent to the client. |
void |
authenticate(boolean openCB,
boolean headerCB)
Second version of authenticate that allows a request for
post-open and post-header callbacks.
|
protected abstract boolean |
authRequired()
Implementation class must provide this method. |
boolean |
callback(int number,
byte[] argsIn,
byte[][] dataOut)
Send a callback to the client. |
void |
closeConnection()
Method to close output stream. |
void |
closeInput()
Discards any further incoming request entity data and marks the input stream as "closed". |
void |
closeOutput()
Method to close output stream. |
void |
connect(java.net.Socket socket)
This method causes a new EnhydraDirectorProtocol instance
to accept the next socket connection from a server socket. |
void |
deactivate()
Cause this connection to go into an inactive state. |
protected long |
discardEntity()
Discard the entire entity body We don't care about it. |
void |
finishHeaders()
Method to send an HTTP cookie. |
protected abstract byte[] |
getAuthData()
Abstract method to get authentication secret data. |
protected abstract EnhydraDirectorFunction |
getFunction(int type)
Internal dispatch table for server side function handlers. |
protected java.lang.String |
getStateName()
Returns a text name for the current state of this instance. |
protected java.lang.String |
getStateName(int stateNum)
Returns a text name for the specified state number. |
int |
inputAvailable()
Returns a maximum number of bytes which can be read without blocking. |
boolean |
isAuthenticated()
Returns true if the client has successfully authenticated
itself for this connection.
|
boolean |
isConnected()
Returns false if this connection is in the CLOSED state,
otherwise returns true .
|
boolean |
isOpen()
Returns |
protected abstract void |
processCgiHeader(byte[] name,
byte[] value)
Abstract method to process a CGI-BIN header. |
protected abstract void |
processCookie(byte[] name,
byte[] value)
Abstract method to process a cookie. |
protected abstract void |
processHttpHeader(byte[] name,
byte[] value)
Abstract method to process an HTTP request header. |
int |
read()
Read a single byte of entity input and return it as an integer from 0 to 255. |
int |
read(byte[] inBuf)
Read at least one and at most inBuf.length bytes.
|
int |
read(byte[] inBuf,
int off,
int len)
Read at least one and at most len request entity bytes.
|
int |
readExactly(byte[] inBuf)
Read request entity bytes with Java read semantics. |
int |
readExactly(byte[] inBuf,
int off,
int len)
Read exactly len request entity bytes.
|
void |
sendCookie(java.lang.String name,
java.lang.String value)
Method to send an HTTP cookie. |
void |
sendHeader(java.lang.String name,
java.lang.String value)
Method to send an HTTP header. |
long |
skip(long n)
Skip over nbytes bytes of entity input data.
|
java.lang.String |
toString()
Generates a string that displays the current state of this instance. |
void |
write(byte[] buf)
Method to write a single byte of response data. |
void |
write(byte[] buf,
int off,
int len)
Method to write a single byte of response data. |
void |
write(int b)
Method to write a single byte of response data. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected static final int MAJOR_VERSION
protected static final int MINOR_VERSION
protected static final int STATE_CLOSED
protected static final int STATE_NEWCONNECT
protected static final int STATE_WAIT_AUTH
protected static final int STATE_WAIT_VERSION
protected static final int STATE_CHECK_AUTH
protected static final int STATE_OPENING
protected static final int STATE_WAIT_OPEN_CALLBACK
protected static final int STATE_OPEN
protected static final int STATE_PROCESSING_FUNC
protected static final int STATE_PROCESSING_HEADER
protected static final int STATE_RECEIVING_HEADERS
protected static final int STATE_HAVE_HEADERS
protected static final int STATE_WAIT_HEADER_CALLBACK
protected static final int STATE_RECEIVING_ENTITY
protected static final int STATE_WAIT_ENTITY_CALLBACK
protected static final int STATE_PROCESSING_ENTITY_FUNC
protected static final int STATE_PROCESSING_REQUEST
protected static final int PKT_TYPE_AUTH
protected static final int PKT_SUBTYPE_AUTH_SVR
protected static final int PKT_SUBTYPE_AUTH_CLI
protected static final int PKT_SUBTYPE_AUTH_OK
protected static final int PKT_SUBTYPE_AUTH_FAIL
protected static final int PKT_TYPE_REQ
protected static final int PKT_SUBTYPE_REQ_DATA
protected static final int PKT_SUBTYPE_REQ_LASTDATA
protected static final int PKT_TYPE_FUNC
protected static final int PKT_SUBTYPE_FUNC_FAIL
protected static final int PKT_SUBTYPE_FUNC_OK
protected static final int PKT_SUBTYPE_FUNC_CALL
protected static final int PKT_SUBTYPE_FUNC_ONEWAY
protected static final int PKT_SUBTYPE_FUNC_END
protected static final int PKT_TYPE_RESP
protected static final int PKT_SUBTYPE_RESP_DATA
protected static final int PKT_SUBTYPE_RESP_LOGS
protected static final int PKT_SUBTYPE_RESP_WARNING
protected static final int PKT_SUBTYPE_RESP_ERROR
protected static final int PKT_SUBTYPE_RESP_END
protected static final int PKT_TYPE_HEADER
protected static final int PKT_SUBTYPE_HEADER_HEADER
protected static final int PKT_SUBTYPE_HEADER_HTTP
protected static final int PKT_SUBTYPE_HEADER_COOKIE
protected static final int PKT_SUBTYPE_HEADER_LAST
protected static final int PKT_TYPE_CTRL_CLI
protected static final int PKT_SUBTYPE_CTRL_CLI_ACTIVATE
protected static final int PKT_SUBTYPE_CTRL_CLI_DEACTIVATE
protected static final int PKT_SUBTYPE_CTRL_CLI_CLOSE
protected static final int PKT_TYPE_CTRL_SVR
protected static final int PKT_SUBTYPE_CTRL_SVR_REFRESH
protected static final int PKT_TYPE_PROTO
protected static final int PKT_SUBTYPE_PROTO_CLOSE
protected static final int PKT_SUBTYPE_PROTO_FATAL
protected static final int PKT_SUBTYPE_PROTO_VERSION
protected static final int PKT_OPENFLAGS_OPENCB
protected static final int PKT_OPENFLAGS_HEADERCB
protected static final int PKT_HEADER_SIZE
protected static final int MAX_AUTHDATA_LENGTH
protected static final int MAX_FUNCDATA_LENGTH
protected static final int MAX_SMALL_PACKET_LENGTH
protected int state
protected int clientMajor
protected int clientMinor
protected boolean active
protected org.apache.commons.logging.Log log
Constructor Detail |
public EnhydraDirectorProtocol(org.apache.commons.logging.Log chan)
Sets the initial state to CLOSED. Before this instance may be used, it
must be assigned a connection using the connect()
method.
Method Detail |
protected abstract EnhydraDirectorFunction getFunction(int type)
type
- Protocol-defined function type number.
protected abstract boolean authRequired()
true
if authentication is required.protected abstract byte[] getAuthData()
This method must be provided by the implementation class. It checks the configuration and finds the secret authentication data used to verify authentication responses from clients.
null
if
authentication data does not exist.protected abstract void processCgiHeader(byte[] name, byte[] value)
null
if
authentication data does not exist.protected abstract void processHttpHeader(byte[] name, byte[] value)
null
if
authentication data does not exist.protected abstract void processCookie(byte[] name, byte[] value)
null
if
authentication data does not exist.public void connect(java.net.Socket socket) throws EnhydraDirectorBadStateException, java.io.IOException
EnhydraDirectorProtocol
instance
to accept the next socket connection from a server socket. This method
may only be called if isConnected()
returns
false
. Otherwise an exception is thrown.
socket
- Server socket from which to obtain a new connection.
java.io.IOException
- If a network failure occurs.
EnhydraDirectorBadStateException
- If this method is called while the state is not CLOSED.public boolean isConnected()
false
if this connection is in the CLOSED state,
otherwise returns true
.
After an exception is raised by this connection, this method should be checked to verify the state of the connection.
public void authenticate() throws EnhydraDirectorBadStateException, java.io.IOException
Authentication data is retrieved in an implementation specific manner by
the abstract getAuthData
method.
This method must only be called after a connect()
call and
before any other calls. However, authentication can be delayed until a
thread becomes available to process the authentication. Once
authentication returns, this instance may be placed back in inactive
status until it is re-activated to handle an incoming request. Upon
authentication failure, this instance reverts to the CLOSED state, and
the connection socket is closed. In such a case, this object must be
deleted and a new one created in order to create a new connection.
Only call this method if isAuthenticated()
returns
false
. Otherwise an exception will be thrown.
java.io.IOException
- If a network failure occurs.
EnhydraDirectorBadStateException
- If this method is called while in a state other than
NEWCONNECT.public void authenticate(boolean openCB, boolean headerCB) throws EnhydraDirectorBadStateException, java.io.IOException
authenticate
that allows a request for
post-open and post-header callbacks.
If either of these options are set, performance will be degraded because the client must go into a wait state until it receives all of the callbacks and the final callback termination packet. Use these options sparingly.
Only call this method if isAuthenticated()
returns
false
. Otherwise an exception will be thrown.
Note: If either callback option is set to true
but
callbacks are not made, the state machine automatically detects this and
sends callback termination to prevent a mutual-receive deadlock condition
from arising.
openCB
- If true
callbacks may be made to the client
immediately prior to finishing the connection establishment.headerCB
- If true
callbacks may be made to the client
immediately after all HTTP request headers have been received.
java.io.IOException
- If a network failure occurs.
EnhydraDirectorBadStateException
- If this method is called while in a state other than
NEWCONNECT.authenticate()
,
activate()
public boolean isAuthenticated()
true
if the client has successfully authenticated
itself for this connection.
Use this method to determine whether authenticate()
must
be called.
public void activate() throws java.io.IOException
After authenticate()
returns, the connection is not fully
open and available for requests until activate
. has been
called. This allows callbacks to be sent prior to full connection
establishment. These callbacks happen only once in the lifetime of a
connection, and not on a per-request basis, as would be the case with
post-header or post-entity callbacks.
If post-open callbacks have not been requested, this method goes straight to the OPEN state. If callbacks were requested, the callback termination packet is sent to tell the client that there are no more callbacks.
java.io.IOException
public void deactivate() throws java.io.IOException
All buffers are freed and the state is reset to OPEN. This method is called by a higher level connection/thread manager to disassociate this instance with any thread. Usually this means the instance is being placed on an inactive list, awaiting future activation by a running client load manager.
EnhydraDirectorBadStateException
- If this instance is currently processing. Only instances
in the OPEN state may be activated or deactivated.
java.io.IOException
public boolean isOpen()
public boolean callback(int number, byte[] argsIn, byte[][] dataOut) throws java.lang.IllegalArgumentException, EnhydraDirectorBadStateException, java.io.IOException
This method may only be send in the following situations:
1. If post-open callbacks are requested, just before
activate()
is called. 2. If post-header callbacks are
requested, just before calls to read()
occur. 3. Once the
request entity has been fully read.
number
- The ID number (0..255) that identifies the callback to run on
the client.argsIn
- Arguments to pass to the remote callback. Format depends on
the function being called.
java.lang.IllegalArgumentException
EnhydraDirectorBadStateException
java.io.IOException
public int read(byte[] inBuf, int off, int len) throws java.io.IOException
len
request entity bytes.
If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns immediately when bytes become available and may read fewer bytes than the allocated buffer length.
inBuf
- Buffer to read into.off
- Offset within the buffer.len
- Number of bytes to read. The read will stop before reaching
the end of the buffer, so fewer than len
bytes
may be read if inBuf.length - off
is less than
len
.
java.io.IOException
public int read(byte[] inBuf) throws java.io.IOException
inBuf.length
bytes.
If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns immediately when bytes become available and may read fewer bytes than the allocated buffer length.
inBuf
- Buffer to read into.
java.io.IOException
public int read() throws java.io.IOException
Returns -1 if the end-of-data is reached.
java.io.IOException
- If an I/O error occurs.public int readExactly(byte[] inBuf, int off, int len) throws java.io.IOException
len
request entity bytes.
If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns only after the buffer is full, end-of-data is reached, or an error occurs. This is convenient when an exact number of bytes are expected.
The actual number of bytes read is returned. This may be less than the buffer length if an error occurs, or if end-of-data is reached.
inBuf
- Buffer to read into.
java.io.IOException
- If a network failure occurs.public int readExactly(byte[] inBuf) throws java.io.IOException
If no EOF or error condition occurs, at least one byte will be read into the buffer, up to the length of the buffer. This method returns only after the buffer is full, end-of-data is reached, or an error occurs. This is convenient when an exact number of bytes are expected.
The actual number of bytes read is returned. This may be less than the buffer length if an error occurs, or if end-of-data is reached.
inBuf
- Buffer to read into.
java.io.IOException
- If a network failure occurs.public long skip(long n) throws java.io.IOException
nbytes
bytes of entity input data.
Receives and discards n
bytes of entity data and returns
the number of bytes discarded. Returns 0 when end-of-data is reached, or
if n
is 0.
n
- The number of bytes to discard.
java.io.IOException
- If a network failure occurs.public void closeInput() throws java.io.IOException
java.io.IOException
- if an error occurs while discarding entity data. This
usually will cause the protocol to go out of sync.public int inputAvailable() throws java.io.IOException
No internal byte[] buffer is kept around. The read() methods read directly from the socket to the passed-in buffer. This means that the number of bytes guaranteed to be available in a non-blocking readExactly() is the minimum of the available bytes on the input socket, and the number of bytes remaining in the current incoming data packet. We can't just read the next packet header, because it may contain a callback, and thus require a block. We don't have a way to make the state machine go backwards in a "putback" fashion. (which would be ugly)
java.io.IOException
- If an I/O error occurs.protected long discardEntity() throws java.io.IOException
java.io.IOException
- If a network failure occurs.public void write(int b) throws java.io.IOException
java.io.IOException
public void write(byte[] buf) throws java.io.IOException
java.io.IOException
public void write(byte[] buf, int off, int len) throws java.io.IOException
java.io.IOException
public void closeOutput() throws java.io.IOException
java.io.IOException
public void closeConnection() throws java.io.IOException
java.io.IOException
public void sendHeader(java.lang.String name, java.lang.String value) throws java.io.IOException
java.io.IOException
public void sendCookie(java.lang.String name, java.lang.String value) throws java.io.IOException
java.io.IOException
public void finishHeaders() throws java.io.IOException
java.io.IOException
protected java.lang.String getStateName()
protected java.lang.String getStateName(int stateNum)
public java.lang.String toString()
Useful for debugging and logging.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |