30 ibrcommon::File MemoryBundleSet::__store_path__;
31 bool MemoryBundleSet::__store_path_set__ =
false;
34 : _name(), _bf_size(bf_size), _bf(bf_size * 8), _listener(listener), _consistent(true)
39 : _name(name), _bf_size(bf_size), _bf(bf_size * 8), _listener(listener), _consistent(true)
45 }
catch (
const std::exception &ex) {
60 set->_bf_size = _bf_size;
62 set->_consistent = _consistent;
65 set->_bundles.insert(_bundles.begin(), _bundles.end());
68 for (bundle_set::const_iterator it = set->_bundles.begin(); it != set->_bundles.end(); ++it)
71 set->_expire.insert(exb);
74 return refcnt_ptr<BundleSetImpl>(set);
87 _bf_size = set._bf_size;
89 _consistent = set._consistent;
96 _bundles.insert(set._bundles.begin(), set._bundles.end());
99 for (bundle_set::const_iterator it = _bundles.begin(); it != _bundles.end(); ++it)
104 }
catch (
const std::bad_cast&) {
112 pair<bundle_set::iterator,bool> ret = _bundles.insert(bundle);
132 if (bundle.isIn(_bf)) {
135 if (!_consistent)
return true;
138 return (iter != _bundles.end());
146 return _bundles.size();
154 if (timestamp == 0)
return;
156 expire_set::iterator iter = _expire.begin();
158 while (iter != _expire.end())
165 if (_listener != NULL)
166 _listener->eventBundleExpired( b.
bundle );
169 _bundles.erase( b.
bundle );
172 _expire.erase( iter++ );
182 for (bundle_set::const_iterator iter = _bundles.begin(); iter != _bundles.end(); ++iter)
202 for (bundle_set::const_iterator iter = _bundles.begin(); iter != _bundles.end(); ++iter)
204 if (!(*iter).isIn(filter))
206 ret.insert( (*iter) );
223 const char *data =
reinterpret_cast<const char*
>(_bf.table());
224 stream.write(data, _bf.size());
234 std::vector<char> buffer(count.get<
size_t>());
236 stream.read(&buffer[0], buffer.size());
239 _bf.load((
unsigned char*)&buffer[0], buffer.size());
250 ibrcommon::File p = path;
253 ibrcommon::File::createDirectory(p);
255 if (p.exists() && p.isDirectory()) {
257 __store_path_set__ =
true;
267 void MemoryBundleSet::store()
270 if (!MemoryBundleSet::__store_path_set__)
return;
273 if (_name.length() == 0)
return;
276 if (!__store_path__.exists())
277 ibrcommon::File::createDirectory(__store_path__);
280 std::stringstream ss; ss << __store_path__.getPath() <<
"/" << _name;
281 ibrcommon::File path_bundles(ss.str().c_str());
282 if(path_bundles.exists())
283 path_bundles.remove();
286 ofstream output_file;
287 output_file.open(path_bundles.getPath().c_str());
290 output_file << _bundles.size();
292 bundle_set::iterator iter = _bundles.begin();
293 while( iter != _bundles.end())
295 output_file << (*iter++);
301 void MemoryBundleSet::restore()
304 if (!MemoryBundleSet::__store_path_set__)
return;
306 std::stringstream ss; ss << __store_path__.getPath() <<
"/" << _name;
307 ibrcommon::File path_bundles(ss.str().c_str());
310 if (!path_bundles.exists())
return;
313 input_file.open(ss.str().c_str());
317 input_file >> num_bundles;
319 while (( i < num_bundles) && input_file.good())
virtual bool has(const dtn::data::BundleID &bundle) const
virtual ~MemoryBundleSet()
virtual std::ostream & serialize(std::ostream &stream) const
virtual std::istream & deserialize(std::istream &stream)
virtual refcnt_ptr< BundleSetImpl > copy() const
MemoryBundleSet(BundleSet::Listener *listener=NULL, Length bf_size=1024)
virtual void assign(const refcnt_ptr< BundleSetImpl > &)
std::set< dtn::data::MetaBundle > getNotIn(const ibrcommon::BloomFilter &filter) const
virtual void add(const dtn::data::MetaBundle &bundle)
virtual void expire(const Timestamp timestamp)
virtual Size size() const
const ibrcommon::BloomFilter & getBloomFilter() const
dtn::data::SDNV< Size > Number
const dtn::data::MetaBundle & bundle
static void setPath(const ibrcommon::File &path)