AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.0.5
HAClient.hpp
Go to the documentation of this file.
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 _HACLIENT_H_
27 #define _HACLIENT_H_
28 
29 #include <ampsplusplus.hpp>
30 #include <HAClientImpl.hpp>
31 #include <MemoryPublishStore.hpp>
32 #include <PublishStore.hpp>
33 #include <MemoryBookmarkStore.hpp>
34 #include <MMapBookmarkStore.hpp>
35 
41 
42 
43 namespace AMPS
44 {
66 
67 class HAClient : public Client
68 {
69 public:
74  : Client(new HAClientImpl(std::string()))
75  {
76  }
77 
87  HAClient(const std::string& name_)
88  : Client(new HAClientImpl(name_))
89  {
90  }
91 
95  HAClient(HAClientImpl* body_) : Client((ClientImpl*)body_) {}
96 
100  HAClient(const HAClient& rhs) : Client((const Client&)rhs) {}
101 
106  {
107  Client::operator=((const Client&)rhs);
108  return *this;
109  }
110 
114  void setTimeout(int timeout_)
115  {
116  getBody().setTimeout(timeout_);
117  }
118 
122  int getTimeout() const
123  {
124  return getBody().getTimeout();
125  }
126 
133  void setReconnectDelay(int reconnectDelay_)
134  {
135  getBody().setReconnectDelay((unsigned int)reconnectDelay_);
136  }
137 
141  int getReconnectDelay() const
142  {
143  return (int)(getBody().getReconnectDelay());
144  }
145 
154  {
155  getBody().setReconnectDelayStrategy(strategy_);
156  }
157 
166  {
167  return getBody().getReconnectDelayStrategy();
168  }
169 
175  std::string getLogonOptions(void) const
176  {
177  return getBody().getLogonOptions();
178  }
179 
183  void setLogonOptions(const char* logonOptions_)
184  {
185  getBody().setLogonOptions(logonOptions_);
186  }
187 
191  void setLogonOptions(const std::string& logonOptions_)
192  {
193  getBody().setLogonOptions(logonOptions_);
194  }
195 
200  {
201  return getBody().getServerChooser();
202  }
203 
208  void setServerChooser(const ServerChooser& serverChooser_)
209  {
210  getBody().setServerChooser(serverChooser_);
211  }
212 
232  static HAClient createMemoryBacked(const std::string& name_)
233  {
234  HAClient client(name_);
236  client.setPublishStore(Store(new MemoryPublishStore(10000)));
237  return client;
238  }
239 
243  // that is named subscribeLogName_.
264  static HAClient createFileBacked(const std::string& name_,
265  const std::string& publishLogName_,
266  const std::string& subscribeLogName_)
267  {
268  HAClient client(name_);
270  new MMapBookmarkStore(subscribeLogName_)));
271  client.setPublishStore(Store(new PublishStore(publishLogName_)));
272  return client;
273  }
274 
281  {
282  getBody().connectAndLogon();
283  }
284 
288  bool disconnected() const
289  {
290  return getBody().disconnected();
291  }
292 
297  ConnectionInfo getConnectionInfo() const
298  {
299  return getBody().getConnectionInfo();
300  }
301 
307  ConnectionInfo gatherConnectionInfo() const
308  {
309  return getBody().getConnectionInfo();
310  }
311 
312 private:
313  // Must make disconnect handler a friend to call the internal version
314  // of connectAndLogon so that the _disconnected flag won't get reset.
315  friend void HAClientImpl::HADisconnectHandler::invoke(Client&, void*);
316 
320  HAClient(const Client& rhs)
321  : Client(rhs)
322  {
323  assert(typeid(HAClientImpl) == typeid(_body.get()));
324  // Doing extra dynamic_cast to throw if bad coversion
325  //dynamic_cast<HAClientImpl*>(&(_body.get()));
326  }
327 
328  void connectAndLogonInternal()
329  {
330  getBody().connectAndLogonInternal();
331  }
332 
333  const HAClientImpl& getBody() const
334  {
335  return dynamic_cast<const HAClientImpl&>(_body.get());
336  }
337 
338  HAClientImpl& getBody()
339  {
340  return dynamic_cast<HAClientImpl&>(_body.get());
341  }
342 
343 }; // class HAClient
344 inline void HAClientImpl::HADisconnectHandler::invoke(Client& client, void*)
345 {
346  HAClient haClient(client);
347  // Intentional disconnect, bail
348  if(haClient.disconnected())
349  return;
350  DisconnectedException de("Disconnected");
351  haClient.getServerChooser().reportFailure((AMPSException&)de,
352  haClient.gatherConnectionInfo());
353  try
354  {
355  haClient.connectAndLogonInternal();
356  }
357  catch( AMPSException& )
358  {
359  }
360 }
361 
362 }// namespace AMPS
363 
364 #endif //_HACLIENT_H_
365 
void reportFailure(const AMPSException &exception_, const ConnectionInfo &info_)
Called by HAClient when an error occurs connecting to the current URI, and/or when an error occurs lo...
Definition: ServerChooser.hpp:86
Client(const std::string &clientName="")
Constructs a new client with a given client name.
Definition: ampsplusplus.hpp:4250
bool disconnected() const
Return whether or not the client is disconnected.
Definition: HAClient.hpp:288
void setPublishStore(const Store &publishStore_)
Set the publish store to be used by the client.
Definition: ampsplusplus.hpp:4570
HAClient(const std::string &name_)
Create an HAClient with the given name.
Definition: HAClient.hpp:87
Provides AMPS::MemoryBookmarkStore, a bookmark store that holds bookmarks in memory.
std::string getLogonOptions(void) const
Get the options passed to the server during logon.
Definition: HAClient.hpp:175
A BookmarkStoreImpl implementation that uses a memory mapped file for storage of the bookmarks...
Definition: MMapBookmarkStore.hpp:55
Provides AMPS::PublishStore, a publish store that uses memory-mapped files to provide a publish store...
STL namespace.
ConnectionInfo getConnectionInfo() const
Get the connection information for the current connection.
Definition: HAClient.hpp:297
HAClient(const HAClient &rhs)
Copy constructor, makes a new reference to the same body.
Definition: HAClient.hpp:100
The main class for interacting with AMPS.
Definition: ampsplusplus.hpp:4233
void setServerChooser(const ServerChooser &serverChooser_)
Set the ServerChooser used to determine the URI used when trying to connect and logon to AMPS...
Definition: HAClient.hpp:208
A StoreImpl implementation that uses a memory-mapped file to provide a publish store that persists ac...
Definition: PublishStore.hpp:46
Core type, function, and class declarations for the AMPS C++ client.
Interface for BookmarkStoreImpl classes.
Definition: ampsplusplus.hpp:833
HAClient()
Create an HAClient with no name The name for the client must be set using setName before it can be us...
Definition: HAClient.hpp:73
int getReconnectDelay() const
The current delay in milliseconds between reconnect attempts.
Definition: HAClient.hpp:141
void setReconnectDelay(int reconnectDelay_)
Set the delay between reconnect attempts in milliseconds.
Definition: HAClient.hpp:133
void setBookmarkStore(const BookmarkStore &bookmarkStore_)
Set the bookmark store to be used by the client.
Definition: ampsplusplus.hpp:4518
Provides AMPS::MemoryPublishStore, a publish store that holds messages in memory. ...
void setLogonOptions(const char *logonOptions_)
Set the options passed to the server during logon.
Definition: HAClient.hpp:183
int getTimeout() const
Get the current timeout used when attempting to log into AMPS.
Definition: HAClient.hpp:122
void setTimeout(int timeout_)
Set the timeout used when logging into AMPS.
Definition: HAClient.hpp:114
ReconnectDelayStrategy is called by AMPS::HAClient to determine how long to wait between attempts to ...
Definition: ReconnectDelayStrategy.hpp:44
HAClient & operator=(const HAClient &rhs)
Assignment operator, the body will be shared after this.
Definition: HAClient.hpp:105
A BookmarkStoreImpl implmentation that stores bookmarks in memory.
Definition: MemoryBookmarkStore.hpp:50
Abstract base class for choosing amongst multiple URIs for both the initial connection and reconnecti...
Definition: ServerChooser.hpp:46
ServerChooser getServerChooser() const
Return the ServerChooser currently used by the HAClient.
Definition: HAClient.hpp:199
void connectAndLogon()
Connect and logon to AMPS using the server(s) from the ServerChooser set on this HAClient and the Aut...
Definition: HAClient.hpp:280
Handle class for StoreImpl classes that track publish messages.
Definition: ampsplusplus.hpp:1241
Provides AMPS::MMapBookmarkStore, a bookmark store that uses a memory mapped file to provide efficien...
A highly-available Client that automatically reconnects and re-subscribes to AMPS instances upon disc...
Definition: HAClient.hpp:67
static HAClient createMemoryBacked(const std::string &name_)
Creates an HAClient with the given name that uses a memory-based Store for publish messages and a mem...
Definition: HAClient.hpp:232
void setReconnectDelayStrategy(const ReconnectDelayStrategy &strategy_)
Set the ReconnectDelayStrategy used to control delay behavior when connecting and reconnecting to ser...
Definition: HAClient.hpp:153
void setLogonOptions(const std::string &logonOptions_)
Set the options passed to the server during logon.
Definition: HAClient.hpp:191
ReconnectDelayStrategy getReconnectDelayStrategy(void) const
Get the ReconnectDelayStrategy used to control delay behavior when connecting and reconnecting to ser...
Definition: HAClient.hpp:165
Definition: ampsplusplus.hpp:136
static HAClient createFileBacked(const std::string &name_, const std::string &publishLogName_, const std::string &subscribeLogName_)
Creates an HAClient with the given name that uses a file-based Store for publish messages that is nam...
Definition: HAClient.hpp:264
HAClient(HAClientImpl *body_)
Create an HAClient wrapping the given implementation, used internally.
Definition: HAClient.hpp:95
A StoreImpl implementation that uses MemoryStoreBuffer as its buffer to hold published messages in me...
Definition: MemoryPublishStore.hpp:44
ConnectionInfo gatherConnectionInfo() const
Get the connection information for the current connection.
Definition: HAClient.hpp:307