com.cometway.email
Class SendEmailAgent

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.email.SendEmailAgent
All Implemented Interfaces:
AgentInterface, SendEmailInterface, HasStateMachineModel, java.lang.Runnable

public class SendEmailAgent
extends ServiceAgent
implements java.lang.Runnable, SendEmailInterface

This agent queues up email messages and sends them to the smtp_host at regular intervals. There are a variety of properties that can be configured which define how and when these messages are sent. This agent implements the SendEmailInterface and registers with the Service Manager for other agents to use.


Field Summary
protected  java.lang.Thread emailerThread
           
protected  boolean isRunning
           
protected  java.util.Vector messageQueue
           
protected  java.lang.Object vectorSync
           
 
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
SendEmailAgent()
           
 
Method Summary
 void initProps()
          Initializes the Props for this agent: "service_name" is used to register this agent with the Service Manager (default: send_email), "max_queue_size" is the maximum number of messages allocated for storage in the queue (default: 100), "smtp_sleep_ms" is the interval between attempts to send messages in the queue (default: 5000ms), "smtp_host" is the host name or IP address of the SMTP server, "smtp_port" is the port of the SMTP server (default: 25), "smtp_timeout_ms" is the amount of time this agent will wait for a socket connection (default 500ms)
 void run()
          This method runs on a Thread owned by this agent.
 void sendEmailMessage(IMessage m)
          Adds an email message to the queue to be sent to the SMTP server.
 void start()
          Starts this agent by creating the message queue, and the Thread that monitors its contents and sends the messages waiting there, then registers itself with the Service Manager using the "service_name" property.
 void stop()
          Stops this agent by unregistering itself with the Service Manager, releasing the message queue, and setting appropriate state information to cause the Thread that checks for email in the queue to terminate.
 
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

emailerThread

protected java.lang.Thread emailerThread

messageQueue

protected java.util.Vector messageQueue

vectorSync

protected java.lang.Object vectorSync

isRunning

protected boolean isRunning
Constructor Detail

SendEmailAgent

public SendEmailAgent()
Method Detail

initProps

public void initProps()
Initializes the Props for this agent: "service_name" is used to register this agent with the Service Manager (default: send_email), "max_queue_size" is the maximum number of messages allocated for storage in the queue (default: 100), "smtp_sleep_ms" is the interval between attempts to send messages in the queue (default: 5000ms), "smtp_host" is the host name or IP address of the SMTP server, "smtp_port" is the port of the SMTP server (default: 25), "smtp_timeout_ms" is the amount of time this agent will wait for a socket connection (default 500ms)

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

start

public void start()
Starts this agent by creating the message queue, and the Thread that monitors its contents and sends the messages waiting there, then registers itself with the Service Manager using the "service_name" property.

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

stop

public void stop()
Stops this agent by unregistering itself with the Service Manager, releasing the message queue, and setting appropriate state information to cause the Thread that checks for email in the queue to terminate.

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

sendEmailMessage

public void sendEmailMessage(IMessage m)
Adds an email message to the queue to be sent to the SMTP server. If adding this message causes the queue to exceed the "max_queue_size" property, the first message in the queue is removed before adding this one.

Specified by:
sendEmailMessage in interface SendEmailInterface

run

public void run()
This method runs on a Thread owned by this agent. While the agent is running, it periodically checks the message queue for new email messages to send to the SMTP server. If so, it opens a socket connection to the SMTP server and attempts to send each message in the queue, removing the messages from the queue if they were sent successfully.

Specified by:
run in interface java.lang.Runnable