TensorFlow Serving C++ API Documentation
|
#include <event_bus.h>
Classes | |
struct | EventAndTime |
Event and the publish time associated with it. More... | |
struct | Options |
class | Subscription |
Public Types | |
using | Callback = std::function< void(const EventAndTime &)> |
Public Member Functions | |
std::unique_ptr< Subscription > | Subscribe (const Callback &callback) TF_LOCKS_EXCLUDED(mutex_) TF_MUST_USE_RESULT |
void | Publish (const E &event) TF_LOCKS_EXCLUDED(mutex_) |
Publishes an event to all subscribers. | |
Static Public Member Functions | |
static std::shared_ptr< EventBus > | CreateEventBus (const Options &options={}) |
EventBus enables basic publish / subscribe semantics for events amongst one or more publishers and subscribers. The purpose of EventBus for serving is to de-couple the code for such events, and is optimized for that use-case.
EventBus and Subscriptions can be destroyed safely in any order. There is a strict requirement for memory safety that a Subscription must be destroyed before any of the objects or memory that a subscriber's callback accesses.
Important scaling and threading limitations:
Scaling: The EventBus is not currently optimized for high scale, either in the number of subscribers or frequency of events. For such use-cases, consider alternate implementations or upgrades to this class.
Threading: EventBus is thread-safe. However, if any subscriber callback calls any method in the EventBus, it will deadlock. Subscribers are notified serially on the event publisher's thread. Thus, the amount of work done in a subscriber's callback should be very minimal.
This implementation is single-binary and does not communicate across tasks.
Note that the types used for typename E in EventBus must be moveable and thread-safe. Future implementations may read Events of type E in multiple threads.
Definition at line 63 of file event_bus.h.
using tensorflow::serving::EventBus< E >::Callback = std::function<void(const EventAndTime&)> |
The function type for EventBus Callbacks to be implemented by clients. Important Warnings:
Definition at line 115 of file event_bus.h.
|
static |
Creates an EventBus and returns a shared_ptr to it. This is the only allowed public mechanism for creating an EventBus so that we can track references to an EventBus uniformly.
Definition at line 191 of file event_bus.h.
std::unique_ptr< typename EventBus< E >::Subscription > tensorflow::serving::EventBus< E >::Subscribe | ( | const Callback & | callback | ) |
Subscribes to all events on the EventBus.
Returns a Subscription RAII object that can be used to unsubscribe, or will automatically unsubscribe on destruction. Returns a unique_ptr so that we can use the subscription's address to Unsubscribe.
Important contract for unsubscribing (deleting the RAII object):
Definition at line 178 of file event_bus.h.