AMPS C/C++ Client Class Reference AMPS C/C++ Client Version 5.3.5.1

HAClient.hpp
Go to the documentation of this file.
1 //
3 // Copyright (c) 2010-2025 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 <amps/ampsplusplus.hpp>
30 #include <amps/HAClientImpl.hpp>
31 #include <amps/MemoryPublishStore.hpp>
32 #include <amps/PublishStore.hpp>
33 #include <amps/MemoryBookmarkStore.hpp>
34 #include <amps/MMapBookmarkStore.hpp>
35
41
42
43 namespace AMPS
44 {
66
67 class HAClient : public Client
68 {
69 public:
73 HAClient()
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
105 HAClient& operator=(const HAClient& rhs)
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
153 void setReconnectDelayStrategy(const ReconnectDelayStrategy& strategy_)
154 {
155 getBody().setReconnectDelayStrategy(strategy_);
156 }
157
165 ReconnectDelayStrategy getReconnectDelayStrategy(void) const
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
199 ServerChooser getServerChooser() const
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_);
238 client.setBookmarkStore(BookmarkStore(new MemoryBookmarkStore()));
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_);
272 client.setBookmarkStore(BookmarkStore(
273 new MMapBookmarkStore(subscribeLogName_)));
274 client.setPublishStore(Store(new PublishStore(publishLogName_)));
275 return client;
276 }
277
283 void connectAndLogon()
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
325 void setDisconnectHandler(const DisconnectHandler&)
326 {
327 throw UsageException("Replacing the disconnect handler on an HAClient is not allowed.");
328 }
329
330 private:
331 // Must make disconnect handler a friend to call the internal version
332 // of connectAndLogon so that the _disconnected flag won't get reset.
333 friend void HAClientImpl::HADisconnectHandler::invoke(Client&, void*);
334
338 HAClient(const Client& rhs)
339 : Client(rhs)
340 {
341 assert(typeid(HAClientImpl) == typeid(_body.get()));
342 }
343
344 void connectAndLogonInternal()
345 {
346 getBody().connectAndLogonInternal();
347 }
348
349 const HAClientImpl& getBody() const
350 {
351 return dynamic_cast<const HAClientImpl&>(_body.get());
352 }
353
354 HAClientImpl& getBody()
355 {
356 return dynamic_cast<HAClientImpl&>(_body.get());
357 }
358
359 }; // class HAClient
360 inline void HAClientImpl::HADisconnectHandler::invoke(Client& client, void*)
361 {
362 HAClient haClient(client);
363 // Intentional disconnect, bail
364 if (haClient.disconnected())
365 {
366 return;
367 }
368 DisconnectedException de("Disconnected");
369 haClient.getServerChooser().reportFailure((AMPSException&)de,
370 haClient.gatherConnectionInfo());
371 try
372 {
373 haClient.connectAndLogonInternal();
374 }
375 catch (RetryOperationException& )
376 {
377 throw;
378 }
379 catch (AMPSException& )
380 {
381 // -V565
382 }
383 }
384
385 }// namespace AMPS
386
387 #endif //_HACLIENT_H_
388
MMapBookmarkStore.hpp
Provides AMPS::MMapBookmarkStore, a bookmark store that uses a memory mapped file to provide efficien...
MemoryBookmarkStore.hpp
Provides AMPS::MemoryBookmarkStore, a bookmark store that holds bookmarks in memory.
MemoryPublishStore.hpp
Provides AMPS::MemoryPublishStore, a publish store that holds messages in memory.
PublishStore.hpp
Provides AMPS::PublishStore, a publish store that uses memory-mapped files to provide a publish store...
ampsplusplus.hpp
Core type, function, and class declarations for the AMPS C++ client.
AMPS::BookmarkStore
Interface for BookmarkStoreImpl classes.
Definition: BookmarkStore.hpp:229
AMPS::Client
Client represents a connection to an AMPS server, but does not provide failover or reconnection behav...
Definition: ampsplusplus.hpp:5190
AMPS::Client::setBookmarkStore
void setBookmarkStore(const BookmarkStore &bookmarkStore_)
Set the bookmark store to be used by the client.
Definition: ampsplusplus.hpp:5552
AMPS::Client::setPublishStore
void setPublishStore(const Store &publishStore_)
Set the publish store to be used by the client.
Definition: ampsplusplus.hpp:5604
AMPS::HAClient
A highly-available Client that automatically reconnects and re-subscribes to AMPS instances upon disc...
Definition: HAClient.hpp:68
AMPS::HAClient::getServerChooser
ServerChooser getServerChooser() const
Return the ServerChooser currently used by the HAClient.
Definition: HAClient.hpp:199
AMPS::HAClient::getReconnectDelay
int getReconnectDelay() const
The current delay in milliseconds between reconnect attempts.
Definition: HAClient.hpp:141
AMPS::HAClient::HAClient
HAClient(const HAClient &rhs)
Copy constructor, makes a new reference to the same body.
Definition: HAClient.hpp:100
AMPS::HAClient::createFileBacked
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
AMPS::HAClient::disconnected
bool disconnected() const
Return whether or not the client is disconnected.
Definition: HAClient.hpp:291
AMPS::HAClient::getReconnectDelayStrategy
ReconnectDelayStrategy getReconnectDelayStrategy(void) const
Get the ReconnectDelayStrategy used to control delay behavior when connecting and reconnecting to ser...
Definition: HAClient.hpp:165
AMPS::HAClient::HAClient
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
AMPS::HAClient::setLogonOptions
void setLogonOptions(const char *logonOptions_)
Set the options passed to the server during logon.
Definition: HAClient.hpp:183
AMPS::HAClient::gatherConnectionInfo
ConnectionInfo gatherConnectionInfo() const
Definition: HAClient.hpp:311
AMPS::HAClient::getLogonOptions
std::string getLogonOptions(void) const
Get the options passed to the server during logon.
Definition: HAClient.hpp:175
AMPS::HAClient::setLogonOptions
void setLogonOptions(const std::string &logonOptions_)
Set the options passed to the server during logon.
Definition: HAClient.hpp:191
AMPS::HAClient::connectAndLogon
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
AMPS::HAClient::HAClient
HAClient(const std::string &name_)
Create an HAClient with the given name.
Definition: HAClient.hpp:87
AMPS::HAClient::getConnectionInfo
ConnectionInfo getConnectionInfo() const
Get the connection information for the current connection.
Definition: HAClient.hpp:300
AMPS::HAClient::setDisconnectHandler
void setDisconnectHandler(const DisconnectHandler &)
Definition: HAClient.hpp:325
AMPS::HAClient::setServerChooser
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
AMPS::HAClient::createMemoryBacked
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
AMPS::HAClient::getTimeout
int getTimeout() const
Get the current timeout used when attempting to log into AMPS.
Definition: HAClient.hpp:122
AMPS::HAClient::operator=
HAClient & operator=(const HAClient &rhs)
Assignment operator, the body will be shared after this.
Definition: HAClient.hpp:105
AMPS::HAClient::setTimeout
void setTimeout(int timeout_)
Set the timeout used when logging into AMPS.
Definition: HAClient.hpp:114
AMPS::HAClient::setReconnectDelayStrategy
void setReconnectDelayStrategy(const ReconnectDelayStrategy &strategy_)
Set the ReconnectDelayStrategy used to control delay behavior when connecting and reconnecting to ser...
Definition: HAClient.hpp:153
AMPS::HAClient::HAClient
HAClient(HAClientImpl *body_)
Create an HAClient wrapping the given implementation, used internally.
Definition: HAClient.hpp:95
AMPS::HAClient::setReconnectDelay
void setReconnectDelay(int reconnectDelay_)
Set the delay between reconnect attempts in milliseconds.
Definition: HAClient.hpp:133
AMPS::Handler< DisconnectHandlerFunc, Client & >
AMPS::MMapBookmarkStore
A BookmarkStoreImpl implementation that uses a memory mapped file for storage of the bookmarks.
Definition: MMapBookmarkStore.hpp:57
AMPS::MemoryBookmarkStore
A BookmarkStoreImpl implementation that stores bookmarks in memory.
Definition: MemoryBookmarkStore.hpp:59
AMPS::MemoryPublishStore
A StoreImpl implementation that uses MemoryStoreBuffer as its buffer to hold published messages in me...
Definition: MemoryPublishStore.hpp:45
AMPS::PublishStore
A StoreImpl implementation that uses a memory-mapped file to provide a publish store that persists ac...
Definition: PublishStore.hpp:47
AMPS::ReconnectDelayStrategy
ReconnectDelayStrategy is called by AMPS::HAClient to determine how long to wait between attempts to ...
Definition: ReconnectDelayStrategy.hpp:45
AMPS::ServerChooser
Abstract base class for choosing amongst multiple URIs for both the initial connection and reconnecti...
Definition: ServerChooser.hpp:47
AMPS::Store
Handle class for StoreImpl classes that track publish messages.
Definition: ampsplusplus.hpp:1224