infofilter
Class NewsReaderAgent

java.lang.Object
  |
  +--ciagent.CIAgent
        |
        +--infofilter.NewsReaderAgent

public class NewsReaderAgent
extends CIAgent

The NewsReaderAgent class implements an agent can read one or more news articles from an NNTP host.

See Also:
Serialized Form

Field Summary
(package private)  java.util.Vector articles
           
(package private)  NewsArticle currentArt
           
(package private)  java.net.Socket news
           
(package private)  java.lang.String newsGroup
           
(package private)  java.util.Vector newsGroups
           
(package private)  java.lang.String newsHost
           
(package private)  boolean newsHostConnectionOK
           
(package private)  java.io.BufferedReader newsIn
           
(package private)  java.io.PrintWriter newsOut
           
(package private)  int numArticles
           
 
Fields inherited from class ciagent.CIAgent
agentPlatform, children, DEFAULT_ASYNCTIME, DEFAULT_SLEEPTIME, name, parent, traceLevel
 
Constructor Summary
NewsReaderAgent()
          Creates a NewsReaderAgent object.
NewsReaderAgent(java.lang.String name)
          Creates a NewsReaderAgent object with the given name.
 
Method Summary
(package private)  void closeNewsHost()
          Closes the connection to the NNTP news host.
 void connectToNewsHost(java.lang.String newsHost)
          Creates a socket connection to an NNTP news server.
protected  void downloadNewsGroup(java.util.Vector args)
          Connects to the news host, reads the news group, and closes the connection with the news host.
 java.util.Vector getArticles()
          Retrieves the articles.
 java.lang.String getNewsGroup()
          Retrieves the news group from this agent.
 java.lang.String getNewsHost()
          Retrieves the news host from this agent.
 int getNumArticles()
          Retrieves the number of articles to be read by this agent.
 java.lang.String getTaskDescription()
          Retrieves the task description.
 void initialize()
          Initializes the agent by setting the sleep time to 5 seconds.
protected  NewsArticle parseHeader(java.lang.String id)
          Parses the article header and retrieves the subject line.
 void process()
          Does nothing.
 void processCIAgentEvent(CIAgentEvent event)
          Processes a CIAgentEvent object (trace, downloadNewsGroup).
 void processTimerPop()
          Does nothing.
 void readNewsGroup(java.lang.String newsGroup)
          Reads an entire news group.
 void readSingleArticle(java.lang.String id)
          Reads a single article from the opened NNTP server.
protected  void sendArticleToListeners(NewsArticle art)
          Sends an article that was read from the news server to anyone listening for it.
 void setNewsGroup(java.lang.String newsGroup)
          Sets the news group to the given string.
 void setNewsHost(java.lang.String newsHost)
          Sets the news host to the given string.
 void setNumArticles(int numArticles)
          Sets the maximum number of articles read by this agent.
 void stop()
          Stops the agent processing.
 
Methods inherited from class ciagent.CIAgent
addAgent, addCIAgentEventListener, addPropertyChangeListener, getAgent, getAgentPlatform, getAgents, getAsyncTime, getChildren, getCustomizerClass, getDisplayName, getName, getParent, getSleepTime, getState, getTraceLevel, notifyCIAgentEventListeners, postCIAgentEvent, processAsynchronousEvents, removeAgent, removeCIAgentEventListener, removePropertyChangeListener, reset, resumeAgentProcessing, setAgentPlatform, setAsyncTime, setName, setParent, setSleepTime, setState, setTraceLevel, startAgentProcessing, stopAgentProcessing, suspendAgentProcessing, trace
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

newsHost

java.lang.String newsHost

newsGroup

java.lang.String newsGroup

news

java.net.Socket news

newsOut

java.io.PrintWriter newsOut

newsIn

java.io.BufferedReader newsIn

newsHostConnectionOK

boolean newsHostConnectionOK

numArticles

int numArticles

articles

java.util.Vector articles

currentArt

NewsArticle currentArt

newsGroups

java.util.Vector newsGroups
Constructor Detail

NewsReaderAgent

public NewsReaderAgent()
Creates a NewsReaderAgent object.

NewsReaderAgent

public NewsReaderAgent(java.lang.String name)
Creates a NewsReaderAgent object with the given name.
Parameters:
name - the String object that contains the agent name
Method Detail

setNewsHost

public void setNewsHost(java.lang.String newsHost)
Sets the news host to the given string.
Parameters:
newsHost - the String object that contains the news host

getNewsHost

public java.lang.String getNewsHost()
Retrieves the news host from this agent.
Returns:
the String object that contains the news host

setNewsGroup

public void setNewsGroup(java.lang.String newsGroup)
Sets the news group to the given string.
Parameters:
newsGroup - the String object that contains the news group

getNewsGroup

public java.lang.String getNewsGroup()
Retrieves the news group from this agent.
Returns:
the String object that contains the news group

setNumArticles

public void setNumArticles(int numArticles)
Sets the maximum number of articles read by this agent.
Parameters:
numArticles - the integer value for the number of articles

getNumArticles

public int getNumArticles()
Retrieves the number of articles to be read by this agent.
Returns:
the integer value for the number of articles

getArticles

public java.util.Vector getArticles()
Retrieves the articles.
Returns:
the Vector object that contains the articles

initialize

public void initialize()
Initializes the agent by setting the sleep time to 5 seconds.
Overrides:
initialize in class CIAgent

getTaskDescription

public java.lang.String getTaskDescription()
Retrieves the task description.
Returns:
the String object that contains the task description
Overrides:
getTaskDescription in class CIAgent

process

public void process()
Does nothing.
Overrides:
process in class CIAgent

stop

public void stop()
Stops the agent processing.

processTimerPop

public void processTimerPop()
Does nothing.
Overrides:
processTimerPop in class CIAgent

processCIAgentEvent

public void processCIAgentEvent(CIAgentEvent event)
Processes a CIAgentEvent object (trace, downloadNewsGroup).
Parameters:
event - the CIAgentEvent object to be processed
Overrides:
processCIAgentEvent in class CIAgent

sendArticleToListeners

protected void sendArticleToListeners(NewsArticle art)
Sends an article that was read from the news server to anyone listening for it.
Parameters:
art - the NewsArticle object to be sent

downloadNewsGroup

protected void downloadNewsGroup(java.util.Vector args)
Connects to the news host, reads the news group, and closes the connection with the news host.
Parameters:
args - the Vector that contains the news host and news group strings

connectToNewsHost

public void connectToNewsHost(java.lang.String newsHost)
Creates a socket connection to an NNTP news server.
Parameters:
newsHost - the String object that contains the news host

closeNewsHost

void closeNewsHost()
Closes the connection to the NNTP news host.

readNewsGroup

public void readNewsGroup(java.lang.String newsGroup)
Reads an entire news group.
Parameters:
newsGroup - the String object that contains the news group to be read

readSingleArticle

public void readSingleArticle(java.lang.String id)
Reads a single article from the opened NNTP server.
Parameters:
id - the String object that contains the id of the article to be read

parseHeader

protected NewsArticle parseHeader(java.lang.String id)
Parses the article header and retrieves the subject line.
Parameters:
id - the String object that contains the id of the article
Returns:
the NewsArticle object that contains the subject line of the article