## org.mortbay.util
Class ThreadedServer

    java.lang.Object
      |
      +--org.mortbay.util.ThreadPool
            |
            +--org.mortbay.util.ThreadedServer

All Implemented Interfaces:
  LifeCycle, java.io.Serializable

Direct Known Subclasses:
  AJP13Listener, 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.22.2.3 2004/03/30 10:28:42 gregwilkins Exp $
Author:
  Greg Wilkins
See Also:
  Serialized Form

Nested Class Summary

Nested classes inherited from class org.mortbay.util.ThreadPool
`ThreadPool.PoolThread`

Field Summary

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
`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` `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` `start()` Start the LifeCycle.
`void` `stop()` Stop the ThreadPool.
`java.lang.String` `toString()`

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
`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

### setInetAddrPort

    public void setInetAddrPort(InetAddrPort address)

  Set the server InetAddress and port.

  Parameters:
    `address` - The Address to listen on, or 0.0.0.0:port for all interfaces.

### getInetAddrPort

    public InetAddrPort getInetAddrPort()

  Returns:
    IP Address and port in a new Instance of InetAddrPort.

### setHost

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

  Parameters:
    `host` -
    `java.net.UnknownHostException`

### getHost

    public java.lang.String getHost()

  Returns:
    Host name

### setInetAddress

    public void setInetAddress(java.net.InetAddress addr)

  Parameters:
    `addr` -

### getInetAddress

    public java.net.InetAddress getInetAddress()

  Returns:
    IP Address

### setPort

    public void setPort(int port)

  Parameters:
    `port` -

### getPort

    public int getPort()

  Returns:
    port number

### setMaxReadTimeMs

    public void setMaxReadTimeMs(int ms)

  Deprecated. maxIdleTime is used instead.

  Set Max Read Time.

### getMaxReadTimeMs

    public int getMaxReadTimeMs()

  Returns:
    milliseconds

### setLingerTimeSecs

    public void setLingerTimeSecs(int ls)

  Parameters:
    `ls` - seconds to linger or -1 to disable linger.

### getLingerTimeSecs

    public int getLingerTimeSecs()

  Returns:
    seconds.

### handle

    public void handle(java.lang.Object job)

  Handle Job. Implementation of ThreadPool.handle(), calls handleConnection.

  Overrides:
    `handle` in class `ThreadPool`
  Parameters:
    `job` - A Connection.

### 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.

  Throws:
    `java.io.IOException` - if an error occurs

### start

    public void start()
               throws java.lang.Exception

  Description copied from interface: `LifeCycle`
  Start the LifeCycle.

  Specified by:
    `start` in interface `LifeCycle`
  Overrides:
    `start` in class `ThreadPool`
  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 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:
    `stop` in interface `LifeCycle`
  Overrides:
    `stop` in class `ThreadPool`
  Throws:
    `java.lang.InterruptedException` - Stopping a lifecycle is rarely atomic and may be interrupted by another thread. If this happens InterruptedException is throw and the component will be in an indeterminant state and should probably be discarded.

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

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