org.ka2ddo.yaac.webserver
Class HttpServer

java.lang.Object
  extended by org.ka2ddo.yaac.webserver.HttpServer
All Implemented Interfaces:
java.lang.Runnable

public class HttpServer
extends java.lang.Object
implements java.lang.Runnable

This class implements a very simple HTTP server. It spawns a HttpConnectionThread instance for each incoming connection request.

See Also:
HttpConnectionThread

Constructor Summary
HttpServer(int listenPort, int refreshRateInSec, java.util.Map<java.lang.String,PathHandler> pathToHandlerMap)
          Create a HttpServer instance on the specified listening port.
 
Method Summary
 int getListenPort()
          Get the port the mini-webserver is currently listening on.
 java.util.Iterator<java.lang.String> getPathIterator()
          Obtain an Iterator across all the pages known to this web server.
 int getRefreshRateInSec()
          Get the automatic page refresh rate setting currently sent to browsers.
 void run()
          Accept incoming HTTP connection requests and spawn a handler thread for each browser connection.
 void setListenPort(int listenPort)
          Change the port number that the mini-webserver should listen on.
 void setRefreshRateInSec(int refreshRateInSec)
          Set the automatic page refresh rate setting currently sent to browsers.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpServer

public HttpServer(int listenPort,
                  int refreshRateInSec,
                  java.util.Map<java.lang.String,PathHandler> pathToHandlerMap)
Create a HttpServer instance on the specified listening port.

Parameters:
listenPort - TCP port number to accept incoming HTTP requests on
refreshRateInSec - refresh interval in seconds for web pages that do auto-refreshing
pathToHandlerMap - map of URL path strings to handler objects
Method Detail

run

public void run()
Accept incoming HTTP connection requests and spawn a handler thread for each browser connection.

Specified by:
run in interface java.lang.Runnable

getRefreshRateInSec

public int getRefreshRateInSec()
Get the automatic page refresh rate setting currently sent to browsers.

Returns:
page refresh rate in seconds between refreshes

setRefreshRateInSec

public void setRefreshRateInSec(int refreshRateInSec)
                         throws java.lang.IllegalArgumentException
Set the automatic page refresh rate setting currently sent to browsers.

Parameters:
refreshRateInSec - page refresh rate in seconds between refreshes
Throws:
java.lang.IllegalArgumentException - if specified refresh rate is shorter than 5 seconds

getListenPort

public int getListenPort()
Get the port the mini-webserver is currently listening on.

Returns:
TCP port number for YAAC's internal webserver

setListenPort

public void setListenPort(int listenPort)
Change the port number that the mini-webserver should listen on. Note this will not take effect until the next time YAAC is started. Changing this port number will shut down the existing listening socket for this HttpServer instance and create a new one on the new port number.

Parameters:
listenPort - TCP port number for YAAC's internal webserver

getPathIterator

public java.util.Iterator<java.lang.String> getPathIterator()
Obtain an Iterator across all the pages known to this web server.

Returns:
Iterator of Strings