|
|||||||||
| Home >> All >> org >> mortbay >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.mortbay.util
Class ThreadedServer

java.lang.Objectorg.mortbay.util.ThreadPool
org.mortbay.util.ThreadedServer
- All Implemented Interfaces:
- LifeCycle, java.io.Serializable
- Direct Known Subclasses:
- TestThreadedServer.TestServer
- public abstract class ThreadedServer
- extends ThreadPool
Threaded socket server. This class listens at a socket and gives the connections received to a pool of Threads
The class is abstract and derived classes must provide the handling for the connections.
The properties THREADED_SERVER_MIN_THREADS and THREADED_SERVER_MAX_THREADS can be set to control the number of threads created.
- Version:
- $Id: ThreadedServer.java,v 1.28 2003/10/05 23:46:29 gregwilkins Exp $
| Nested Class Summary | |
private class |
ThreadedServer.Acceptor
|
| Nested classes inherited from class org.mortbay.util.ThreadPool |
ThreadPool.PoolThread |
| Field Summary | |
private ThreadedServer.Acceptor |
_acceptor
|
private InetAddrPort |
_address
|
private int |
_lingerTimeSecs
|
private java.net.ServerSocket |
_listen
|
private boolean |
_running
|
private int |
_soTimeOut
|
private boolean |
_tcpNoDelay
|
private static org.apache.commons.logging.Log |
log
|
| Fields inherited from class org.mortbay.util.ThreadPool |
__DAEMON, __PRIORITY |
| Constructor Summary | |
ThreadedServer()
|
|
ThreadedServer(java.net.InetAddress address,
int port)
Construct for specific address and port. |
|
ThreadedServer(InetAddrPort address)
Construct for specific address and port. |
|
ThreadedServer(int port)
Construct for specific port. |
|
ThreadedServer(java.lang.String host,
int port)
Construct for specific address and port. |
|
| Method Summary | |
protected java.net.Socket |
acceptSocket(java.net.ServerSocket serverSocket,
int timeout)
Accept socket connection. |
java.lang.String |
getHost()
|
java.net.InetAddress |
getInetAddress()
|
InetAddrPort |
getInetAddrPort()
|
int |
getLingerTimeSecs()
|
int |
getMaxReadTimeMs()
|
int |
getPort()
|
java.net.ServerSocket |
getServerSocket()
|
boolean |
getTcpNoDelay()
|
void |
handle(java.lang.Object job)
Handle Job. |
protected void |
handleConnection(java.io.InputStream in,
java.io.OutputStream out)
Handle new connection. |
protected void |
handleConnection(java.net.Socket connection)
Handle new connection. |
protected java.net.ServerSocket |
newServerSocket(InetAddrPort address,
int acceptQueueSize)
New server socket. |
void |
open()
Open the server socket. |
void |
setHost(java.lang.String host)
|
void |
setInetAddress(java.net.InetAddress addr)
|
void |
setInetAddrPort(InetAddrPort address)
Set the server InetAddress and port. |
void |
setLingerTimeSecs(int ls)
|
void |
setMaxReadTimeMs(int ms)
Deprecated. maxIdleTime is used instead. |
void |
setPort(int port)
|
void |
setTcpNoDelay(boolean tcpNoDelay)
|
void |
start()
Start the LifeCycle. |
void |
stop()
Stop the ThreadPool. |
protected void |
stopJob(java.lang.Thread thread,
java.lang.Object job)
Kill a job. |
java.lang.String |
toString()
Convert this Object to a human-readable String. |
| Methods inherited from class org.mortbay.util.ThreadPool |
getIdleThreads, getMaxIdleTimeMs, getMaxThreads, getMinThreads, getName, getPoolName, getThreads, getThreadsPriority, isDaemon, isStarted, join, run, setDaemon, setMaxIdleTimeMs, setMaxStopTimeMs, setMaxThreads, setMinThreads, setName, setPoolName, setThreadsPriority, shrink |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
log
private static org.apache.commons.logging.Log log
_address
private InetAddrPort _address
_soTimeOut
private int _soTimeOut
_lingerTimeSecs
private int _lingerTimeSecs
_tcpNoDelay
private boolean _tcpNoDelay
_acceptor
private transient ThreadedServer.Acceptor _acceptor
_listen
private transient java.net.ServerSocket _listen
_running
private transient boolean _running
| Constructor Detail |
ThreadedServer
public ThreadedServer()
ThreadedServer
public ThreadedServer(int port)
- Construct for specific port.
ThreadedServer
public ThreadedServer(java.net.InetAddress address, int port)
- Construct for specific address and port.
ThreadedServer
public ThreadedServer(java.lang.String host, int port) throws java.net.UnknownHostException
- Construct for specific address and port.
ThreadedServer
public ThreadedServer(InetAddrPort address)
- Construct for specific address and port.
| Method Detail |
getServerSocket
public java.net.ServerSocket getServerSocket()
setInetAddrPort
public void setInetAddrPort(InetAddrPort address)
- Set the server InetAddress and port.
getInetAddrPort
public InetAddrPort getInetAddrPort()
setHost
public void setHost(java.lang.String host) throws java.net.UnknownHostException
getHost
public java.lang.String getHost()
setInetAddress
public void setInetAddress(java.net.InetAddress addr)
getInetAddress
public java.net.InetAddress getInetAddress()
setPort
public void setPort(int port)
getPort
public int getPort()
setMaxReadTimeMs
public void setMaxReadTimeMs(int ms)
- Deprecated. maxIdleTime is used instead.
- Set Max Read Time.
- Set Max Read Time.
getMaxReadTimeMs
public int getMaxReadTimeMs()
setLingerTimeSecs
public void setLingerTimeSecs(int ls)
getLingerTimeSecs
public int getLingerTimeSecs()
setTcpNoDelay
public void setTcpNoDelay(boolean tcpNoDelay)
getTcpNoDelay
public boolean getTcpNoDelay()
handleConnection
protected void handleConnection(java.io.InputStream in, java.io.OutputStream out)
- Handle new connection.
This method should be overridden by the derived class to implement
the required handling. It is called by a thread created for it and
does not need to return until it has finished it's task
handleConnection
protected void handleConnection(java.net.Socket connection) throws java.io.IOException
- Handle new connection.
If access is required to the actual socket, override this method
instead of handleConnection(InputStream in,OutputStream out).
The default implementation of this just calls
handleConnection(InputStream in,OutputStream out).
handle
public void handle(java.lang.Object job)
- Handle Job.
Implementation of ThreadPool.handle(), calls handleConnection.
- Overrides:
handlein classThreadPool
newServerSocket
protected java.net.ServerSocket newServerSocket(InetAddrPort address, int acceptQueueSize) throws java.io.IOException
- New server socket.
Creates a new servers socket. May be overriden by derived class
to create specialist serversockets (eg SSL).
acceptSocket
protected java.net.Socket acceptSocket(java.net.ServerSocket serverSocket, int timeout)
- Accept socket connection.
May be overriden by derived class
to create specialist serversockets (eg SSL).
open
public void open()
throws java.io.IOException
- Open the server socket.
This method can be called to open the server socket in advance of starting the
listener. This can be used to test if the port is available.
start
public void start()
throws java.lang.Exception
- Description copied from interface:
LifeCycle - Start the LifeCycle.
- Specified by:
startin interfaceLifeCycle- Overrides:
startin classThreadPool
stop
public void stop()
throws java.lang.InterruptedException
- Description copied from class:
ThreadPool - Stop the ThreadPool.
New jobs are no longer accepted,idle threads are interrupted
and stopJob is called on active threads.
The method then waits
min(getMaxStopTimeMs(),getMaxIdleTimeMs()), for all jobs to
stop, at which time killJob is called.
- Specified by:
stopin interfaceLifeCycle- Overrides:
stopin classThreadPool
stopJob
protected void stopJob(java.lang.Thread thread, java.lang.Object job)
- Kill a job.
This method closes IDLE and socket associated with a job
- Overrides:
stopJobin classThreadPool
toString
public java.lang.String toString()
- Description copied from class:
java.lang.Object - Convert this Object to a human-readable String.
There are no limits placed on how long this String
should be or what it should contain. We suggest you
make it as intuitive as possible to be able to place
it into System.out.println() 55
and such.
It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.
This method will be called when performing string concatenation with this object. If the result is
null, string concatenation will instead use"null".The default implementation returns
getClass().getName() + "@" + Integer.toHexString(hashCode()).
|
|||||||||
| Home >> All >> org >> mortbay >> [ util overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC