AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.3.0
RecoveryPoint.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2010-2021 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 <BookmarkStore.hpp>
30 #include <Field.hpp>
31 #include <util.hpp>
32 
36 namespace AMPS
37 {
38 
39 class RecoveryPoint;
40 
44 class RecoveryPointImpl : public RefBody
45 {
46 public:
47  virtual ~RecoveryPointImpl() { }
50  virtual const Field& getSubId() const = 0;
53  virtual const Field& getBookmark() const = 0;
55  virtual RecoveryPointImpl* deepCopy() = 0;
57  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_) = 0;
59  virtual void clear() = 0;
60 };
61 
66 {
67 public:
68  RecoveryPoint() : _body() { }
69 
71  : _body(body_)
72  { }
73 
74  RecoveryPoint(const RecoveryPoint& rhs_)
75  : _body(rhs_._body)
76  { }
77 
78  ~RecoveryPoint() { }
79 
82  const Field& getSubId() const
83  {
84  return _body.get().getSubId();
85  }
86 
89  const Field& getBookmark() const
90  {
91  return _body.get().getBookmark();
92  }
93 
96  {
97  return _body.get().deepCopy();
98  }
99 
102  {
103  return _body.get().deepCopy(original_._body.get());
104  }
105 
107  void clear()
108  {
109  return _body.get().clear();
110  }
111 
112  RecoveryPoint& operator=(const RecoveryPoint& rhs_)
113  {
114  _body = rhs_._body;
115  return *this;
116  }
117 private:
118  RefHandle<RecoveryPointImpl> _body;
119 };
120 
124 typedef RecoveryPoint (*RecoveryPointFactory)(const Field& subId_,
125  const Field& bookmark_);
126 
132 {
133 public:
137  static RecoveryPoint create(const Field& subId_, const Field& bookmark_)
138  {
139  return RecoveryPoint(new FixedRecoveryPoint(subId_, bookmark_));
140  }
141 
142  FixedRecoveryPoint() : RecoveryPointImpl(), _owner(false) { }
143 
144  FixedRecoveryPoint(const Field& subId_, const Field& bookmark_)
145  : _subId(subId_), _bookmark(bookmark_), _owner(false)
146  {
147  }
148 
149  FixedRecoveryPoint(const Field& subId_, const Field& bookmark_,
150  bool deepCopy_)
151  : _owner(deepCopy_)
152  {
153  if (_owner)
154  {
155  _subId.deepCopy(subId_);
156  _bookmark.deepCopy(bookmark_);
157  }
158  else
159  {
160  _subId = subId_;
161  _bookmark = bookmark_;
162  }
163  }
164 
165  virtual ~FixedRecoveryPoint()
166  {
167  if (_owner)
168  {
169  _subId.clear();
170  _bookmark.clear();
171  }
172  }
173 
174  virtual const Field& getSubId() const
175  {
176  return _subId;
177  }
178 
179  virtual const Field& getBookmark() const
180  {
181  return _bookmark;
182  }
183 
185  {
186  return new FixedRecoveryPoint(_subId, _bookmark, true);
187  }
188 
189  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
190  {
191  if (!_owner)
192  {
193  // deepCopy calls clear() so need to avoid that
194  _subId = Field();
195  _bookmark = Field();
196  }
197  _owner = true;
198  _subId.deepCopy(original_.getSubId());
199  _bookmark.deepCopy(original_.getBookmark());
200  return this;
201  }
202 
204  virtual void clear()
205  {
206  if (_owner)
207  {
208  _subId.clear();
209  _bookmark.clear();
210  _owner = false;
211  }
212  else
213  {
214  _subId = Field();
215  _bookmark = Field();
216  }
217  }
218 
219 private:
220  Field _subId;
221  Field _bookmark;
222  bool _owner;
223 };
224 
233 {
234 public:
238  static RecoveryPoint create(const Field& subId_, const Field&,
239  const BookmarkStore& store_)
240  {
241  return RecoveryPoint(new DynamicRecoveryPoint(subId_, store_));
242  }
243 
244  DynamicRecoveryPoint(const Field& subId_,
245  const BookmarkStore& store_,
246  bool owner_ = false)
247  : RecoveryPointImpl(), _subId(subId_), _store(store_), _owner(owner_)
248  {
249  if (_owner) _subId.deepCopy(subId_);
250  }
251 
252  virtual ~DynamicRecoveryPoint()
253  {
254  if (_owner)
255  {
256  _subId.clear();
257  }
258  }
259 
260  virtual const Field& getSubId() const
261  {
262  return _subId;
263  }
264 
265  virtual const Field& getBookmark() const
266  {
267  _bookmark = _store.getMostRecent(_subId);
268  return _bookmark;
269  }
270 
272  {
273  return new DynamicRecoveryPoint(_subId, _store, true);
274  }
275 
276  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
277  {
278  if (!_owner)
279  {
280  // deepCopy calls clear() so need to avoid that
281  _subId = Field();
282  }
283  _owner = true;
284  _subId.deepCopy(original_.getSubId());
285  if (typeid(*this) == typeid(original_))
286  {
287  _store = ((DynamicRecoveryPoint*)&original_)->_store;
288  }
289  return this;
290  }
291 
293  virtual void clear()
294  {
295  if (_owner)
296  {
297  _subId.clear();
298  _owner = false;
299  }
300  else
301  {
302  _subId = Field();
303  }
304  }
305 
306 private:
307  Field _subId;
308  mutable Field _bookmark;
309  mutable BookmarkStore _store;
310  bool _owner;
311 
313 };
314 
315 }
316 
317 #endif //_RECOVERYPOINT_H_
318 
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:179
void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:107
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:260
RecoveryPoint deepCopy(const RecoveryPoint &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:101
virtual const Field & getSubId() const =0
Get the sub id for this recovery point.
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:174
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:293
RecoveryPoint provides access to the subId and bookmark needed to restart a subscription.
Definition: RecoveryPoint.hpp:65
RecoveryPointImpl virtual base class provides access to the subId and bookmark needed to restart a su...
Definition: RecoveryPoint.hpp:44
static RecoveryPoint create(const Field &subId_, const Field &, const BookmarkStore &store_)
Use this function in BookmarkStore::setRecoveryPointFactory( std::bind(&DynamicRecoveryPoint::create...
Definition: RecoveryPoint.hpp:238
Defines the AMPS::Field class, which represents the value of a field in a message.
Interface for BookmarkStoreImpl classes.
Definition: BookmarkStore.hpp:225
virtual RecoveryPointImpl * deepCopy()=0
Return a deep copy of self.
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:189
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:184
RecoveryPoint deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:95
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:276
DynamicRecoveryPoint is a RecoveryPoint implementation where subId is set explicitly but bookmark is ...
Definition: RecoveryPoint.hpp:232
Field represents the value of a single field in a Message.
Definition: Field.hpp:84
static RecoveryPoint create(const Field &subId_, const Field &bookmark_)
Use this function in BookmarkStore::setRecoveryPointFactory( std::bind(&FixedRecoveryPoint::create, std::placeholder::_1, std::placeholder::_2))
Definition: RecoveryPoint.hpp:137
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:265
FixedRecoveryPoint is a RecoveryPoint implementation where subId and bookmark are set explicitly...
Definition: RecoveryPoint.hpp:131
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:204
virtual const Field & getBookmark() const =0
Get the bookmark for this recovery point.
virtual void clear()=0
Clear the internal state, possibly reclaiming memory.
Definition: ampsplusplus.hpp:103
const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:82
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:271
const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:89