Feature #2411
Updated by Junxiao Shi almost 11 years ago
Change ContentStore lookup API from:
const Data* find(Interest interest) const;
to:
typedef std::function<void(const Data&)> HitCallback; Data*)> FindCallback;
typedef std::function<void()> MissCallback;
void find(Interest interest, HitCallback hit, MissCallback miss) FindCallback cb) const;
This allows ContentStore implementation to perform lookup operations asynchronously.
This asynchronous API enables the following use case:
On a low-memory device, it's desirable to store part of ContentStore on external storage, in order to increase the capacity of ContentStore.
A possible design is: keep the index in main memory, but store some Data packets on a flash drive.
Under such design, a the ContentStore in low-memory device can synchronously determine whether a match exists, but needs to load the matched Data packet from the flash drive asynchronously.
Although the API is asynchronous and does not specify a timeout, ContentStore implementation should invoke the callback quickly (within a few milliseconds).
If the match result is already known, the callback may be invoked within find function.
`const Data&` passed to HitCallback is guaranteed to be valid only for the duration of this callback.
However, this Data object is always created by `make_shared` and therefore the callback can safely obtain shared ownership with `shared_from_this` in order to extend its validity.
Forwarding pipelines must be changed accordingly: the second half of "Incoming Interest pipeline" is split to "ContentStore Hit pipeline" and "ContentStore Miss pipeline".