: Class ThreadedServer

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.mortbay.Util
Class ThreadedServer

    java.lang.Object
      |
      +--com.mortbay.Util.ThreadedServer

Direct Known Subclasses:
  HttpListener, InetGateway

public abstract class ThreadedServer
extends java.lang.Object
implements java.lang.Runnable

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 2.27 2000/10/22 22:17:39 gregwilkins Exp $
Author:
  Greg Wilkins

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(InetAddrPort address, int minThreads, int maxThreads, int maxIdleTime)` Constructor.
`ThreadedServer(int port)` Construct for specific port
`ThreadedServer(java.lang.String name)`

Method Summary
`protected java.net.Socket` | `accept(java.net.ServerSocket serverSocket)` Accept socket connection.
`java.net.InetAddress` | `address()` Deprecated. Use getInetAddress()
`java.net.InetAddress` | `getInetAddress()`
`InetAddrPort` | `getInetAddrPort()`
`int` | `getMaxIdleTimeMs()`
`int` | `getMaxSize()`
`int` | `getMinSize()`
`int` | `getPort()`
`int` | `getSize()`
`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.
`protected void` | `handleConnection(java.net.Socket connection)` Handle new connection If access is required to the actual socket, override this method instead of handleConnection(InputStream in,OutputStream out).
`void` | `join()`
`protected java.net.ServerSocket` | `newServerSocket(InetAddrPort address, int acceptQueueSize)` New server socket.
`int` | `port()` Deprecated. Use getPort()
`void` | `run()`
`void` | `setAddress(java.net.InetAddress address, int port)`
`void` | `setAddress(InetAddrPort address)`
`void` | `setThreadClass(java.lang.Class threadClass)` Set the Thread class.
`void` | `start()`
`void` | `stop()`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### ThreadedServer

    public ThreadedServer()

### ThreadedServer

    public ThreadedServer(java.lang.String name)

### ThreadedServer

    public ThreadedServer(int port)
                   throws java.io.IOException

  Construct for specific port

### ThreadedServer

    public ThreadedServer(java.net.InetAddress address,
                          int port)
                   throws java.io.IOException

  Construct for specific address and port

### ThreadedServer

    public ThreadedServer(InetAddrPort address)
                   throws java.io.IOException

  Construct for specific address and port

### ThreadedServer

    public ThreadedServer(InetAddrPort address,
                          int minThreads,
                          int maxThreads,
                          int maxIdleTime)
                   throws java.io.IOException

  Constructor.
  Parameters:
    `address` - The address to listen on
    `minThreads` - Minimum number of handler threads.
    `maxThreads` - Maximum number of handler threads.
    `maxIdleTime` - Idle time in milliseconds before a handler thread dies.
  Throws:
    java.io.IOException - Problem listening to the socket.

Method Detail

### setThreadClass

    public void setThreadClass(java.lang.Class threadClass)

  Set the Thread class. Sets the class used for threads in the thread pool. The class must have a constractor taking a Runnable.
  Parameters:
    `threadClass` -

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

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

### getInetAddrPort

    public InetAddrPort getInetAddrPort()

  Returns:
    IP Address and port

### address

    public java.net.InetAddress address()

  Deprecated. Use getInetAddress()

  Returns:
    IP Address

### getInetAddress

    public java.net.InetAddress getInetAddress()

  Returns:
    IP Address

### port

    public int port()

  Deprecated. Use getPort()

  Returns:
    port number

### getPort

    public int getPort()

  Returns:
    port number

### getSize

    public int getSize()

### getMinSize

    public int getMinSize()

### getMaxSize

    public int getMaxSize()

### getMaxIdleTimeMs

    public int getMaxIdleTimeMs()

### setAddress

    public void setAddress(java.net.InetAddress address,
                           int port)
                    throws java.io.IOException

### setAddress

    public void setAddress(InetAddrPort address)
                    throws java.io.IOException

### 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).
  Parameters:
    `address` - Address and port
    `acceptQueueSize` - Accept queue size
  Returns:
    The new ServerSocket
  Throws:
    java.io.IOException -

### accept

    protected java.net.Socket accept(java.net.ServerSocket serverSocket)
                              throws java.io.IOException

  Accept socket connection. May be overriden by derived class to create specialist serversockets (eg SSL).
  Parameters:
    `serverSocket` -
  Returns:
    Accepted Socket
  Throws:
    java.io.IOException -

### start

    public void start()
               throws java.io.IOException

### stop

    public void stop()

### join

    public final void join()
                    throws java.lang.InterruptedException

### run

    public final void run()

  Specified by:
    run in interface java.lang.Runnable

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD