org.locomotive.router
Class Router

java.lang.Object
  |
  +--org.locomotive.router.Router

public class Router
extends java.lang.Object
implements LocomotiveService

The router provides a mechanism for handling HTTP requests from clients and dispatching them to a locomotive, thereby eliminating the need for a web server to be able to run the locomotive.

The router listens for HTTP connections from clients, parses the headers and then either forwardis them to a locomotive or to a real web server, depending on the URL. The locomotive or web server are both optional, and can be run on either the same machine as the router or a different one.

Still to do: use the bean directory for configuration

Author:
Erik Erskine (erik@sundayta.co.uk)

Method Summary
 int getBacklog()
          Returns the maximum length of the queue of clients waiting at any given time.
 int getMaxPooledThreads()
          Returns the maximum number of threads used by the router.
 int getMinPooledThreads()
          Returns the minimum number of threads used by the router.
 int getPort()
          Returns the port this router uses.
 boolean isRunning()
          Return true if this service is running, false otherwise.
static void main(java.lang.String[] args)
          Startup method to use the router as a standalone application.
 void setBacklog(int backlog)
          Sets the maximum length of the queue of clients waiting at any given time.
 void setLocomotive(java.lang.String url, int port)
          Sets the address of the locomotive.
 void setMaxPooledThreads(int max)
          Sets the maximum number of threads used by the router.
 void setMinPooledThreads(int min)
          Sets the minimum number of threads used by the router.
 void setPort(int port)
          Sets the port this router will use.
 void setWebServer(java.lang.String url, int port)
          Sets the address of the web server.
 void startService()
          Start the service.
 void stopService()
          Stop the service.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

startService

public void startService()
                  throws ServiceException
Start the service.
Specified by:
startService in interface LocomotiveService

stopService

public void stopService()
                 throws ServiceException
Stop the service.
Specified by:
stopService in interface LocomotiveService

isRunning

public boolean isRunning()
Return true if this service is running, false otherwise.
Specified by:
isRunning in interface LocomotiveService

getPort

public int getPort()
Returns the port this router uses.
See Also:
setPort(int)

setPort

public void setPort(int port)
Sets the port this router will use.
See Also:
getPort()

getBacklog

public int getBacklog()
Returns the maximum length of the queue of clients waiting at any given time.
See Also:
setBacklog(int)

setBacklog

public void setBacklog(int backlog)
Sets the maximum length of the queue of clients waiting at any given time.
See Also:
getBacklog()

getMinPooledThreads

public int getMinPooledThreads()
Returns the minimum number of threads used by the router.
See Also:
setMinPooledThreads(int), getMaxPooledThreads(), setMaxPooledThreads(int)

setMinPooledThreads

public void setMinPooledThreads(int min)
Sets the minimum number of threads used by the router.
See Also:
getMinPooledThreads(), getMaxPooledThreads(), setMaxPooledThreads(int)

getMaxPooledThreads

public int getMaxPooledThreads()
Returns the maximum number of threads used by the router.
See Also:
getMinPooledThreads(), setMinPooledThreads(int), setMaxPooledThreads(int)

setMaxPooledThreads

public void setMaxPooledThreads(int max)
Sets the maximum number of threads used by the router.
See Also:
getMinPooledThreads(), setMinPooledThreads(int), getMaxPooledThreads()

setLocomotive

public void setLocomotive(java.lang.String url,
                          int port)
Sets the address of the locomotive.
Parameters:
url - the url as accessed from the router's machine
port - the port

setWebServer

public void setWebServer(java.lang.String url,
                         int port)
Sets the address of the web server.
Parameters:
url - the url as accessed from the router's machine
port - the port

main

public static void main(java.lang.String[] args)
Startup method to use the router as a standalone application.