AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.2.0
RecoveryPoint.hpp
1 //
3 // Copyright (c) 2010-2020 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 
33 namespace AMPS
34 {
35 
36 class RecoveryPoint;
37 
41 class RecoveryPointImpl : public RefBody
42 {
43 public:
44  virtual ~RecoveryPointImpl() { }
47  virtual const Field& getSubId() const = 0;
50  virtual const Field& getBookmark() const = 0;
52  virtual RecoveryPointImpl* deepCopy() = 0;
54  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_) = 0;
56  virtual void clear() = 0;
57 };
58 
63 {
64 public:
65  RecoveryPoint() : _body() { }
66 
68  : _body(body_)
69  { }
70 
71  RecoveryPoint(const RecoveryPoint& rhs_)
72  : _body(rhs_._body)
73  { }
74 
75  ~RecoveryPoint() { }
76 
79  const Field& getSubId() const
80  {
81  return _body.get().getSubId();
82  }
83 
86  const Field& getBookmark() const
87  {
88  return _body.get().getBookmark();
89  }
90 
93  {
94  return _body.get().deepCopy();
95  }
96 
99  {
100  return _body.get().deepCopy(original_._body.get());
101  }
102 
104  void clear()
105  {
106  return _body.get().clear();
107  }
108 private:
109  RefHandle<RecoveryPointImpl> _body;
110 };
111 
115 typedef RecoveryPoint (*RecoveryPointFactory)(const Field& subId_,
116  const Field& bookmark_);
117 
123 {
124 public:
128  static RecoveryPoint create(const Field& subId_, const Field& bookmark_)
129  {
130  return RecoveryPoint(new FixedRecoveryPoint(subId_, bookmark_));
131  }
132 
133  FixedRecoveryPoint() : RecoveryPointImpl(), _owner(false) { }
134 
135  FixedRecoveryPoint(const Field& subId_, const Field& bookmark_)
136  : _subId(subId_), _bookmark(bookmark_), _owner(false)
137  {
138  }
139 
140  FixedRecoveryPoint(const Field& subId_, const Field& bookmark_,
141  bool deepCopy_)
142  : _owner(deepCopy_)
143  {
144  if (_owner)
145  {
146  _subId.deepCopy(subId_);
147  _bookmark.deepCopy(bookmark_);
148  }
149  else
150  {
151  _subId = subId_;
152  _bookmark = bookmark_;
153  }
154  }
155 
156  virtual ~FixedRecoveryPoint()
157  {
158  if (_owner)
159  {
160  _subId.clear();
161  _bookmark.clear();
162  }
163  }
164 
165  virtual const Field& getSubId() const
166  {
167  return _subId;
168  }
169 
170  virtual const Field& getBookmark() const
171  {
172  return _bookmark;
173  }
174 
176  {
177  return new FixedRecoveryPoint(_subId, _bookmark, true);
178  }
179 
180  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
181  {
182  if (!_owner)
183  {
184  // deepCopy calls clear() so need to avoid that
185  _subId = Field();
186  _bookmark = Field();
187  }
188  _owner = true;
189  _subId.deepCopy(original_.getSubId());
190  _bookmark.deepCopy(original_.getBookmark());
191  return this;
192  }
193 
195  virtual void clear()
196  {
197  if (_owner)
198  {
199  _subId.clear();
200  _bookmark.clear();
201  _owner = false;
202  }
203  else
204  {
205  _subId = Field();
206  _bookmark = Field();
207  }
208  }
209 
210 private:
211  Field _subId;
212  Field _bookmark;
213  bool _owner;
214 };
215 
224 {
225 public:
229  static RecoveryPoint create(const Field& subId_, const Field&,
230  const BookmarkStore& store_)
231  {
232  return RecoveryPoint(new DynamicRecoveryPoint(subId_, store_));
233  }
234 
235  DynamicRecoveryPoint(const Field& subId_,
236  const BookmarkStore& store_,
237  bool owner_ = false)
238  : RecoveryPointImpl(), _subId(subId_), _store(store_), _owner(owner_)
239  {
240  if (_owner) _subId.deepCopy(subId_);
241  }
242 
243  virtual ~DynamicRecoveryPoint()
244  {
245  if (_owner)
246  {
247  _subId.clear();
248  }
249  }
250 
251  virtual const Field& getSubId() const
252  {
253  return _subId;
254  }
255 
256  virtual const Field& getBookmark() const
257  {
258  _bookmark = _store.getMostRecent(_subId);
259  return _bookmark;
260  }
261 
263  {
264  return new DynamicRecoveryPoint(_subId, _store, true);
265  }
266 
267  virtual RecoveryPointImpl* deepCopy(const RecoveryPointImpl& original_)
268  {
269  if (!_owner)
270  {
271  // deepCopy calls clear() so need to avoid that
272  _subId = Field();
273  }
274  _owner = true;
275  _subId.deepCopy(original_.getSubId());
276  if (typeid(*this) == typeid(original_))
277  {
278  _store = ((DynamicRecoveryPoint*)&original_)->_store;
279  }
280  return this;
281  }
282 
284  virtual void clear()
285  {
286  if (_owner)
287  {
288  _subId.clear();
289  _owner = false;
290  }
291  else
292  {
293  _subId = Field();
294  }
295  }
296 
297 private:
298  Field _subId;
299  mutable Field _bookmark;
300  mutable BookmarkStore _store;
301  bool _owner;
302 
304 };
305 
306 }
307 
308 #endif //_RECOVERYPOINT_H_
309 
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:170
void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:104
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:251
RecoveryPoint deepCopy(const RecoveryPoint &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:98
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:165
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:284
RecoveryPoint provides access to the subId and bookmark needed to restart a subscription.
Definition: RecoveryPoint.hpp:62
RecoveryPointImpl virtual base class provides access to the subId and bookmark needed to restart a su...
Definition: RecoveryPoint.hpp:41
static RecoveryPoint create(const Field &subId_, const Field &, const BookmarkStore &store_)
Use this function in BookmarkStore::setRecoveryPointFactory( std::bind(&DynamicRecoveryPoint::create...
Definition: RecoveryPoint.hpp:229
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:180
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:175
RecoveryPoint deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:92
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:267
DynamicRecoveryPoint is a RecoveryPoint implementation where subId is set explicitly but bookmark is ...
Definition: RecoveryPoint.hpp:223
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:128
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:256
FixedRecoveryPoint is a RecoveryPoint implementation where subId and bookmark are set explicitly...
Definition: RecoveryPoint.hpp:122
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:195
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:105
const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:79
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:262
const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:86