com.cometway.httpd
Class HTTPFileDownloadAgent

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.ak.RequestAgent
                  extended by com.cometway.httpd.HTTPFileDownloadAgent
All Implemented Interfaces:
AgentInterface, RequestAgentInterface, HasStateMachineModel

public class HTTPFileDownloadAgent
extends RequestAgent

This agent is used to throttle specific content to web browsers. It can be used to limit maximum connections downloading content and the amount of bandwidth each connection is using.


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
HTTPFileDownloadAgent()
           
 
Method Summary
protected  boolean addSession()
          This method is used to internally track the number of active sessions.
 void handleRequest(AgentRequest agentRequest)
          This method handles the download request.
 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 ServiceManager (default: download.agent) "html_directory" points to the root directory where HTML files are served (default: public_html) "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 removeSession()
          This method is used to internally track the number of active sessions.
 void start()
          Registers this agent and initializes the log file.
 void stop()
          Unregisters this instance with the service manager using the service_name property.
 
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

HTTPFileDownloadAgent

public HTTPFileDownloadAgent()
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 ServiceManager (default: download.agent) "html_directory" points to the root directory where HTML files are served (default: public_html) "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 Agent

start

public void start()
Registers this agent and initializes the log file.

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

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.


handleRequest

public void handleRequest(AgentRequest agentRequest)
This method handles the download request. It looks for the CGI parameter "file" and throttles the contents of the file to the client. If no parameter is found or the file does not exist, a 404 is returned.


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.