Kea  1.9.9-git
isc::dns::RRCollator Class Reference

A converter from a stream of RRs to a stream of collated RRsets. More...

#include <rrcollator.h>

+ Inheritance diagram for isc::dns::RRCollator:


class  Impl

Public Types

typedef std::function< void(const RRsetPtr &rrset)> AddRRsetCallback
 Callback functor type for RRCollator. More...

Public Member Functions

 RRCollator (const AddRRsetCallback &callback)
 Constructor. More...
 ~RRCollator ()
 Destructor. More...
void flush ()
 Call the callback on the remaining RRset, if any. More...
AddRRCallback getCallback ()
 Return MasterLoader compatible callback. More...

Detailed Description

A converter from a stream of RRs to a stream of collated RRsets.

This class is mainly intended to be a helper used as an adapter for user applications of the MasterLoader class; it works as a callback for MasterLoader, buffers given RRs from the loader, collating consecutive RRs that belong to the same RRset (ones having the same owner name, RR type and class), and produces a stream of RRsets through its own callback. RRSIGs are also separated if their type covered fields have different values even if the owner name and RR class are the same.

It also "normalizes" TTLs of the RR; if collated RRs have different TTLs, this class guarantees that the TTL of the resulting RRsets has the smallest TTL among them.

The conversion will be useful for applications of MasterLoader because many of this library have interfaces that take an RRset object (or a pointer to it). Note, however, that this class doesn't guarantee that all RRs that would belong to the same RRset are collated into the same single RRset. In fact, it can only collate RRs that are consecutive in the original stream; once it encounters an RR of a different RRset, any subsequent RRs of the previous RRset will form a separate RRset object.

This class is non-copyable; it's partially for the convenience of internal implementation details, but it actually doesn't make sense to copy an object of this class, if not harmful, for the intended usage of the class.

Definition at line 45 of file rrcollator.h.

Member Typedef Documentation

typedef std::function<void(const RRsetPtr& rrset)> isc::dns::RRCollator::AddRRsetCallback

Callback functor type for RRCollator.

This type of callback is given to an RRCollator object on its construction, and will be called for each collated RRset built in the RRCollator.

rrsetThe collated RRset.

Definition at line 54 of file rrcollator.h.

Constructor & Destructor Documentation

isc::dns::RRCollator::RRCollator ( const AddRRsetCallback callback)


std::bad_allocInternal memory allocation fails. This should be very rare.
callbackThe callback functor to be called for each collated RRset.

Definition at line 82 of file

isc::dns::RRCollator::~RRCollator ( )


It only performs trivial internal cleanup. In particular, even if it still has a buffered RRset it will be simply discarded. This is because the given callback could throw an exception, and it's impossible to predict how this class is used (to see if it's a very rare case where propagating an exception from a destructor is justified). Instead, the application needs to make sure that flush() is called before the object of this class is destroyed.


Definition at line 86 of file

Member Function Documentation

void isc::dns::RRCollator::flush ( )

Call the callback on the remaining RRset, if any.

This method is expected to be called that it's supposed all RRs have been passed to this class object. Since there is no explicit indicator of the end of the stream, the user of this class needs to explicitly call this method to call the callback for the last buffered RRset (see also the destructor's description).

If there is no buffered RRset, this method does nothing. It can happen if it's called without receiving any RRs, or called more than once.

It propagates any exception thrown from the callback; otherwise it doesn't throw anything.

Definition at line 97 of file

References isc::dns::RRCollator::Impl::callback_, and isc::dns::RRCollator::Impl::current_rrset_.

AddRRCallback isc::dns::RRCollator::getCallback ( )

Return MasterLoader compatible callback.

This method returns a functor in the form of AddRRCallback that works as an adapter between MasterLoader and an application that needs to get a stream of RRsets. When the returned callback is called, this RRCollator object accepts the corresponding RR, and collates it with other RRs of the same RRset if necessary. Every time the RRCollator object encounters an RR of a different RRset, it calls the callback passed to the constructor with the RRset built so far.

Like flush(), this AddRRCallback functor propagates any exception thrown from the callback.

This method is expected to be called only once for a given RRCollator object. It doesn't prohibit duplicate calls, but returned functor objects internally refer to the same RRCollator object, and calling the both callbacks randomly will just cause confusion.

Definition at line 91 of file

References isc::dns::RRCollator::Impl::addRR().

+ Here is the call graph for this function:

The documentation for this class was generated from the following files: