All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.webconcepts.net.MultiThreadServer

java.lang.Object
   |
   +----COM.webconcepts.net.MultiThreadServer

public class MultiThreadServer
extends Object
MultiThreadServer takes some of the drudgery out of writing network servers. It uses Java's metaclassing abilities to automatically create instances of service thread classes for a thread pool without knowing their type until run-time. Thus any threads that extend ServiceThread can be used to handle incoming clients; in theory it is possible to write a server without adding any code to MultiThreadServer except a main() method to run the server itself. You can concentrate on writing the protocol- specific client-handlign code and ignore the rest for the most part MultiThreadServer relies on a fixed, non-regenerating pool of threads. One possible line of improvement would be to add a monitor thread that watches for dying threads and replaces them with new ones.

See Also:
HttpProxyServer, ServiceThread, MultiThreadServer

Constructor Index

 o MultiThreadServer(Class, int)
creates a multi-threaded server with a default backlog size and thread pool size (5)
 o MultiThreadServer(Class, int, int)
creates a multi-threaded server with a default backlog size (5)
 o MultiThreadServer(Class, int, int, int)
creates a multi-threaded server

Method Index

 o getServerSocket()
returns the server socket
 o init()
init() populates the thread pool and starts each listener thread

Constructors

 o MultiThreadServer
 public MultiThreadServer(Class serviceThreadClass,
                          int servicePort)
creates a multi-threaded server with a default backlog size and thread pool size (5)

Parameters:
serviceThreadClass - the class to instantiate when creating threads
servicePort - the port to listen on for clients
 o MultiThreadServer
 public MultiThreadServer(Class serviceThreadClass,
                          int servicePort,
                          int threadPoolSize)
creates a multi-threaded server with a default backlog size (5)

Parameters:
serviceThreadClass - the class to instantiate when creating threads
servicePort - the port to listen on for clients
threadPoolSize - the number of service threads to create
 o MultiThreadServer
 public MultiThreadServer(Class serviceThreadClass,
                          int servicePort,
                          int threadPoolSize,
                          int backlogSize)
creates a multi-threaded server

Parameters:
serviceThreadClass - the class to instantiate when creating threads
servicePort - the port to listen on for clients
threadPoolSize - the number of service threads to create
backlogSize - the maximum number of clients to keep waiting for a free thread

Methods

 o init
 public void init() throws IOException, InstantiationException, IllegalAccessException
init() populates the thread pool and starts each listener thread

Throws: IOException
if there are network errors with the server socket
Throws: InstantiationException
if there are problems creating service threads
Throws: IllegalAccessException
if there are problems finding the service thread class
 o getServerSocket
 public ServerSocket getServerSocket()
returns the server socket

Returns:
a reference to the server socket

All Packages  Class Hierarchy  This Package  Previous  Next  Index