prophet::Repository Class Reference

Implements a modified heap-based priority_queue with bounds enforcement. More...

#include <Repository.h>

List of all members.

Classes

class  BundleCoreRep
 Reduced interface into BundleCore to provide logging, drop_bundle signal, and answer the query for bundle storage quota. More...

Public Types

typedef BundleList::iterator iterator
typedef BundleList::const_iterator const_iterator

Public Member Functions

 Repository (BundleCoreRep *core, QueueComp *qc=NULL, const BundleList *list=NULL)
 Constructor.
 ~Repository ()
 Destructor.
bool add (const Bundle *bundle)
 Add bundle to Repository, incrementing current utilization by Bundle's storage size.
void del (const Bundle *bundle)
 Remove arbitrary Bundle from Repository, and decrement current utilization accordingly.
void set_comparator (QueueComp *qc)
 Change policy of Repository by replacing comparator; post condition is that eviction order is resorted using the new comparator.
const QueueCompget_comparator () const
 Accessor to current comparator.
void handle_change_max ()
 Callback to instruct Repository to query BundleCore on new max.
void change_priority (const Bundle *b)
 Callback for external notice to recalculate eviction order for list, due to changed comparator state.
const BundleListget_bundles () const
 Fetch const reference to internal list of Bundles (there is no guarantee of meaningful order to returned list).
bool empty () const
 Return boolean indicating whether Repository has any bundles.
size_t size () const
 Return number of Bundles in Repository.
u_int get_max () const
 Return the current upper limit imposed by Repository.
u_int get_current () const
 Return current storage consumed by Bundles in Repository.

Protected Member Functions

void evict ()
 Evict the next candidate Bundle according to policy order.
bool find (const Bundle *b, iterator &i)
 Utility function for find.

void make_heap (size_t first, size_t last)
 Heap operations.
void push_heap (size_t first, size_t hole, size_t top, const Bundle *b)
 Heap operations.
void pop_heap (size_t first, size_t last, size_t result, const Bundle *b)
 Heap operations.
void adjust_heap (size_t first, size_t hole, size_t len, const Bundle *b)
 Heap operations.
void remove_and_reheap (size_t hole)
 Heap operations.

Protected Attributes

BundleCoreRepcore_
 facade interface into Bundle host
QueueCompcomp_
 queue policy Bundle comparator
BundleList list_
 array-based eviction-ordered heap of Bundles
u_int current_
 current utilization

Detailed Description

Implements a modified heap-based priority_queue with bounds enforcement.

Any change to a Bundle's priority (such as the act of forwarding a Bundle over a link) requires a call-back to change_priority to preserve correct heap ordering. Any change to a Bundle's size will result in undefined behavior; at present, the best practice is to drop() the bundle before the size change then add() it again after the size is finalized. Any change in policy (ie, a new comparator) will cost n for the pass-thru of reheaping; any change in max will also be at most a linear cost.

Definition at line 43 of file Repository.h.


Member Typedef Documentation

typedef BundleList::const_iterator prophet::Repository::const_iterator

Definition at line 47 of file Repository.h.

typedef BundleList::iterator prophet::Repository::iterator

Definition at line 46 of file Repository.h.


Constructor & Destructor Documentation

prophet::Repository::Repository ( BundleCoreRep core,
QueueComp qc = NULL,
const BundleList list = NULL 
)

Constructor.

Repository assumes ownership of memory pointed to by qc, but not for list (makes a copy).

Parameters:
core facade interface into Bundle host
qc Queue Policy comparator to sort by eviction order (such that the next Bundle to be evicted is evaluated less-than all other Bundles)
list initial list of Bundles to store

Definition at line 25 of file Repository.cc.

References add(), comp_, prophet::QueuePolicy::FIFO, and prophet::QueuePolicy::policy().

prophet::Repository::~Repository (  ) 

Destructor.

Definition at line 45 of file Repository.cc.

References comp_.


Member Function Documentation

bool prophet::Repository::add ( const Bundle bundle  ) 

Add bundle to Repository, incrementing current utilization by Bundle's storage size.

Parameters:
bundle pointer to Bundle to be added
Returns:
whether bundle was added

Definition at line 79 of file Repository.cc.

References core_, current_, evict(), find(), list_, LOG, prophet::Repository::BundleCoreRep::max_bundle_quota(), push_heap(), and prophet::Bundle::size().

Referenced by dtn::ProphetBundleList::add(), and Repository().

void prophet::Repository::adjust_heap ( size_t  first,
size_t  hole,
size_t  len,
const Bundle b 
) [protected]

Heap operations.

Definition at line 229 of file Repository.cc.

References comp_, list_, and push_heap().

Referenced by make_heap(), pop_heap(), and remove_and_reheap().

void prophet::Repository::change_priority ( const Bundle b  ) 

Callback for external notice to recalculate eviction order for list, due to changed comparator state.

Definition at line 132 of file Repository.cc.

References list_, LOG, push_heap(), remove_and_reheap(), and prophet::Bundle::sequence_num().

Referenced by prophet::Controller::handle_bundle_transmitted().

void prophet::Repository::del ( const Bundle bundle  ) 

Remove arbitrary Bundle from Repository, and decrement current utilization accordingly.

Assumes Bundle priority has not been changed, and that underlying heap is in priority order.

Parameters:
bundle pointer to Bundle to be removed

Definition at line 51 of file Repository.cc.

References current_, find(), list_, LOG, remove_and_reheap(), prophet::Bundle::sequence_num(), and prophet::Bundle::size().

Referenced by dtn::ProphetBundleList::clear(), and dtn::ProphetBundleList::del().

bool prophet::Repository::empty (  )  const [inline]

Return boolean indicating whether Repository has any bundles.

Definition at line 129 of file Repository.h.

References list_.

Referenced by dtn::ProphetBundleList::clear(), and dtn::ProphetBundleList::empty().

void prophet::Repository::evict (  )  [protected]
bool prophet::Repository::find ( const Bundle b,
iterator i 
) [protected]

Utility function for find.

Definition at line 279 of file Repository.cc.

References list_.

Referenced by add(), and del().

const BundleList& prophet::Repository::get_bundles (  )  const [inline]

Fetch const reference to internal list of Bundles (there is no guarantee of meaningful order to returned list).

Definition at line 124 of file Repository.h.

References list_.

Referenced by dtn::ProphetBundleList::clear(), dtn::ProphetBundleList::find(), and dtn::ProphetBundleList::get_bundles().

const QueueComp* prophet::Repository::get_comparator (  )  const [inline]

Accessor to current comparator.

Definition at line 107 of file Repository.h.

References comp_.

Referenced by prophet::Controller::Controller(), and prophet::Controller::set_queue_policy().

u_int prophet::Repository::get_current (  )  const [inline]

Return current storage consumed by Bundles in Repository.

Definition at line 144 of file Repository.h.

References current_.

u_int prophet::Repository::get_max (  )  const [inline]

Return the current upper limit imposed by Repository.

Definition at line 139 of file Repository.h.

References core_, and prophet::Repository::BundleCoreRep::max_bundle_quota().

void prophet::Repository::handle_change_max (  ) 

Callback to instruct Repository to query BundleCore on new max.

Definition at line 123 of file Repository.cc.

References core_, current_, evict(), and prophet::Repository::BundleCoreRep::max_bundle_quota().

void prophet::Repository::make_heap ( size_t  first,
size_t  last 
) [protected]

Heap operations.

Definition at line 263 of file Repository.cc.

References adjust_heap(), len, and list_.

Referenced by set_comparator().

void prophet::Repository::pop_heap ( size_t  first,
size_t  last,
size_t  result,
const Bundle b 
) [protected]

Heap operations.

Definition at line 222 of file Repository.cc.

References adjust_heap(), and list_.

Referenced by evict().

void prophet::Repository::push_heap ( size_t  first,
size_t  hole,
size_t  top,
const Bundle b 
) [protected]

Heap operations.

Definition at line 209 of file Repository.cc.

References comp_, and list_.

Referenced by add(), adjust_heap(), and change_priority().

void prophet::Repository::remove_and_reheap ( size_t  hole  )  [protected]

Heap operations.

Definition at line 254 of file Repository.cc.

References adjust_heap(), and list_.

Referenced by change_priority(), del(), and evict().

void prophet::Repository::set_comparator ( QueueComp qc  ) 

Change policy of Repository by replacing comparator; post condition is that eviction order is resorted using the new comparator.

Parameters:
qc comparator used to sort Bundles in eviction order

Definition at line 108 of file Repository.cc.

References comp_, list_, LOG, make_heap(), prophet::QueueComp::qp(), and prophet::QueuePolicy::qp_to_str().

Referenced by prophet::Controller::Controller(), and prophet::Controller::set_queue_policy().

size_t prophet::Repository::size (  )  const [inline]

Return number of Bundles in Repository.

Definition at line 134 of file Repository.h.

References list_.

Referenced by dtn::ProphetBundleList::size().


Member Data Documentation

queue policy Bundle comparator

Definition at line 166 of file Repository.h.

Referenced by adjust_heap(), evict(), get_comparator(), push_heap(), Repository(), set_comparator(), and ~Repository().

facade interface into Bundle host

Definition at line 165 of file Repository.h.

Referenced by add(), evict(), get_max(), and handle_change_max().

u_int prophet::Repository::current_ [protected]

current utilization

Definition at line 168 of file Repository.h.

Referenced by add(), del(), evict(), get_current(), and handle_change_max().

array-based eviction-ordered heap of Bundles

Definition at line 167 of file Repository.h.

Referenced by add(), adjust_heap(), change_priority(), del(), empty(), evict(), find(), get_bundles(), make_heap(), pop_heap(), push_heap(), remove_and_reheap(), set_comparator(), and size().


The documentation for this class was generated from the following files:
Generated on Sun Nov 21 13:21:33 2010 for DTN Reference Implementation by  doxygen 1.6.3