13#include "arcane/impl/FlexLMTools.h"
20#define FLEXLMAPI_IS_STATIC_LIBRARY
24#include "arcane/core/IParallelSuperMng.h"
25#include "arcane/utils/FatalErrorException.h"
26#include "arcane/utils/TraceInfo.h"
27#include "arcane/utils/StringBuilder.h"
28#include "arcane/utils/Array.h"
39LicenseErrorException::
40LicenseErrorException(
const String& where)
49LicenseErrorException::
50LicenseErrorException(
const String& where,
const String& message)
51: Exception(
"LicenseError", where, message)
59LicenseErrorException::
60LicenseErrorException(
const TraceInfo& where)
61: Exception(
"LicenseError", where)
69LicenseErrorException::
70LicenseErrorException(
const TraceInfo& where,
const String& message)
71: Exception(
"LicenseError", where, message)
79void LicenseErrorException::
80explain(std::ostream& m)
const
82 m <<
"Licensing error occured.\n"
83 <<
"Excution stopped.\n";
89void LicenseErrorException::
90write(std::ostream& o)
const
94 o <<
"Exception thrown in: '" << where() <<
"\n";
96 if (!message().null())
97 o <<
"Message: " << message() <<
'\n';
100 String st = stackTrace().toString();
102 o <<
"\nCall stack:\n";
114FlexLMMng* FlexLMMng::m_instance = NULL;
121: m_parallel_super_mng(NULL)
133 if (m_instance == NULL)
144 if (m_parallel_super_mng != NULL)
151 m_parallel_super_mng = parallel_super_mng;
170 if (m_parallel_super_mng == NULL)
175 test = license_test((
char*)name.
localstr(), (
char*)String::format(
"{0}", version).localstr());
178 if (test != 0 && do_fatal)
179 throw LicenseErrorException(A_FUNCINFO, String::format(
"Checking feature {0} (v{1}) has failed\nFeature info: {2}", name, version,
featureInfo(name, version)));
189 if (m_parallel_super_mng == NULL)
194 m_features[name] += nb_licenses;
195 for (
Integer i = 0; i < nb_licenses; ++i)
196 error += license_begin_rc((
char*)name.
localstr(), (
char*)String::format(
"{0}", version).localstr());
200 throw LicenseErrorException(A_FUNCINFO, String::format(
"Cannot checkout {0} license{1} for feature {2} (v{3})\nFeature info: {4}", nb_licenses, ((nb_licenses > 1) ?
"s" :
""), name, version,
featureInfo(name, version)));
209 if (m_parallel_super_mng == NULL)
212 if (nb_licenses == 0)
216 FeatureMapType::iterator finder = m_features.find(name);
219 if (finder == m_features.end())
222 Integer& nb_allocated_licenses = finder->second;
223 if (nb_licenses == 0)
224 nb_licenses = nb_allocated_licenses;
225 for (
Integer i = 0; i < nb_licenses; ++i)
226 license_end_no_quit((
char*)name.
localstr());
228 nb_allocated_licenses -= nb_licenses;
229 if (nb_allocated_licenses < 0)
230 nb_allocated_licenses = 0;
240 if (m_parallel_super_mng == NULL)
244 for (FeatureMapType::iterator iter = m_features.begin(); iter != m_features.end(); ++iter) {
245 const String name = (*iter).first;
246 Integer nb_licenses = (*iter).second;
247 for (
Integer i = 0; i < nb_licenses; ++i)
248 license_end_no_quit((
char*)name.
localstr());
264 if (license_test((
char*)name.
localstr(), (
char*)String::format(
"{0}", version).localstr()) == 0) {
266 char** users = get_user_list((
char*)name.
localstr());
267 while (users[count]) {
268 info_builder += String::format(
"{0} ", users[count++]);
271 info_builder = String::format(
"no declared user");
274 info_builder = String::format(
"Used by {0} user{1} : ", count, ((count > 1) ?
"s" :
""), info_builder.
toString());
284 info =
"Unknown feature";
293 m_parallel_super_mng->broadcast(utf8_array, 0);
297 m_parallel_super_mng->broadcast(utf8_array, 0);
298 info = String::fromUtf8(utf8_array);
constexpr Integer size() const noexcept
Number of elements in the array.
Base class for an exception.
static FlexLMMng * instance()
Access to the singleton.
void getLicense(const String name, const Real version, Integer nb_licenses=1)
Requests the allocation of.
bool checkLicense(const String name, const Real version, bool do_fatal=true) const
Tests the presence of a static feature.
void setCheckInterval(const Integer t=120)
Sets a new license check periodicity.
void init(IParallelSuperMng *parallel_super_mng)
Initializes the license manager.
void releaseAllLicenses()
Releases all allocated licenses.
bool m_is_master
Is this host the master for checks?
void releaseLicense(const String name, Integer nb_licenses=0)
Releases the licenses for the feature.
String featureInfo(const String name, const Real version) const
Return info on feature.
Abstract class of the parallelism supervisor.
virtual Int32 commRank() const =0
Returns the process number (between 0 and nbProcess()-1).
Unicode character string constructor.
String toString() const
Returns the constructed character string.
Unicode character string.
bool null() const
Returns true if the string is null.
const char * localstr() const
Returns the conversion of the instance into UTF-8 encoding.
ByteConstArrayView utf8() const
Returns the conversion of the instance into UTF-8 encoding.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ArrayView< Integer > IntegerArrayView
C equivalent of a 1D array of integers.
UniqueArray< Byte > ByteUniqueArray
Dynamic 1D array of characters.
double Real
Type representing a real number.