Skip to content

Commit

Permalink
[DXFC-402] Implement adding multiple symbols and removing symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
AnatolyKalin committed May 24, 2023
1 parent 706800f commit dfc1219
Show file tree
Hide file tree
Showing 13 changed files with 141 additions and 174 deletions.
18 changes: 9 additions & 9 deletions include/dxfeed_graal_cpp_api/api/DXEndpoint.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ struct DXEndpoint : SharedEntity {
LOCAL_HUB
};

static auto roleToString(Role role) {
static std::string roleToString(Role role) {
switch (role) {
case Role::FEED:
return "FEED";
Expand Down Expand Up @@ -488,7 +488,7 @@ struct DXEndpoint : SharedEntity {
public:
virtual ~DXEndpoint() {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint{{{}}}::~DXEndpoint()", handler_.toString());
Debugger::debug("DXEndpoint{" + handler_.toString() + " }::~DXEndpoint()");
}
}

Expand Down Expand Up @@ -534,7 +534,7 @@ struct DXEndpoint : SharedEntity {
*/
static std::shared_ptr<DXEndpoint> getInstance(Role role) {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::getInstance(role = {})", roleToString(role));
Debugger::debug("DXEndpoint::getInstance(role = " + roleToString(role) + ")");
}

std::lock_guard lock(MTX);
Expand Down Expand Up @@ -573,7 +573,7 @@ struct DXEndpoint : SharedEntity {
*/
static std::shared_ptr<DXEndpoint> create(Role role) {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::create(role = {})", roleToString(role));
Debugger::debug("DXEndpoint::create(role = " + roleToString(role) + ")");
}

return newBuilder()->withRole(role)->build();
Expand Down Expand Up @@ -749,7 +749,7 @@ struct DXEndpoint : SharedEntity {
*/
void close() {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint{{{}}}::close()", handler_.toString());
Debugger::debug("DXEndpoint{" + handler_.toString() + "}::close()");
}

closeImpl();
Expand Down Expand Up @@ -838,7 +838,7 @@ struct DXEndpoint : SharedEntity {
/// Releases the GraalVM handle
virtual ~Builder() {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::~Builder()", handler_.toString());
Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::~Builder()");
}
}

Expand All @@ -854,7 +854,7 @@ struct DXEndpoint : SharedEntity {
std::shared_ptr<Builder> withName(const std::string &name) {
// TODO: check invalid utf-8
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::withName(name = {})", handler_.toString(), name);
Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withName(name = " + name + ")");
}

return withProperty(NAME_PROPERTY, name);
Expand Down Expand Up @@ -892,8 +892,8 @@ struct DXEndpoint : SharedEntity {
*/
template <typename Properties> std::shared_ptr<Builder> withProperties(Properties &&properties) {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXEndpoint::Builder{{{}}}::withProperties(properties[{}])", handler_.toString(),
properties.size());
Debugger::debug("DXEndpoint::Builder{" + handler_.toString() + "}::withProperties(properties[" +
std::to_string(properties.size()) + "])");
}

for (auto &&[k, v] : properties) {
Expand Down
8 changes: 4 additions & 4 deletions include/dxfeed_graal_cpp_api/api/DXFeed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct DXFeed : SharedEntity {
public:
virtual ~DXFeed() noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeed{{{}}}::~DXFeed()", handler_.toString());
Debugger::debug("DXFeed{" + handler_.toString() + "}::~DXFeed()");
}
}

Expand All @@ -68,7 +68,7 @@ struct DXFeed : SharedEntity {
template <typename EventTypeIt>
std::shared_ptr<DXFeedSubscription> createSubscription(EventTypeIt begin, EventTypeIt end) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::createSubscription(eventTypes = {})", namesToString(begin, end));
Debugger::debug("{}::createSubscription(eventTypes = " + namesToString(begin, end) + ")");
}

auto sub = DXFeedSubscription::create(begin, end);
Expand All @@ -87,8 +87,8 @@ struct DXFeed : SharedEntity {
#endif
{
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::createSubscription(eventTypes = {})", toString(),
namesToString(std::begin(eventTypes), std::end(eventTypes)));
Debugger::debug(toString() + "::createSubscription(eventTypes = " +
namesToString(std::begin(eventTypes), std::end(eventTypes)) + ")");
}

auto sub = DXFeedSubscription::create(eventTypes);
Expand Down
18 changes: 9 additions & 9 deletions include/dxfeed_graal_cpp_api/api/DXFeedSubscription.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DXFeedSubscription : public SharedEntity {
DXFeedSubscription(EventTypeIt begin, EventTypeIt end) noexcept
: mtx_{}, handler_{}, eventListenerHandler_{}, onEvent_{} {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription(eventTypes = {})", namesToString(begin, end));
Debugger::debug("DXFeedSubscription(eventTypes = " + namesToString(begin, end) + ")");
}

auto list = handler_utils::EventClassList::create(begin, end);
Expand Down Expand Up @@ -72,7 +72,7 @@ class DXFeedSubscription : public SharedEntity {

~DXFeedSubscription() override {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription{{{}}}::~DXFeedSubscription()", handler_.toString());
Debugger::debug("DXFeedSubscription{" + handler_.toString() + "}::~DXFeedSubscription()");
}

tryCallWithLock(mtx_, [this] { closeImpl(); });
Expand All @@ -85,7 +85,7 @@ class DXFeedSubscription : public SharedEntity {
*/
static std::shared_ptr<DXFeedSubscription> create(const EventTypeEnum &eventType) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription::create(eventType = {})", eventType.getName());
Debugger::debug("DXFeedSubscription::create(eventType = " + eventType.getName() + ")");
}

auto sub = std::shared_ptr<DXFeedSubscription>(new DXFeedSubscription(eventType));
Expand All @@ -107,7 +107,7 @@ class DXFeedSubscription : public SharedEntity {
template <typename EventTypeIt>
static std::shared_ptr<DXFeedSubscription> create(EventTypeIt begin, EventTypeIt end) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("DXFeedSubscription::create(eventTypes = {})", namesToString(begin, end));
Debugger::debug("DXFeedSubscription::create(eventTypes = " + namesToString(begin, end) + ")");
}

auto sub = std::shared_ptr<DXFeedSubscription>(new DXFeedSubscription(begin, end));
Expand Down Expand Up @@ -178,7 +178,7 @@ class DXFeedSubscription : public SharedEntity {
*/
void close() noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::close()", toString());
Debugger::debug(toString() + "::close()");
}

std::lock_guard lock(mtx_);
Expand Down Expand Up @@ -227,7 +227,7 @@ class DXFeedSubscription : public SharedEntity {

template <typename Symbol> void addSymbol(Symbol &&symbol) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::addSymbol(symbol = {})", toString(), symbol);
Debugger::debug(toString() + "::addSymbol(symbol = " + std::string(symbol) + ")");
}

if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
Expand All @@ -245,7 +245,7 @@ class DXFeedSubscription : public SharedEntity {

template <typename Symbol> void removeSymbol(Symbol &&symbol) noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::removeSymbol(symbol = {})", toString(), symbol);
Debugger::debug(toString() + "::removeSymbol(symbol = " + symbol + ")");
}

if constexpr (std::is_same_v<std::decay_t<Symbol>, std::string>) {
Expand All @@ -272,7 +272,7 @@ class DXFeedSubscription : public SharedEntity {
*/
void clear() noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::clear()", toString());
Debugger::debug(toString() + "::clear()");
}

std::lock_guard lock(mtx_);
Expand All @@ -289,7 +289,7 @@ class DXFeedSubscription : public SharedEntity {
*/
bool isClosed() noexcept {
if constexpr (Debugger::isDebug) {
Debugger::debug("{}::isClosed()", toString());
Debugger::debug(toString() + "::isClosed()");
}

std::lock_guard lock(mtx_);
Expand Down
51 changes: 28 additions & 23 deletions include/dxfeed_graal_cpp_api/internal/Isolate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,21 @@ class Isolate final {
this->idx = idx++;

if constexpr (Debugger::traceIsolates) {
Debugger::trace("IsolateThread{{{}, isMain = {}, tid = {}, idx = {}}}()",
dxfcpp::toString(bit_cast<void *>(handle)), isMain, dxfcpp::toString(tid), idx);
Debugger::trace("IsolateThread{" + dxfcpp::toString(bit_cast<void *>(handle)) +
", isMain = " + dxfcpp::toString(isMain) + ", tid = " + dxfcpp::toString(tid) +
", idx = " + std::to_string(idx) + "}()");
}
}

CEntryPointErrors detach() noexcept {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("{}::detach()", toString());
Debugger::trace(toString() + "::detach()");
}

// OK if nothing is attached.
if (!handle) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tNot attached");
Debugger::trace(toString() + "::detach(): !handle => Not attached");
}

return CEntryPointErrors::NO_ERROR;
Expand All @@ -60,7 +61,7 @@ class Isolate final {

if (result == CEntryPointErrors::NO_ERROR) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tDetached");
Debugger::trace(toString() + "::detach(): result == CEntryPointErrors::NO_ERROR => Detached");
}

handle = nullptr;
Expand All @@ -71,12 +72,12 @@ class Isolate final {

CEntryPointErrors detachAllThreadsAndTearDownIsolate() noexcept {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("{}::detachAllThreadsAndTearDownIsolate()", toString());
Debugger::trace(toString() + "::detachAllThreadsAndTearDownIsolate()");
}

if (!handle) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tNot attached");
Debugger::trace(toString() + "::detachAllThreadsAndTearDownIsolate(): !handle => Not attached");
}

return CEntryPointErrors::NO_ERROR;
Expand All @@ -86,7 +87,9 @@ class Isolate final {

if (result == CEntryPointErrors::NO_ERROR) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tAll threads have been detached. The isolate has been teared down.");
Debugger::trace(toString() +
"::detachAllThreadsAndTearDownIsolate(): CEntryPointErrors::NO_ERROR => All "
"threads have been detached. The isolate has been teared down.");
}

handle = nullptr;
Expand All @@ -97,12 +100,12 @@ class Isolate final {

~IsolateThread() noexcept {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("~{}()", toString());
Debugger::trace(toString() + "::~()");
}

if (isMain) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tThis is the main thread");
Debugger::trace(toString() + "::~(): isMain => This is the main thread");
}

return;
Expand Down Expand Up @@ -130,8 +133,8 @@ class Isolate final {
currentIsolateThread_.isMain = true;

if constexpr (Debugger::traceIsolates) {
Debugger::trace("Isolate{{{}, main = {}, current = {}}}()", bit_cast<std::size_t>(handle),
mainIsolateThread_.toString(), currentIsolateThread_.toString());
Debugger::trace("Isolate{" + dxfcpp::toString(bit_cast<void *>(handle)) + ", main = " +
mainIsolateThread_.toString() + ", current = " + currentIsolateThread_.toString() + "}()");
}
}

Expand All @@ -149,28 +152,28 @@ class Isolate final {
auto result = std::shared_ptr<Isolate>{new Isolate{graalIsolateHandle, graalIsolateThreadHandle}};

if constexpr (Debugger::traceIsolates) {
Debugger::trace("Isolate::create() -> *{}", result->toString());
Debugger::trace("Isolate::create() -> *" + result->toString());
}

return result;
}

if constexpr (Debugger::traceIsolates) {
Debugger::trace("\t-> nullptr");
Debugger::trace("Isolate::create() -> nullptr");
}

return nullptr;
}

CEntryPointErrors attach() noexcept {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("{}::attach()", toString());
Debugger::trace(toString() + "::attach()");
}

// We will not re-attach.
if (!currentIsolateThread_.handle) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tNeeds to be attached.");
Debugger::trace(toString() + "::attach(): !currentIsolateThread_.handle => Needs to be attached.");
}

GraalIsolateThreadHandle newIsolateThreadHandle{};
Expand All @@ -179,7 +182,8 @@ class Isolate final {
result != CEntryPointErrors::NO_ERROR) {

if constexpr (Debugger::traceIsolates) {
Debugger::trace("\t-> {}", result.getDescription());
Debugger::trace(toString() + "::attach(): result != CEntryPointErrors::NO_ERROR [" +
std::to_string(result.getCode()) + "] " + result.getDescription());
}

return result;
Expand All @@ -189,11 +193,11 @@ class Isolate final {
currentIsolateThread_.isMain = mainIsolateThread_.handle == newIsolateThreadHandle;

if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tAttached: {}", currentIsolateThread_.toString());
Debugger::trace(toString() + "::attach(): Attached: " + currentIsolateThread_.toString());
}
} else {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\tCached: {}", currentIsolateThread_.toString());
Debugger::trace(toString() + "::attach(): Cached: " + currentIsolateThread_.toString());
}
}

Expand All @@ -202,7 +206,7 @@ class Isolate final {

GraalIsolateThreadHandle get() noexcept {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("{}::get()", toString());
Debugger::trace(toString() + "::get()");
}

return graal_get_current_thread(handle_);
Expand All @@ -221,7 +225,7 @@ class Isolate final {
static std::shared_ptr<Isolate> instance = create();

if constexpr (Debugger::traceIsolates) {
Debugger::trace("Isolate::getInstance() -> *{}", instance->toString());
Debugger::trace("Isolate::getInstance() -> *" + instance->toString());
}

return instance;
Expand All @@ -230,7 +234,7 @@ class Isolate final {
template <typename F>
auto runIsolated(F &&f) -> std::variant<CEntryPointErrors, std::invoke_result_t<F &&, GraalIsolateThreadHandle>> {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("{}::runIsolated({})", toString(), bit_cast<std::size_t>(&f));
Debugger::trace(toString() + "::runIsolated(" + typeid(f).name() + ")");
}

// Perhaps the code is already running within the GraalVM thread (for example, we are in a listener)
Expand All @@ -240,7 +244,8 @@ class Isolate final {

if (auto result = attach(); result != CEntryPointErrors::NO_ERROR) {
if constexpr (Debugger::traceIsolates) {
Debugger::trace("\t-> {}", result.getDescription());
Debugger::trace(toString() + "::runIsolated(" + typeid(f).name() +
"): result != CEntryPointErrors::NO_ERROR -> " + result.getDescription());
}

return result;
Expand Down
Loading

0 comments on commit dfc1219

Please sign in to comment.