cluster/Backend: Rename HandleRemoteEvent() to ProcessEvent()

...also add Backend::ProcessEvent() for backends to trigger event
processing without needing to use ProcessEventMessage().
This commit is contained in:
Arne Welzel 2025-02-06 16:33:19 +01:00
parent 390a4fc1bb
commit f8ef5addaa
3 changed files with 26 additions and 8 deletions

View file

@ -19,7 +19,7 @@
using namespace zeek::cluster; using namespace zeek::cluster;
bool detail::LocalEventHandlingStrategy::DoHandleRemoteEvent(std::string_view topic, detail::Event e) { bool detail::LocalEventHandlingStrategy::DoProcessEvent(std::string_view topic, detail::Event e) {
zeek::event_mgr.Enqueue(e.Handler(), std::move(e.Args()), util::detail::SOURCE_BROKER, 0, nullptr, e.Timestamp()); zeek::event_mgr.Enqueue(e.Handler(), std::move(e.Args()), util::detail::SOURCE_BROKER, 0, nullptr, e.Timestamp());
return true; return true;
} }
@ -123,7 +123,11 @@ void Backend::EnqueueEvent(EventHandlerPtr h, zeek::Args args) {
event_handling_strategy->EnqueueLocalEvent(h, std::move(args)); event_handling_strategy->EnqueueLocalEvent(h, std::move(args));
} }
bool Backend::ProcessEventMessage(std::string_view topic, std::string_view format, const byte_buffer_span payload) { bool Backend::ProcessEvent(std::string_view topic, detail::Event e) {
return event_handling_strategy->ProcessEvent(topic, std::move(e));
}
bool Backend::ProcessEventMessage(std::string_view topic, std::string_view format, byte_buffer_span payload) {
if ( format != event_serializer->Name() ) { if ( format != event_serializer->Name() ) {
zeek::reporter->Error("ProcessEventMessage: Wrong format: %s vs %s", std::string{format}.c_str(), zeek::reporter->Error("ProcessEventMessage: Wrong format: %s vs %s", std::string{format}.c_str(),
event_serializer->Name().c_str()); event_serializer->Name().c_str());
@ -139,7 +143,7 @@ bool Backend::ProcessEventMessage(std::string_view topic, std::string_view forma
return false; return false;
} }
return event_handling_strategy->HandleRemoteEvent(topic, std::move(*r)); return ProcessEvent(topic, std::move(*r));
} }
bool Backend::ProcessLogMessage(std::string_view format, byte_buffer_span payload) { bool Backend::ProcessLogMessage(std::string_view format, byte_buffer_span payload) {

View file

@ -102,7 +102,7 @@ public:
* *
* @return true if the remote event was handled successfully, else false. * @return true if the remote event was handled successfully, else false.
*/ */
bool HandleRemoteEvent(std::string_view topic, Event e) { return DoHandleRemoteEvent(topic, std::move(e)); } bool ProcessEvent(std::string_view topic, Event e) { return DoProcessEvent(topic, std::move(e)); }
/** /**
* Method for enquing backend specific events. * Method for enquing backend specific events.
@ -120,14 +120,14 @@ public:
private: private:
/** /**
* Hook method for implementing HandleRemoteEvent(). * Hook method for implementing ProcessEvent().
* *
* @param topic The topic on which the event was received. * @param topic The topic on which the event was received.
* @param ev The parsed event that was received. * @param ev The parsed event that was received.
* *
* @return true if the remote event was handled successfully, else false. * @return true if the remote event was handled successfully, else false.
*/ */
virtual bool DoHandleRemoteEvent(std::string_view topic, Event e) = 0; virtual bool DoProcessEvent(std::string_view topic, Event e) = 0;
/** /**
* Hook method for implementing EnqueueLocalEvent(). * Hook method for implementing EnqueueLocalEvent().
@ -143,7 +143,7 @@ private:
*/ */
class LocalEventHandlingStrategy : public EventHandlingStrategy { class LocalEventHandlingStrategy : public EventHandlingStrategy {
private: private:
bool DoHandleRemoteEvent(std::string_view topic, Event e) override; bool DoProcessEvent(std::string_view topic, Event e) override;
void DoEnqueueLocalEvent(EventHandlerPtr h, zeek::Args args) override; void DoEnqueueLocalEvent(EventHandlerPtr h, zeek::Args args) override;
}; };
@ -308,6 +308,20 @@ protected:
*/ */
void EnqueueEvent(EventHandlerPtr h, zeek::Args args); void EnqueueEvent(EventHandlerPtr h, zeek::Args args);
/**
* Process a cluster event.
*
* This method is called by ProcessEventMessage() and delegates
* to the event handling strategy. It should only be used by
* backends implementing their own serialization format. Other
* backends should not have a use for this and call ProcessEventMessage()
* directly instead.
*
* @param topic The topic on which the event was received.
* @param e The event as cluster::detail::Event.
*/
bool ProcessEvent(std::string_view topic, detail::Event e);
/** /**
* Process an incoming event message. * Process an incoming event message.
*/ */

View file

@ -53,7 +53,7 @@ private:
* will need some abstractions if client's can opt to use different encodings * will need some abstractions if client's can opt to use different encodings
* of events in the future. * of events in the future.
*/ */
bool DoHandleRemoteEvent(std::string_view topic, zeek::cluster::detail::Event e) override { bool DoProcessEvent(std::string_view topic, zeek::cluster::detail::Event e) override {
// If the client has left, no point in sending it any pending event. // If the client has left, no point in sending it any pending event.
if ( wsc->IsTerminated() ) if ( wsc->IsTerminated() )
return true; return true;