10#include <system_error>
20inline std::int32_t
envInt(
const char* name,
const std::int32_t fallback)
22 const char* value = std::getenv(name);
23 return (value !=
nullptr && *value !=
'\0') ?
static_cast<std::int32_t
>(std::strtol(value,
nullptr, 10)) : fallback;
32inline std::string
envString(
const char* name,
const std::string& fallback)
34 const char* value = std::getenv(name);
35 return (value !=
nullptr && *value !=
'\0') ? std::string{ value } : fallback;
45 const char* value = std::getenv(name);
46 return value !=
nullptr && *value !=
'\0';
56inline std::string
joinPath(
const std::string& dir,
const std::string& name)
62 return dir.back() ==
'/' ? dir + name : dir +
'/' + name;
73inline std::string
resolveAeronDir(
const char* envName,
const std::int32_t memberId)
75 const char* value = std::getenv(envName);
76 if (value !=
nullptr && *value !=
'\0')
80 const std::string name =
"seqeron-seq-aeron-" + std::to_string(memberId);
81 std::error_code error;
82 if (std::filesystem::is_directory(
"/dev/shm", error))
86 const char* tmpDir = std::getenv(
"TMPDIR");
87 return joinPath(tmpDir !=
nullptr && *tmpDir !=
'\0' ? tmpDir :
"/tmp", name);
99 return envString(envName,
"localhost:" + std::to_string(defaultPort));
106 static const bool enabled =
envFlag(
"SEQERON_VERBOSE_LOG");
bool verboseLoggingEnabled()
Definition Env.hpp:104
std::string resolveEgressEndpoint(const char *envName, const std::uint16_t defaultPort)
Resolves a "host:port" cluster-egress endpoint.
Definition Env.hpp:97
std::string resolveAeronDir(const char *envName, const std::int32_t memberId)
Resolves the co-located cluster member's Aeron directory, which an app shares to reach that node's qu...
Definition Env.hpp:73
std::string joinPath(const std::string &dir, const std::string &name)
Joins a directory and a name with exactly one separator.
Definition Env.hpp:56
std::int32_t envInt(const char *name, const std::int32_t fallback)
Reads a base-10 int from the environment.
Definition Env.hpp:20
bool envFlag(const char *name)
Whether a variable is set and non-empty — the convention every SEQERON_* opt-in switch uses.
Definition Env.hpp:43
std::string envString(const char *name, const std::string &fallback)
Reads a string from the environment.
Definition Env.hpp:32