Next: News Database
Up: Implementation
Previous: News Cache Daemon
Subsections
The following sections show the implementation of the news server
classes. These classes provide an interface to several kinds of news
databases. The NServer class is an abstract class that acts
only as common superclass for the news server classes. For
facilitating the exploitation of polymorphism the methods of the
NServer class are declared as abstract and virtual.
Table 6.1 gives an explanation of these concepts.
Tabelle 6.1:
Abstract and virtual methods in C++
- Abstract Method
- An abstract method only defines the interface
for the method. The actual implementation for the method must be
provided by classes that inherit the method from its parent class.
Using abstract methods in a class ensures that all subclasses of
the base class implement at least the abstract methods provided by
the base class.
- Virtual Method
- Declaring methods of a class as virtual allows
to exploit polymorphism across its subclasses. Consider a class
GeometricShape and some subclasses (e.g., Rectangle ,
Circle , ...) that define the method draw .
Whenever GeometricShape is used in the place of one of its
subclasses, the correct method draw will be called.
|
The current version of the News Server Class Library already
provides a class for the retrieval of news articles from a remote news
server (RServer ), from a local news database (LServer )
and a class retrieving news articles from a remote news server with
the ability to cache already requested data in a local news database
(LServer ). The relationship between those classes has been
explained in section 5.4 and is shown again in
Figure 6.2. The classes of this library
allow any program (e.g., news readers, proxy news servers, news
caches, etc.) to access a news database in different ways.
Abbildung 6.2:
Hierarchy of the News Server classes
|
The NServer class defines the interface for all methods needed
to access a news server. These methods are declared abstract
and virtual. The methods are declared abstract
because the method has to be implemented by the subclass of this
class. The methods are declared virtual to provide
polymorphism across the news server classes.
An NVActiveDB class is used for the active database and an
NVOverviewDB class for the overview database. Currently these
two classes have to be used by all the NServer 's subclasses.
However, this is likely to change in the future (See
section 8.1.1) for a detailed explanation).
The following methods have been defined for the retrieval of
newsgroups articles and the overview database:
- active()
- This method returns a pointer to the active database.
- group(char *name)
- This method returns a pointer to information
about the newsgroup name. It contains the type of the
newsgroup, the number of the first and last article and the total
number of articles.
- xoverfmt()
- This method returns the order of the database
entries stored in the overview database.
- xoverdb(int fst, int lst)
- This method returns a pointer to the
overview database of the newsgroup. The overview database contains
at least the overview records for the articles within the range
fst-lst.
- article(int nbr)
- returns the article with the number
nbr from the current newsgroup.
- post(Article *article)
- posts the article stored in
article to the news database.
- setserver(char *ns_name, char *ns_serv)
- This method selects a
new database. The parameters ns_name and
ns_serv define the name of the database. For the
RServer and CServer classes ns_name and
ns_serv reflect the name and the service of the news
server. This function has been added to allow multiplexing between
different news databases. This interface may change in the future.
The RServer class is a subclass of the NServer class and
implements the news server interface as specified by theNServer
class. The RServer class uses the news database provided by a
news server. The data on the news server is accessed using NNRP.
The RServer class implements the following methods in addition
to the methods specified in section 6.4.1:
- connect()
- This method connects to the news server specified by
the setserver method.
- is_connected()
- This method returns, whether the RServer
class currently is connected to the news server.
- disconnect()
- This method disconnects the RServer class
from the news server.
The LServer class is a subclass of the NServer class and
implements the news server interface as specified by the
NServer class. The LServer class uses a local news
database to provide newsgroups and news articles.
The LServer class needs not implement any method in addition to
the ones defined in the NServer class.
The CServer class is a subclass of the RServer and the
LServer class and implements the news server interface as
specified by theNServer class. The CServer class is used
to retrieve newsgroups and articles from a news server using NNRP.
Before these groups and articles are passed back to the caller, the
data are cached in a local news database. The local news database is
used to satisfy successive requests to the same data.
In addition to the methods defined in its superclasses, the
CServer class implements the setttl(ttl_list,
ttl_desc, ttl_group) method. This method is used to specify the
timeouts used for the ActiveDB (ttl_list), the group
description file (ttl_desc) and for the newsgroups
(ttl_group). Whenever a client requests a database being
expired, the databases is requested from the news server again.
Next: News Database
Up: Implementation
Previous: News Cache Daemon
gschwind@infosys.tuwien.ac.at