IBR-DTNSuite
0.10
Main Page
Namespaces
Classes
Files
File List
File Members
SimpleBundleStorage.h
Go to the documentation of this file.
1
/*
2
* SimpleBundleStorage.h
3
*
4
* Copyright (C) 2011 IBR, TU Braunschweig
5
*
6
* Written-by: Johannes Morgenroth <morgenroth@ibr.cs.tu-bs.de>
7
*
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
11
*
12
* http://www.apache.org/licenses/LICENSE-2.0
13
*
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
19
*
20
*/
21
22
#ifndef SIMPLEBUNDLESTORAGE_H_
23
#define SIMPLEBUNDLESTORAGE_H_
24
25
#include "
Component.h
"
26
#include "
core/BundleCore.h
"
27
#include "
storage/BundleStorage.h
"
28
#include "
core/Node.h
"
29
#include "
core/EventReceiver.h
"
30
31
#include "
storage/DataStorage.h
"
32
#include "
storage/MetaStorage.h
"
33
34
#include <
ibrcommon/thread/Conditional.h
>
35
#include <
ibrcommon/thread/AtomicCounter.h
>
36
#include <
ibrcommon/thread/RWMutex.h
>
37
38
#include <
ibrcommon/data/File.h
>
39
#include <
ibrdtn/data/Bundle.h
>
40
#include <
ibrdtn/data/BundleList.h
>
41
#include <
ibrcommon/thread/Queue.h
>
42
43
#include <set>
44
#include <map>
45
46
namespace
dtn
47
{
48
namespace
storage
49
{
53
class
SimpleBundleStorage
:
public
DataStorage::Callback
,
public
BundleStorage
,
public
dtn::core::EventReceiver
,
public
dtn::daemon::IntegratedComponent
,
public
dtn::data::BundleList::Listener
54
{
55
static
const
std::string TAG;
56
57
public
:
61
SimpleBundleStorage
(
const
ibrcommon::File
&workdir,
const
dtn::data::Length
maxsize = 0,
const
unsigned
int
buffer_limit = 0);
62
66
virtual
~SimpleBundleStorage
();
67
72
virtual
void
store
(
const
dtn::data::Bundle
&bundle);
73
80
virtual
dtn::data::Bundle
get
(
const
dtn::data::BundleID
&id);
81
85
virtual
void
get
(
const
BundleSelector
&cb,
BundleResult
&result)
throw
(
NoBundleFoundException
,
BundleSelectorException
);
86
90
virtual
const
eid_set
getDistinctDestinations
();
91
97
void
remove
(
const
dtn::data::BundleID
&id);
98
104
dtn::data::MetaBundle
remove
(
const
ibrcommon::BloomFilter
&filter);
105
109
void
clear
();
110
114
bool
empty
();
115
119
dtn::data::Size
count
();
120
124
void
releaseCustody
(
const
dtn::data::EID
&custodian,
const
dtn::data::BundleID
&
id
);
125
130
void
raiseEvent
(
const
dtn::core::Event
*evt)
throw
();
131
135
virtual
const
std::string
getName
()
const
;
136
137
virtual
void
eventDataStorageStored
(
const
dtn::storage::DataStorage::Hash
&hash);
138
virtual
void
eventDataStorageStoreFailed
(
const
dtn::storage::DataStorage::Hash
&hash,
const
ibrcommon::Exception
&);
139
virtual
void
eventDataStorageRemoved
(
const
dtn::storage::DataStorage::Hash
&hash);
140
virtual
void
eventDataStorageRemoveFailed
(
const
dtn::storage::DataStorage::Hash
&hash,
const
ibrcommon::Exception
&);
141
virtual
void
iterateDataStorage
(
const
dtn::storage::DataStorage::Hash
&hash,
dtn::storage::DataStorage::istream
&stream);
142
143
/*** BEGIN: methods for unit-testing ***/
144
148
virtual
void
wait
();
149
154
virtual
void
setFaulty
(
bool
mode);
155
156
/*** END: methods for unit-testing ***/
157
158
protected
:
159
virtual
void
componentUp
()
throw
();
160
virtual
void
componentDown
()
throw
();
161
virtual
void
eventBundleExpired
(
const
dtn::data::MetaBundle
&b)
throw
();
162
163
private
:
164
class
BundleContainer :
public
DataStorage::Container
165
{
166
public
:
167
BundleContainer(
const
dtn::data::Bundle
&b);
168
virtual
~BundleContainer();
169
170
std::string getKey()
const
;
171
std::ostream& serialize(std::ostream &stream);
172
173
private
:
174
const
dtn::data::Bundle
_bundle;
175
};
176
177
void
__remove(
const
dtn::data::MetaBundle
&meta);
178
void
__store(
const
dtn::data::Bundle
&bundle,
const
dtn::data::Length
&bundle_size);
179
180
typedef
std::map<DataStorage::Hash, dtn::data::Bundle> pending_map;
181
ibrcommon::RWMutex
_pending_lock;
182
pending_map _pending_bundles;
183
184
// This object manages data stored on disk
185
DataStorage
_datastore;
186
187
// stores all the meta data in memory
188
ibrcommon::RWMutex
_meta_lock;
189
MetaStorage
_metastore;
190
};
191
}
192
}
193
194
#endif
/*SIMPLEBUNDLESTORAGE_H_*/
daemon
src
storage
SimpleBundleStorage.h
Generated on Mon Jul 22 2013 15:16:00 for IBR-DTNSuite by
1.8.3.1