AMPS C/C++ Client Class Reference
AMPS C/C++ Client Version 5.3.3.1
HAClient.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 _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 
235  static HAClient createMemoryBacked(const std::string& name_)
236  {
237  HAClient client(name_);
239  client.setPublishStore(Store(new MemoryPublishStore(10000)));
240  return client;
241  }
242 
246  // that is named subscribeLogName_.
267  static HAClient createFileBacked(const std::string& name_,
268  const std::string& publishLogName_,
269  const std::string& subscribeLogName_)
270  {
271  HAClient client(name_);
273  new MMapBookmarkStore(subscribeLogName_)));
274  client.setPublishStore(Store(new PublishStore(publishLogName_)));
275  return client;
276  }
277 
284  {
285  getBody().connectAndLogon();
286  }
287 
291  bool disconnected() const
292  {
293  return getBody().disconnected();
294  }
295 
300  ConnectionInfo getConnectionInfo() const
301  {
302  return getBody().getConnectionInfo();
303  }
304 
311  ConnectionInfo gatherConnectionInfo() const // -V524
312  {
313  return getBody().getConnectionInfo();
314  }
315 
316 private:
317  // Must make disconnect handler a friend to call the internal version
318  // of connectAndLogon so that the _disconnected flag won't get reset.
319  friend void HAClientImpl::HADisconnectHandler::invoke(Client&, void*);
320 
324  HAClient(const Client& rhs)
325  : Client(rhs)
326  {
327  assert(typeid(HAClientImpl) == typeid(_body.get()));
328  // Doing extra dynamic_cast to throw if bad coversion
329  //dynamic_cast<HAClientImpl*>(&(_body.get()));
330  }
331 
332  void connectAndLogonInternal()
333  {
334  getBody().connectAndLogonInternal();
335  }
336 
337  const HAClientImpl& getBody() const
338  {
339  return dynamic_cast<const HAClientImpl&>(_body.get());
340  }
341 
342  HAClientImpl& getBody()
343  {
344  return dynamic_cast<HAClientImpl&>(_body.get());
345  }
346 
347 }; // class HAClient
348 inline void HAClientImpl::HADisconnectHandler::invoke(Client& client, void*)
349 {
350  HAClient haClient(client);
351  // Intentional disconnect, bail
352  if(haClient.disconnected())
353  return;
354  DisconnectedException de("Disconnected");
355  haClient.getServerChooser().reportFailure((AMPSException&)de,
356  haClient.gatherConnectionInfo());
357  try
358  {
359  haClient.connectAndLogonInternal();
360  }
361  catch( AMPSException& )
362  { // -V565
363  }
364 }
365 
366 }// namespace AMPS
367 
368 #endif //_HACLIENT_H_
369 
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:4266
bool disconnected() const
Return whether or not the client is disconnected.
Definition: HAClient.hpp:291
void setPublishStore(const Store &publishStore_)
Set the publish store to be used by the client.
Definition: ampsplusplus.hpp:4594
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:56
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:300
HAClient(const HAClient &rhs)
Copy constructor, makes a new reference to the same body.
Definition: HAClient.hpp:100
Client represents a connection to an AMPS server, but does not provide failover or reconnection behav...
Definition: ampsplusplus.hpp:4249
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: BookmarkStore.hpp:225
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:4542
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:56
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:283
Handle class for StoreImpl classes that track publish messages.
Definition: ampsplusplus.hpp:857
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:235
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:103
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:267
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
Definition: HAClient.hpp:311