AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.4.4
RecoveryPoint.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2010-2024 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 
68  {
69  public:
70  RecoveryPoint() : _body() { }
71 
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 
98  {
99  return _body.get().deepCopy();
100  }
101 
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 
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 
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 
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 
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 
318  };
319 
320 }
321 
322 #endif //_RECOVERYPOINT_H_
323 
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:181
void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:109
virtual const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:265
RecoveryPoint deepCopy(const RecoveryPoint &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:103
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:176
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:298
Provides access to the subId and bookmark needed to restart a subscription.
Definition: RecoveryPoint.hpp:67
RecoveryPointImpl virtual base class provides access to the subId and bookmark needed to restart a su...
Definition: RecoveryPoint.hpp:49
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
Defines the AMPS::Field class, which represents the value of a field in a message.
Interface for BookmarkStoreImpl classes.
Definition: BookmarkStore.hpp:228
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:191
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:186
RecoveryPoint deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:97
virtual RecoveryPointImpl * deepCopy(const RecoveryPointImpl &original_)
Make self a deep copy of original_.
Definition: RecoveryPoint.hpp:281
DynamicRecoveryPoint is a RecoveryPoint implementation where subId is set explicitly but bookmark is ...
Definition: RecoveryPoint.hpp:234
Field represents the value of a single field in a Message.
Definition: Field.hpp:86
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:139
virtual const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:270
FixedRecoveryPoint is a RecoveryPoint implementation where subId and bookmark are set explicitly...
Definition: RecoveryPoint.hpp:133
virtual void clear()
Clear the internal state, possibly reclaiming memory.
Definition: RecoveryPoint.hpp:206
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:102
const Field & getSubId() const
Get the sub id for this recovery point.
Definition: RecoveryPoint.hpp:84
virtual RecoveryPointImpl * deepCopy()
Return a deep copy of self.
Definition: RecoveryPoint.hpp:276
const Field & getBookmark() const
Get the bookmark for this recovery point.
Definition: RecoveryPoint.hpp:91