com.cometway.httpd
Class HTTPThrottledFileServer

java.lang.Object
  extended by com.cometway.props.Props
      extended by com.cometway.ak.Agent
          extended by com.cometway.ak.ServiceAgent
              extended by com.cometway.httpd.WebServerExtension
                  extended by com.cometway.httpd.HTTPFileServerAgent
                      extended by com.cometway.httpd.HTTPThrottledFileServer
All Implemented Interfaces:
AgentInterface, HasStateMachineModel

public class HTTPThrottledFileServer
extends HTTPFileServerAgent

This agent is used by the WebServer to handle requests for HTML files and other static documents from the file system. It is a subclass of the HTTPFileServerAgent and used in place of the HTTPFileServerAgent when content needs to be throttled at a certain bandwidth. This agent provides additional options for logging the amount of bandwidth used, limiting the maximum number of concurrent downloading sessions, and the ammount of bandwidth each connection can use.


Field Summary
protected  int currentSessions
           
protected  java.lang.String html_directory
           
protected  java.io.FileWriter logOut
           
protected  java.lang.Object sync
           
 
Fields inherited from class com.cometway.ak.Agent
agent_id, agentController, CREATING_STATE, debugReporter, DESTROYED_STATE, DESTROYING_STATE, errorReporter, FAILED_STATE, printlnReporter, props, RUNNING_STATE, STARTING_STATE, STOPPED_STATE, STOPPING_STATE, warningReporter
 
Constructor Summary
HTTPThrottledFileServer()
           
 
Method Summary
protected  boolean addSession()
          This method is used to internally track the number of active sessions.
 void initProps()
          Initializes this agent's properties by providing default values for each of the following missing properties: "service_name" is used to register this agent with the Service Manager (default: HTTPThrottledFileServer), "html_directory" points to the root directory where HTML files are served (default: ./), "default_index" is the default file served when no filename is specified (default: index.html), "allow_directory_lists" when enabled, allows this agent to display links to files in a directory (default: yes) "max_sessions" denotes the maximum amount of concurrent connections downloading content at a single time (default: 4) "max_bandwidth" denotes the amount of bytes per second allowed for each connection (default: 5000) "log_file" denotes the file which bandwidth usage is to be logged (default: downloads.log)
protected  void printLog(java.lang.String logString, HTTPAgentRequest request)
          This method is used by this Agent to log bandwidth related information to the log file.
protected  void printTryAgain(HTTPAgentRequest request)
          This method generates the message when the maximum number of connections has been reached.
protected  void removeSession()
          This method is used to internally track the number of active sessions.
protected  void sendFile(java.io.File file, HTTPAgentRequest request)
           
 void start()
          Registers Server and sets up directories, url's, etc.
 void stop()
          Unregisters this instance with the service manager using the service_name property.
 
Methods inherited from class com.cometway.httpd.HTTPFileServerAgent
generateDirectoryList, handleRequest, isKeepAlive, printRedirect
 
Methods inherited from class com.cometway.ak.Agent
currentStateEquals, debug, destroy, error, error, getAgentController, getDateTimeStr, getProps, getServiceImpl, getStateMachineModel, println, register, registerService, setAgentController, setProps, toString, unregister, unregisterService, warning, warning
 
Methods inherited from class com.cometway.props.Props
addListener, append, copy, copyFrom, copyTo, decrementInteger, dump, enableListeners, enumerateKeys, format, getBoolean, getByteArray, getCharacter, getDate, getDate, getDateString, getDouble, getFloat, getHexString, getInteger, getKeys, getLong, getNextKey, getProperty, getProperty, getPropsContainer, getSize, getString, getString, getTokens, getTokens, getTrimmedString, getVector, hasProperty, incrementInteger, insertProps, loadProps, notifyPropsChanged, notifyPropsChangedIgnore, notifyPropsChangedIgnore, parse, propertyMatchesRegEx, readFromFile, regExPropertyMatches, removeAll, removeListener, removeProperty, resumeNotify, saveProps, set, setBoolean, setCharacter, setDefault, setDouble, setFloat, setInteger, setLong, setProperty, setProperty, setProperty, setPropsContainer, suspendNotify, writeToFile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

html_directory

protected java.lang.String html_directory

currentSessions

protected int currentSessions

sync

protected java.lang.Object sync

logOut

protected java.io.FileWriter logOut
Constructor Detail

HTTPThrottledFileServer

public HTTPThrottledFileServer()
Method Detail

initProps

public void initProps()
Initializes this agent's properties by providing default values for each of the following missing properties: "service_name" is used to register this agent with the Service Manager (default: HTTPThrottledFileServer), "html_directory" points to the root directory where HTML files are served (default: ./), "default_index" is the default file served when no filename is specified (default: index.html), "allow_directory_lists" when enabled, allows this agent to display links to files in a directory (default: yes) "max_sessions" denotes the maximum amount of concurrent connections downloading content at a single time (default: 4) "max_bandwidth" denotes the amount of bytes per second allowed for each connection (default: 5000) "log_file" denotes the file which bandwidth usage is to be logged (default: downloads.log)

Specified by:
initProps in interface AgentInterface
Overrides:
initProps in class HTTPFileServerAgent

start

public void start()
Registers Server and sets up directories, url's, etc.

Specified by:
start in interface AgentInterface
Overrides:
start in class HTTPFileServerAgent

stop

public void stop()
Description copied from class: ServiceAgent
Unregisters this instance with the service manager using the service_name property.

Specified by:
stop in interface AgentInterface
Overrides:
stop in class ServiceAgent

addSession

protected boolean addSession()
This method is used to internally track the number of active sessions. If the maximum number of sessions has been reached, this method returns false and no session counter is tracked.


removeSession

protected void removeSession()
This method is used to internally track the number of active sessions.


sendFile

protected void sendFile(java.io.File file,
                        HTTPAgentRequest request)
                 throws java.io.IOException
Overrides:
sendFile in class HTTPFileServerAgent
Throws:
java.io.IOException

printTryAgain

protected void printTryAgain(HTTPAgentRequest request)
This method generates the message when the maximum number of connections has been reached.


printLog

protected void printLog(java.lang.String logString,
                        HTTPAgentRequest request)
This method is used by this Agent to log bandwidth related information to the log file.