#include <Repository.h>
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.
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 QueueComp * | get_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 BundleList & | get_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 | |
BundleCoreRep * | core_ |
facade interface into Bundle host | |
QueueComp * | comp_ |
queue policy Bundle comparator | |
BundleList | list_ |
array-based eviction-ordered heap of Bundles | |
u_int | current_ |
current utilization | |
Classes | |
class | BundleCoreRep |
Reduced interface into BundleCore to provide logging, drop_bundle signal, and answer the query for bundle storage quota. More... |
typedef BundleList::iterator prophet::Repository::iterator |
Definition at line 46 of file Repository.h.
typedef BundleList::const_iterator prophet::Repository::const_iterator |
Definition at line 47 of file Repository.h.
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).
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 comp_, prophet::QueuePolicy::FIFO, and prophet::QueuePolicy::policy().
prophet::Repository::~Repository | ( | ) |
Add bundle to Repository, incrementing current utilization by Bundle's storage size.
bundle | pointer to Bundle to be 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().
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.
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().
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.
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().
const QueueComp* prophet::Repository::get_comparator | ( | ) | const [inline] |
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::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().
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().
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().
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().
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().
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_.
void prophet::Repository::evict | ( | ) | [protected] |
Evict the next candidate Bundle according to policy order.
Definition at line 157 of file Repository.cc.
References comp_, core_, current_, prophet::Repository::BundleCoreRep::drop_bundle(), len, prophet::QueuePolicy::LEPR, list_, prophet::QueueComp::min_fwd_, prophet::Bundle::num_forward(), pop_heap(), prophet::QueueComp::qp(), remove_and_reheap(), and prophet::Bundle::size().
Referenced by add(), and handle_change_max().
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::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.
Referenced by add(), adjust_heap(), and change_priority().
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::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::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().
BundleCoreRep* prophet::Repository::core_ [protected] |
facade interface into Bundle host
Definition at line 165 of file Repository.h.
Referenced by add(), evict(), get_max(), and handle_change_max().
QueueComp* prophet::Repository::comp_ [protected] |
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().
BundleList prophet::Repository::list_ [protected] |
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().
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().