|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object atg.nucleus.logging.VariableArgumentApplicationLoggingImpl atg.nucleus.GenericService atg.nucleus.TimedOperationService atg.server.tcp.RequestServer
public class RequestServer
This is the base class for Nucleus services that handle TCP requests. This will create a set of RequestServerHandler objects to handle incoming connections. This class understands the ServerImpl interface, in that it knows how to start and stop itself.
This class also keeps basic statistics about its operation, including total number of requests served, current number of requests being served, and average time spent on each request.
Subclasses should override the "createHandler" method to create a new subclass of RequestServerHandler.
The server can be configured to run in "standby" or "one-shot" mode. In "standby" mode, a number of handler threads are created at startup and kept around to handle requests. That number is specified by the property "handlerCount". In "one-shot" mode, handlers are created whenever a request comes in and destroyed after the request is complete. No handlers are kept around in this case. This mode is triggered by setting "handlerCount" to 0.
Field Summary | |
---|---|
static java.lang.String |
CLASS_VERSION
Class version string |
static int |
DEFAULT_BACKLOG
The default number of connections that get queued up to a "connect" system call. |
protected java.lang.String |
mAllowedConnection
Set to a regular expression pattern of ip addresses allowed to connect |
protected atg.core.util.MiniRegex |
mAllowedConnectionMatcher
The regular expression matcher for ip addresses |
protected int |
mBacklog
The backlog, or 0 if default |
protected boolean |
mEnabled
If false, prevent this server from starting up |
protected int |
mHandlerCount
The number of handlers |
protected java.net.InetAddress |
mHostAddr
The host address of the server |
protected java.lang.String |
mHostName
The hostname of the server |
protected int |
mLocalPort
This is the actual port we are listening on. |
protected int |
mPort
The port this will use to listen for connections |
protected atg.service.portregistry.PortRegistry |
mPortRegistry
The PortRegistry to whom this will report its port usage |
protected int |
mReadTimeout
Maximum number of seconds (not millis) to block while reading input. |
Fields inherited from class atg.nucleus.GenericService |
---|
SERVICE_INFO_KEY |
Fields inherited from interface atg.nucleus.logging.TraceApplicationLogging |
---|
DEFAULT_LOG_TRACE_STATUS |
Fields inherited from interface atg.nucleus.logging.ApplicationLogging |
---|
DEFAULT_LOG_DEBUG_STATUS, DEFAULT_LOG_ERROR_STATUS, DEFAULT_LOG_INFO_STATUS, DEFAULT_LOG_WARNING_STATUS |
Constructor Summary | |
---|---|
RequestServer()
Constructs a new RequestServer |
Method Summary | |
---|---|
java.net.Socket |
acceptConnection()
Accepts and returns one connection. |
void |
acceptConnections()
Repeatedly accepts connections and spins off handlers to handle those connections. |
RequestServerHandler |
createAndStartHandler()
Constructs and starts a new RequestServerHandler without any socket. |
RequestServerHandler |
createAndStartHandlerIfNeeded(RequestServerHandler handler,
int deathType)
Called when a RequestServerHandler changes state, either from being turned into a zombie or from see if a new handler should be started socket. |
protected RequestServerHandler |
createHandler(java.lang.ThreadGroup pGroup,
java.lang.String pThreadName,
java.net.Socket pSocket)
Constructs a new RequestServerHandler. |
protected java.net.ServerSocket |
createServerSocket(int pPort,
int pBacklog,
java.net.InetAddress pHostAddr)
Create a ServerSocket used by the RequestServer. |
void |
doStartService()
If the server is enabled this will start the server running, and create the minimum number of clients. |
void |
doStopService()
This will stop the server from running by shutting down the server socket. |
int |
getAcceptorPriorityDelta()
Gets the acceptor thread priority delta. |
int |
getActiveHandlerCount()
Returns the number of handlers currently handling requests. |
java.lang.String |
getAllowedConnection()
Returns the AllowedConnection property. |
int |
getBacklog()
Returns the backlog that will be set to the server socket. |
boolean |
getCloseSocketWhenStopped()
Close the listener socket when this server is stopped? |
atg.server.tcp.ConnectionAcceptor |
getConnectionAcceptor()
Returns the connection acceptor used to acquire connected clients for the handler threads. |
boolean |
getEnabled()
Returns the Enabled property. |
int |
getHandlerCount()
Returns the number of handlers that will be used to listen for requests. |
java.net.InetAddress |
getHostAddr()
Returns the host address of the server |
java.lang.String |
getHostName()
Returns the hostname of the server |
int |
getLocalPort()
Returns the port this server is listening on. |
int |
getMaxZombieHandlerCount()
Returns the maximum number of handlers that can be in a killed state. |
int |
getNewHandlerRequestCount()
Returns the number of handlers which have been requested, but have not yet started. |
int |
getPort()
Returns the port this server is listening on. |
atg.service.portregistry.PortRegistry |
getPortRegistry()
Returns the PortRegistry to whom this will report which port this is using. |
int |
getReadTimeout()
Gets the maximum number of seconds (not millis) to block when reading input. |
RequestServerHandler[] |
getRequestHandlers()
Returns an array of the RequestHandler objects running in the server. |
protected atg.server.tcp.RequestServerSocket |
getRequestServerSocket()
|
int |
getRunningHandlerCount()
Returns the total number of handlers, including those that are currently handling connections, and those that are waiting for connections. |
javax.net.ServerSocketFactory |
getServerSocketFactory()
Returns property ServerSocketFactory |
long |
getWaitForRequestHandlersToStop()
Gets the amount of time in milliseconds to wait until all request handlers have completed, during doStopService() |
int |
getWaitingHandlerCount()
Returns the number of handlers waiting for new requests. |
int |
getZombieHandlerCount()
Returns the number of handlers which have been killed, but have not yet handled the ThreadDeath. |
boolean |
isOutOfMemoryDetected()
Was an out of memory exception detected? |
boolean |
isSuccessfulServerStartup()
get SuccessfulServerStartup |
boolean |
isUseServerSocketFactory()
Returns property UseServerSocketFactory |
void |
setAcceptorPriorityDelta(int pDelta)
Sets the acceptor thread priority delta. |
void |
setAllowedConnection(java.lang.String pAllowedConnection)
Sets a regular expression against which connecting hosts are matched to see if they are allowed to connect. |
void |
setBacklog(int pBacklog)
Sets the backlog that will be set to the server socket. |
void |
setCloseSocketWhenStopped(boolean pClose)
Close the listener socket when this server is stopped? |
void |
setConnectionAcceptor(atg.server.tcp.ConnectionAcceptor pAcceptor)
Changes the connection acceptor used to acquire connected clients for the handler threads. |
void |
setEnabled(boolean pEnabled)
Sets the Enabled flag. |
void |
setHandlerCount(int pHandlerCount)
Sets the number of handlers that will be used to listen for requests. |
void |
setHostAddr(java.net.InetAddress pHostAddr)
Sets the host address of the server |
void |
setHostName(java.lang.String pHostName)
Sets the host name explicitly. |
void |
setMaxZombieHandlerCount(int pMaxZombieHandlerCount)
Sets the maximum number of handlers that can be in a killed state. |
void |
setOutOfMemoryDetected(boolean pOutOfMemoryDetected)
Was an out of memory exception detected? |
void |
setPort(int pPort)
Sets the port this uses to listen for connections. |
void |
setPortRegistry(atg.service.portregistry.PortRegistry pPortRegistry)
Sets the PortRegistry to whom this will report which port this is using. |
void |
setReadTimeout(int pReadTimeout)
Sets the maximum number of seconds (not millis) to block when reading input. |
void |
setServerSocketFactory(javax.net.ServerSocketFactory pServerSocketFactory)
Sets property ServerSocketFactory |
void |
setSocketReadTimeout(java.net.Socket pSocket)
Attempt to set the read timeout for the specified socket. |
void |
setSuccessfulServerStartup(boolean pSuccessfulServerStartup)
set SuccessfulServerStartup |
void |
setUseServerSocketFactory(boolean pUseServerSocketFactory)
Sets property UseServerSocketFactory |
void |
setWaitForRequestHandlersToStop(long pWait)
Sets the amount of time in milliseconds to wait until all request handlers have completed, during doStopService() |
void |
startServer()
This will start the server running, and create the minimum number of handlers. |
Methods inherited from class atg.nucleus.TimedOperationService |
---|
getAverageRequestHandlingTime, getHandledRequestCount, getRequestStartTime, getTotalRequestHandlingTime, isKeepingStatistics, notifyHandledRequest, resetStatistics, setKeepingStatistics |
Methods inherited from class atg.nucleus.logging.VariableArgumentApplicationLoggingImpl |
---|
vlogDebug, vlogDebug, vlogDebug, vlogDebug, vlogDebugTrace, vlogError, vlogError, vlogError, vlogError, vlogInfo, vlogInfo, vlogInfo, vlogInfo, vlogTrace, vlogTrace, vlogTrace, vlogTrace, vlogWarning, vlogWarning, vlogWarning, vlogWarning |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static java.lang.String CLASS_VERSION
public static final int DEFAULT_BACKLOG
protected int mPort
protected int mLocalPort
protected java.lang.String mHostName
protected java.net.InetAddress mHostAddr
protected int mHandlerCount
protected int mBacklog
protected atg.service.portregistry.PortRegistry mPortRegistry
protected boolean mEnabled
protected java.lang.String mAllowedConnection
protected atg.core.util.MiniRegex mAllowedConnectionMatcher
protected int mReadTimeout
Constructor Detail |
---|
public RequestServer()
Method Detail |
---|
protected atg.server.tcp.RequestServerSocket getRequestServerSocket()
public RequestServerHandler createAndStartHandler()
protected RequestServerHandler createHandler(java.lang.ThreadGroup pGroup, java.lang.String pThreadName, java.net.Socket pSocket)
pGroup
- the ThreadGroup to which the new handler should belongpThreadName
- the name that should be assigned to the
handler's thread.pSocket
- the socket that the handler should use to perform
its one-shot request. If null, then the handler should obtain
sockets by calling "acceptConnection".public RequestServerHandler createAndStartHandlerIfNeeded(RequestServerHandler handler, int deathType)
public java.net.Socket acceptConnection() throws DisallowedConnectionException
DisallowedConnectionException
public void acceptConnections()
public void setPort(int pPort)
public int getPort()
public int getLocalPort()
public java.net.InetAddress getHostAddr()
public void setHostAddr(java.net.InetAddress pHostAddr)
public void setHostName(java.lang.String pHostName)
public java.lang.String getHostName()
public void setServerSocketFactory(javax.net.ServerSocketFactory pServerSocketFactory)
public javax.net.ServerSocketFactory getServerSocketFactory()
public void setUseServerSocketFactory(boolean pUseServerSocketFactory)
public boolean isUseServerSocketFactory()
public void setHandlerCount(int pHandlerCount)
public int getMaxZombieHandlerCount()
public void setMaxZombieHandlerCount(int pMaxZombieHandlerCount)
public int getHandlerCount()
public void setBacklog(int pBacklog)
public int getBacklog()
public void setPortRegistry(atg.service.portregistry.PortRegistry pPortRegistry)
public atg.service.portregistry.PortRegistry getPortRegistry()
public void setEnabled(boolean pEnabled)
public boolean getEnabled()
public void setSuccessfulServerStartup(boolean pSuccessfulServerStartup)
pSuccessfulServerStartup
- the SuccessfulServerStartuppublic boolean isSuccessfulServerStartup()
public void setAllowedConnection(java.lang.String pAllowedConnection)
public java.lang.String getAllowedConnection()
public void setAcceptorPriorityDelta(int pDelta)
This property is only used by the DRP server in connection pooling mode.
public long getWaitForRequestHandlersToStop()
public void setWaitForRequestHandlersToStop(long pWait)
public int getAcceptorPriorityDelta()
This property is only used by the DRP server in connection pooling mode.
public void setReadTimeout(int pReadTimeout)
int
- the maximum number of secondspublic int getReadTimeout()
public int getRunningHandlerCount()
public int getActiveHandlerCount()
public int getZombieHandlerCount()
public int getNewHandlerRequestCount()
public int getWaitingHandlerCount()
public boolean getCloseSocketWhenStopped()
public void setCloseSocketWhenStopped(boolean pClose)
public atg.server.tcp.ConnectionAcceptor getConnectionAcceptor()
public void setConnectionAcceptor(atg.server.tcp.ConnectionAcceptor pAcceptor)
public boolean isOutOfMemoryDetected()
public void setOutOfMemoryDetected(boolean pOutOfMemoryDetected)
public RequestServerHandler[] getRequestHandlers()
protected java.net.ServerSocket createServerSocket(int pPort, int pBacklog, java.net.InetAddress pHostAddr) throws java.io.IOException
pPort
- port number on which to listenpBacklog
- the backlog of pending connection before rejection of connectionspHostAddr
- host address of network interface where connections accepted
java.io.IOException
- is an erro occured while creating the ServerSocketpublic void startServer()
public void doStartService() throws ServiceException
doStartService
in class GenericService
ServiceException
- if there was a problempublic void doStopService() throws ServiceException
doStopService
in class GenericService
ServiceException
- if an error occurred during the operationpublic void setSocketReadTimeout(java.net.Socket pSocket)
Socket
- -- the socket whose read timeout to set
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |