59 const string& variable)
61 if (service.empty() || variable.empty())
return kEmptyStr;
63 string env_var = service +
"__RPC_CLIENT__" + variable;
73 return app->
GetConfig().
Get(service +
".rpc_client", variable);
84 unsigned int ret = NStr::StringToNumeric<unsigned int>(
str);
85 return ret > 0 ? ret : 3;
101 double sec = NStr::StringToNumeric<double>(
str);
126 unsigned int try_limit)
132 m_TryLimit(try_limit > 0 ? try_limit : 3)
194 ERR_POST(
"Affinity cannot be changed on a recursive request");
205 if (
m_Out.get() !=
nullptr) {
216 if (
m_Out.get() !=
nullptr) {
238 :
"(no_request_type)";
243 double span = max_span;
250 "Request canceled " + request_name);
271 "Connection stream is in bad state " + request_name);
322 "Failed to receive reply after "
330 "Retrying request stopped by the server: "
338 if (limit_by_time && span <= 0) {
341 "Failed to receive reply in "
343 +
' ' + request_name);
349 "Request canceled " + request_name);
354 "CRPCClient_Base::Reset() " + request_name);
368 _TRACE(
"CRPCClient_Base::x_ShouldRetry: retrying after " << tries
395 return "Content-Type: x-ncbi-data/x-asn-text\r\n";
397 return "Content-Type: x-ncbi-data/x-asn-binary\r\n";
399 return "Content-Type: application/xml\r\n";
401 return "Content-Type: application/json\r\n";
410 case eRetry:
return "eRetry";
411 case eFailed:
return "eFailed";
412 case eArgs:
return "eArgs";
413 case eOther:
return "eOther";
CCounterGuard(int *counter)
Guard for collecting diag messages (affects the current thread only).
Thrown on an attempt to access wrong choice variant.
CNcbiOstrstreamToString class helps convert CNcbiOstrstream to a string Sample usage:
Root class for all serialization exceptions.
Base class for all serializable objects.
The NCBI C++ standard methods for dealing with std::string.
bool HasLoadedConfig(void) const
Check if the config file has been loaded.
static CNcbiApplicationGuard InstanceGuard(void)
Singleton method.
const CNcbiRegistry & GetConfig(void) const
Get the application's cached configuration parameters (read-only).
void Release(void)
Release the guard.
EDiagSev GetDiagPostLevel(void)
Get current threshold severity for posting the messages.
void SetSeverityCap(EDiagSev sev)
Set new severity cap for use in PrintCapped mode.
#define ERR_POST(message)
Error posting with file, line number information but without error codes.
@ ePrintCapped
Print collected messages at reduced severity.
@ ePrint
Print all collected messages as is.
@ eDiag_Info
Informational message.
@ eDiag_Critical
Critical error message.
#define STD_CATCH_ALL_XX(err_name, err_subcode, message)
Standard handling of "exception"-derived exceptions; catches non-standard exceptions and generates "u...
TErrCode GetErrCode(void) const
Get error code.
#define NCBI_THROW(exception_class, err_code, message)
Generic macro to throw an exception, given the exception class, error code and message string.
void Warning(CExceptionArgs_Base &args)
virtual const char * GetErrCodeString(void) const
Get error code interpreted as text.
bool IsCanceled(void) const
void SetAffinity(const string &affinity)
CRPCClient_Base(const string &service, ESerialDataFormat format)
bool IsSetRetryContext(void) const
virtual void x_ReadReply(CObjectIStream &in, CSerialObject &reply)=0
void x_SetStream(CNcbiIostream *stream)
virtual void x_Disconnect(void)
Disconnect as cleanly as possible.
static const char * GetContentTypeHeader(ESerialDataFormat format)
unique_ptr< CObjectIStream > m_In
ESerialDataFormat m_Format
CMutex m_Mutex
To allow sharing across threads.
virtual void x_WriteRequest(CObjectOStream &out, const CSerialObject &request)=0
CRetryContext & GetRetryContext(void)
Read retry related data.
unique_ptr< CObjectOStream > m_Out
virtual string x_GetAffinity(const CSerialObject &request) const =0
CTimeSpan x_GetRetryDelay(double max_delay) const
virtual const CTypeInfo * GetThisTypeInfo(void) const =0
virtual bool x_ShouldRetry(unsigned int tries)
virtual const char * GetErrCodeString(void) const override
Get error code interpreted as text.
virtual void x_Connect(void)=0
These run with m_Mutex already acquired.
virtual ~CRPCClient_Base(void)
unique_ptr< CNcbiIostream > m_Stream
CHttpRetryContext m_RetryCtx
ESerialDataFormat
Data file format.
void x_Ask(const CSerialObject &request, CSerialObject &reply)
@ eArgs
Failed to send request arguments.
@ eRetry
Request failed, should be retried if possible.
@ eFailed
Request (or retry) failed.
@ eSerial_AsnText
ASN.1 text.
@ eSerial_AsnBinary
ASN.1 binary.
static CObjectOStream * Open(ESerialDataFormat format, CNcbiOstream &outStream, bool deleteOutStream)
Create serial object writer and attach it to an output stream.
static CObjectIStream * Open(ESerialDataFormat format, CNcbiIstream &inStream, bool deleteInStream)
Create serial object reader and attach it to an input stream.
virtual const string & Get(const string §ion, const string &name, TFlags flags=0) const
Get the parameter value.
bool IsSetStop(void) const
Check if STOP flag is set.
const CTimeSpan & GetDelay(void) const
Get retry delay.
void ResetNeedReconnect(void)
Reset need-reconnect flag (e.g.
bool IsSetContentOverride(void) const
Check if content source is set.
const string & GetContent(void) const
Get retry content.
bool IsSetDelay(void) const
Check if retry delay is set.
const string & GetStopReason(void) const
Get STOP reason (or empty string).
bool IsSetContent(void) const
Check if retry content is set and content-override flag assumes any content (eFromResponse or eData).
EContentOverride GetContentOverride(void) const
Get content source.
void SetContent(const string &content)
Set retry content.
bool GetNeedRetry(void) const
Check if another retry attempt has been requested (any new headers except STOP received in the last r...
void Reset(void)
Clear all options.
@ eFromResponse
On retry send content from the response body.
@ eNoContent
Do not send any content on retry.
#define END_NCBI_SCOPE
End previously defined NCBI scope.
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
IO_PREFIX::iostream CNcbiIostream
Portable alias for iostream.
bool NcbiStreamCopy(CNcbiOstream &os, CNcbiIstream &is)
Copy the entire contents of stream "is" to stream "os".
static enable_if< is_arithmetic< TNumeric >::value||is_convertible< TNumeric, Int8 >::value, string >::type NumericToString(TNumeric value, TNumToStringFlags flags=0, int base=10)
Convert numeric value to string.
static string & ToUpper(string &str)
Convert string to upper case – string& version.
bool IsEmpty(void) const
Return TRUE is an object keep zero time span.
long GetNanoSecondsAfterSecond(void) const
Get number of nanoseconds.
double GetAsDouble(void) const
Return time span as number of seconds.
long GetCompleteSeconds(void) const
Get number of complete seconds.
const string & GetName(void) const
Get name of this type.
void SleepMicroSec(unsigned long mc_sec, EInterruptOnSignal onsignal=eRestartOnSignal)
void SleepSec(unsigned long sec, EInterruptOnSignal onsignal=eRestartOnSignal)
Sleep.
static string s_GetConfigString(const string &service, const string &variable)
static unsigned int s_GetTryLimit(const string &service)
static CTimeSpan s_GetRetryDelay(const string &service)
static const char * str(char *buf, int n)