AMPS C/C++ Client Class Reference AMPS C/C++ Client Version 5.3.5.1

RecoveryPoint.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2010-2025 60East Technologies Inc., All Rights Reserved.
4 //
5 // This computer software is owned by 60East Technologies Inc. and is
6 // protected by U.S. copyright laws and other laws and by international
7 // treaties. This computer software is furnished by 60East Technologies
8 // Inc. pursuant to a written license agreement and may be used, copied,
9 // transmitted, and stored only in accordance with the terms of such
10 // license agreement and with the inclusion of the above copyright notice.
11 // This computer software or any other copies thereof may not be provided
12 // or otherwise made available to any other person.
13 //
14 // U.S. Government Restricted Rights. This computer software: (a) was
15 // developed at private expense and is in all respects the proprietary
16 // information of 60East Technologies Inc.; (b) was not developed with
17 // government funds; (c) is a trade secret of 60East Technologies Inc.
18 // for all purposes of the Freedom of Information Act; and (d) is a
19 // commercial item and thus, pursuant to Section 12.212 of the Federal
20 // Acquisition Regulations (FAR) and DFAR Supplement Section 227.7202,
21 // Government's use, duplication or disclosure of the computer software
22 // is subject to the restrictions set forth by 60East Technologies Inc..
23 //
25
26 #ifndef _RECOVERYPOINT_H_
27 #define _RECOVERYPOINT_H_
28
29 #include <amps/BookmarkStore.hpp>
30 #include <amps/Field.hpp>
31 #include <amps/util.hpp>
32
36 namespace AMPS
37 {
38
44 class RecoveryPoint;
45
49 class RecoveryPointImpl : public RefBody
50 {
51 public:
52 virtual ~RecoveryPointImpl() { }
55 virtual const Field& getSubId() const = 0;
58 virtual const Field& getBookmark() const = 0;
60 virtual RecoveryPointImpl* deepCopy() = 0;
62 virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_) = 0;
64 virtual void clear() = 0;
65 };
66
67 class RecoveryPoint
68 {
69 public:
70 RecoveryPoint() : _body() { }
71
72 RecoveryPoint(RecoveryPointImpl* body_)
73 : _body(body_)
74 { }
75
76 RecoveryPoint(const RecoveryPoint& rhs_)
77 : _body(rhs_._body)
78 { }
79
80 ~RecoveryPoint() { }
81
84 const Field& getSubId() const
85 {
86 return _body.get().getSubId();
87 }
88
91 const Field& getBookmark() const
92 {
93 return _body.get().getBookmark();
94 }
95
97 RecoveryPoint deepCopy()
98 {
99 return _body.get().deepCopy();
100 }
101
103 RecoveryPoint deepCopy(const RecoveryPoint& original_)
104 {
105 return _body.get().deepCopy(original_._body.get());
106 }
107
109 void clear()
110 {
111 return _body.get().clear();
112 }
113
114 RecoveryPoint& operator=(const RecoveryPoint& rhs_)
115 {
116 _body = rhs_._body;
117 return *this;
118 }
119 private:
120 RefHandle<RecoveryPointImpl> _body;
121 };
122
126 typedef RecoveryPoint (*RecoveryPointFactory)(const Field& subId_,
127 const Field& bookmark_);
128
133 class FixedRecoveryPoint : public RecoveryPointImpl
134 {
135 public:
139 static RecoveryPoint create(const Field& subId_, const Field& bookmark_)
140 {
141 return RecoveryPoint(new FixedRecoveryPoint(subId_, bookmark_));
142 }
143
144 FixedRecoveryPoint() : RecoveryPointImpl(), _owner(false) { }
145
146 FixedRecoveryPoint(const Field& subId_, const Field& bookmark_)
147 : _subId(subId_), _bookmark(bookmark_), _owner(false)
148 {
149 }
150
151 FixedRecoveryPoint(const Field& subId_, const Field& bookmark_,
152 bool deepCopy_)
153 : _owner(deepCopy_)
154 {
155 if (_owner)
156 {
157 _subId.deepCopy(subId_);
158 _bookmark.deepCopy(bookmark_);
159 }
160 else
161 {
162 _subId = subId_;
163 _bookmark = bookmark_;
164 }
165 }
166
167 virtual ~FixedRecoveryPoint()
168 {
169 if (_owner)
170 {
171 _subId.clear();
172 _bookmark.clear();
173 }
174 }
175
176 virtual const Field& getSubId() const
177 {
178 return _subId;
179 }
180
181 virtual const Field& getBookmark() const
182 {
183 return _bookmark;
184 }
185
186 virtual RecoveryPointImpl* deepCopy()
187 {
188 return new FixedRecoveryPoint(_subId, _bookmark, true);
189 }
190
191 virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
192 {
193 if (!_owner)
194 {
195 // deepCopy calls clear() so need to avoid that
196 _subId = Field();
197 _bookmark = Field();
198 }
199 _owner = true;
200 _subId.deepCopy(original_.getSubId());
201 _bookmark.deepCopy(original_.getBookmark());
202 return this;
203 }
204
206 virtual void clear()
207 {
208 if (_owner)
209 {
210 _subId.clear();
211 _bookmark.clear();
212 _owner = false;
213 }
214 else
215 {
216 _subId = Field();
217 _bookmark = Field();
218 }
219 }
220
221 private:
222 Field _subId;
223 Field _bookmark;
224 bool _owner;
225 };
226
234 class DynamicRecoveryPoint : public RecoveryPointImpl
235 {
236 public:
240 static RecoveryPoint create(const Field& subId_, const Field&,
241 const BookmarkStore& store_)
242 {
243 return RecoveryPoint(new DynamicRecoveryPoint(subId_, store_));
244 }
245
246 DynamicRecoveryPoint(const Field& subId_,
247 const BookmarkStore& store_,
248 bool owner_ = false)
249 : RecoveryPointImpl(), _subId(subId_), _store(store_), _owner(owner_)
250 {
251 if (_owner)
252 {
253 _subId.deepCopy(subId_);
254 }
255 }
256
257 virtual ~DynamicRecoveryPoint()
258 {
259 if (_owner)
260 {
261 _subId.clear();
262 }
263 }
264
265 virtual const Field& getSubId() const
266 {
267 return _subId;
268 }
269
270 virtual const Field& getBookmark() const
271 {
272 _bookmark = _store.getMostRecent(_subId);
273 return _bookmark;
274 }
275
276 virtual RecoveryPointImpl* deepCopy()
277 {
278 return new DynamicRecoveryPoint(_subId, _store, true);
279 }
280
281 virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
282 {
283 if (!_owner)
284 {
285 // deepCopy calls clear() so need to avoid that
286 _subId = Field();
287 }
288 _owner = true;
289 _subId.deepCopy(original_.getSubId());
290 if (typeid(*this) == typeid(original_))
291 {
292 _store = ((DynamicRecoveryPoint*)&original_)->_store;
293 }
294 return this;
295 }
296
298 virtual void clear()
299 {
300 if (_owner)
301 {
302 _subId.clear();
303 _owner = false;
304 }
305 else
306 {
307 _subId = Field();
308 }
309 }
310
311 private:
312 Field _subId;
313 mutable Field _bookmark;
314 mutable BookmarkStore _store;
315 bool _owner;
316
317 DynamicRecoveryPoint();
318 };
319
320 }
321
322 #endif //_RECOVERYPOINT_H_
323
Field.hpp
Defines the AMPS::Field class, which represents the value of a field in a message.
AMPS::BookmarkStore
Interface for BookmarkStoreImpl classes.
Definition: BookmarkStore.hpp:229
AMPS::DynamicRecoveryPoint
DynamicRecoveryPoint is a RecoveryPoint implementation where subId is set explicitly but bookmark is ...
Definition: RecoveryPoint.hpp:235
AMPS::DynamicRecoveryPoint::deepCopy
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:276
AMPS::DynamicRecoveryPoint::clear
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:298
AMPS::DynamicRecoveryPoint::deepCopy
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:281
AMPS::DynamicRecoveryPoint::create
static RecoveryPoint create(const Field &subId_, const Field &, const BookmarkStore &store_)
Use this function in BookmarkStore::setRecoveryPointFactory( std::bind(&DynamicRecoveryPoint::create,...
Definition: RecoveryPoint.hpp:240
AMPS::DynamicRecoveryPoint::getBookmark
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:270
AMPS::DynamicRecoveryPoint::getSubId
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:265
AMPS::Field
Field represents the value of a single field in a Message.
Definition: Field.hpp:87
AMPS::Field::clear
void clear()
Deletes the data associated with this Field, should only be used on Fields that were created as deepC...
Definition: Field.hpp:260
AMPS::Field::deepCopy
void deepCopy(const Field &orig_)
Makes self a deep copy of the original field.
Definition: Field.hpp:218
AMPS::FixedRecoveryPoint
FixedRecoveryPoint is a RecoveryPoint implementation where subId and bookmark are set explicitly.
Definition: RecoveryPoint.hpp:134
AMPS::FixedRecoveryPoint::getSubId
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:176
AMPS::FixedRecoveryPoint::deepCopy
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:191
AMPS::FixedRecoveryPoint::clear
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:206
AMPS::FixedRecoveryPoint::create
static RecoveryPoint create(const Field &subId_, const Field &bookmark_)
Use this function in BookmarkStore::setRecoveryPointFactory( std::bind(&FixedRecoveryPoint::create,...
Definition: RecoveryPoint.hpp:139
AMPS::FixedRecoveryPoint::getBookmark
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:181
AMPS::FixedRecoveryPoint::deepCopy
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:186
AMPS::RecoveryPointImpl
RecoveryPointImpl virtual base class provides access to the subId and bookmark needed to restart a su...
Definition: RecoveryPoint.hpp:50
AMPS::RecoveryPointImpl::getSubId
virtual const Field & getSubId() const =0
Get the sub id for this recovery point.
AMPS::RecoveryPointImpl::deepCopy
virtual RecoveryPointImpl * deepCopy()=0
Return a deep copy of self.
AMPS::RecoveryPointImpl::deepCopy
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)=0
Make self a deep copy of original_.
AMPS::RecoveryPointImpl::clear
virtual void clear()=0
Clear the internal state, possibly reclaiming memory.
AMPS::RecoveryPointImpl::getBookmark
virtual const Field & getBookmark() const =0
Get the bookmark for this recovery point.
AMPS::RecoveryPoint
Provides access to the subId and bookmark needed to restart a subscription.
Definition: RecoveryPoint.hpp:68
AMPS::RecoveryPoint::deepCopy
RecoveryPoint deepCopy(const RecoveryPoint &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:103
AMPS::RecoveryPoint::getBookmark
const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:91
AMPS::RecoveryPoint::clear
void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:109
AMPS::RecoveryPoint::getSubId
const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:84
AMPS::RecoveryPoint::deepCopy
RecoveryPoint deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:97
AMPS::BookmarkStore::getMostRecent
Message::Field getMostRecent(const Message::Field &subId_)
Returns the most recent bookmark from the log that ought to be used for (re-)subscriptions.
Definition: BookmarkStore.hpp:310