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

DefaultServerChooser.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 _DEFAULTSERVERCHOOSER_H_
27 #define _DEFAULTSERVERCHOOSER_H_
28
29 #include <amps/ampsplusplus.hpp>
30 #include <amps/ServerChooser.hpp>
31 #include <vector>
32
38
39 namespace AMPS
40 {
41
47 class DefaultServerChooser : public ServerChooserImpl
48 {
49 public:
52 DefaultServerChooser() : _current(0) {}
53
59 virtual std::string getCurrentURI()
60 {
61 if (_uris.size() > 0)
62 {
63 return _uris[_current];
64 }
65 return std::string();
66 }
67
71 void add(const std::string& uri_)
72 {
73 _uris.push_back(uri_);
74 }
75
79 template <class T>
80 void addAll(const T& uriContainer_)
81 {
82 for (typename T::const_iterator i = uriContainer_.begin(); i != uriContainer_.end(); ++i)
83 {
84 _uris.push_back(*i);
85 }
86 }
87
91 void remove(const std::string& /*uri_*/)
92 {
93 //Not permitted in DefaultServerChooser
94 }
95
101 virtual Authenticator& getCurrentAuthenticator()
102 {
103 return DefaultAuthenticator::instance();
104 }
105
111 virtual void reportFailure(const AMPSException& exception_,
112 const ConnectionInfo& /* info_ */)
113 {
114 if (strcmp(exception_.getClassName(), "DisconnectedException") != 0)
115 {
116 next();
117 }
118 }
119
125 virtual std::string getError()
126 {
127 return std::string();
128 }
129
133 virtual void reportSuccess(const ConnectionInfo& /* info_ */)
134 {
135 }
136
140 virtual void next()
141 {
142 if (_uris.size() == 0)
143 {
144 return;
145 }
146 _current = (_current + 1) % _uris.size();
147 }
148
152 ~DefaultServerChooser() {}
153
154 private:
155 std::vector<std::string> _uris;
156 size_t _current;
157 };
158
159 } //namespace AMPS
160
161 #endif //_DEFAULTSERVERCHOOSER_H_
162
ServerChooser.hpp
Provides AMPS::ServerChooser, the abstract base class that defines the interface that an AMPS::HAClie...
ampsplusplus.hpp
Core type, function, and class declarations for the AMPS C++ client.
AMPS::Authenticator
The interface for handling authentication with the AMPS server.
Definition: ampsplusplus.hpp:1007
AMPS::DefaultAuthenticator::instance
static Authenticator & instance()
Static function to return a static instance used when no Authenticator is supplied to a Client.
Definition: ampsplusplus.hpp:1060
AMPS::DefaultServerChooser
A server chooser that rotates through multiple URIs, in order.
Definition: DefaultServerChooser.hpp:48
AMPS::DefaultServerChooser::add
void add(const std::string &uri_)
Adds the given URI to self's list of URIs.
Definition: DefaultServerChooser.hpp:71
AMPS::DefaultServerChooser::reportSuccess
virtual void reportSuccess(const ConnectionInfo &)
Called by the HAClient when successfully connected and logged on to the current instance.
Definition: DefaultServerChooser.hpp:133
AMPS::DefaultServerChooser::next
virtual void next()
Advance the server chooser to the next server in the list, starting over with the first server when t...
Definition: DefaultServerChooser.hpp:140
AMPS::DefaultServerChooser::getCurrentAuthenticator
virtual Authenticator & getCurrentAuthenticator()
Returns the Authenticator instance associated with the current URI.
Definition: DefaultServerChooser.hpp:101
AMPS::DefaultServerChooser::DefaultServerChooser
DefaultServerChooser()
Default constructor which initializes an empty DefaultServerChooser.
Definition: DefaultServerChooser.hpp:52
AMPS::DefaultServerChooser::getCurrentURI
virtual std::string getCurrentURI()
Returns the current URI.
Definition: DefaultServerChooser.hpp:59
AMPS::DefaultServerChooser::~DefaultServerChooser
~DefaultServerChooser()
Destroy self.
Definition: DefaultServerChooser.hpp:152
AMPS::DefaultServerChooser::addAll
void addAll(const T &uriContainer_)
Adds the given URIs to self's list of URIs.
Definition: DefaultServerChooser.hpp:80
AMPS::DefaultServerChooser::remove
void remove(const std::string &)
Removes the given URI from self's list of URIs if found.
Definition: DefaultServerChooser.hpp:91
AMPS::DefaultServerChooser::reportFailure
virtual void reportFailure(const AMPSException &exception_, const ConnectionInfo &)
Called by HAClient when an error occurs connecting to the current URI, and/or when an error occurs lo...
Definition: DefaultServerChooser.hpp:111
AMPS::DefaultServerChooser::getError
virtual std::string getError()
Called by HAClient when no servers are available to provide a more detailed error message in the exce...
Definition: DefaultServerChooser.hpp:125
AMPS::ServerChooserImpl
Abstract base class for choosing amongst multiple URIs for both the initial connection and reconnecti...
Definition: ServerChooserImpl.hpp:40