org.mortbay.util
Class ThreadedServer

java.lang.Object
  |
  +--org.mortbay.util.ThreadPool
        |
        +--org.mortbay.util.ThreadedServer
All Implemented Interfaces:
LifeCycle
Direct Known Subclasses:
SocketListener

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.6 2001/10/18 00:47:14 gregwilkins Exp $
Author:
Greg Wilkins

Inner classes inherited from class org.mortbay.util.ThreadPool
ThreadPool.PoolThread
 
Fields inherited from class org.mortbay.util.ThreadPool
__nullLockChecks
 
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
 void destroy()
          Destroy the ThreadPool.
 java.lang.String getHost()
           
 java.net.InetAddress getInetAddress()
           
 InetAddrPort getInetAddrPort()
           
 int getLingerTimeSecs()
           
 int getMaxReadTimeMs()
           
 int getPort()
           
 java.net.ServerSocket getServerSocket()
           
 void handle(java.lang.Object job)
          Handle Job.
 void setAddress(InetAddrPort address)
          Set the server InetAddress and port.
 void setHost(java.lang.String host)
           
 void setInetAddress(java.net.InetAddress addr)
           
 void setLingerTimeSecs(int ls)
           
 void setMaxReadTimeMs(int ms)
          Set Max Read Time.
 void setPort(int port)
           
 void start()
          Start the LifeCycle.
 void stop()
          Stop the ThreadPool.
 java.lang.String toString()
           
 
Methods inherited from class org.mortbay.util.ThreadPool
getIdleThreads, getMaxIdleTimeMs, getMaxSize, getMaxStopTimeMs, getMaxThreads, getMinSize, getMinThreads, getName, getSize, getThreadClass, getThreads, initialize, isDestroyed, isStarted, join, run, setMaxIdleTimeMs, setMaxSize, setMaxStopTimeMs, setMaxThreads, setMinSize, setMinThreads, setName, setThreadClass
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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()
Returns:
The ServerSocket

setAddress

public void setAddress(InetAddrPort address)
Set the server InetAddress and port.
Parameters:
address - The Address to listen on, or 0.0.0.0:port for all interfaces.

setHost

public void setHost(java.lang.String host)
             throws java.net.UnknownHostException
Parameters:
host -  

setInetAddress

public void setInetAddress(java.net.InetAddress addr)
Parameters:
addr -  

setPort

public void setPort(int port)
Parameters:
port -  

setMaxReadTimeMs

public void setMaxReadTimeMs(int ms)
Set Max Read Time. Setting this to a none zero value results in setSoTimeout being called for all accepted sockets. This causes an InterruptedIOException if a read blocks for this period of time.
Parameters:
ms - Max read time in ms or 0 for no limit.

getMaxReadTimeMs

public int getMaxReadTimeMs()
Returns:
milliseconds

setLingerTimeSecs

public void setLingerTimeSecs(int ls)
Parameters:
sec - seconds to linger or -1 to disable linger.

getLingerTimeSecs

public int getLingerTimeSecs()
Returns:
seconds.

getInetAddrPort

public InetAddrPort getInetAddrPort()
Returns:
IP Address and port in a new Instance of InetAddrPort.

getInetAddress

public java.net.InetAddress getInetAddress()
Returns:
IP Address

getHost

public java.lang.String getHost()
Returns:
Host name

getPort

public int getPort()
Returns:
port number

handle

public void handle(java.lang.Object job)
Handle Job. Implementation of ThreadPool.handle(), calls handleConnection.
Parameters:
job - A Connection.

start

public void start()
           throws java.lang.Exception
Description copied from interface: LifeCycle
Start the LifeCycle.
Overrides:
start in class ThreadPool
Following copied from interface: org.mortbay.util.LifeCycle
Throws:
java.lang.Exception - An arbitrary exception may be thrown.

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
Overrides:
stop in class ThreadPool

destroy

public void destroy()
Description copied from class: ThreadPool
Destroy the ThreadPool. All threads are interrupted and if they do not terminate after a short delay, they are stopped.
Overrides:
destroy in class ThreadPool

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.