All Projects → mmcshane → eventbus

mmcshane / eventbus

Licence: other
A threadsafe C++ implementation of the EventBus idiom

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to eventbus

vertx-vue-keycloak
This repo holds the source codes for the Medium Article "Vert.x + VueJS + OAuth2 in 5 steps"
Stars: ✭ 20 (-25.93%)
Mutual labels:  eventbus
mvp4g
A framework to build a gwt application the right way
Stars: ✭ 29 (+7.41%)
Mutual labels:  eventbus
LiteBus
LiteBus is an easy-to-use and ambitious in-process mediator providing the foundation to implement CQS. It is implemented with minimum reflection usage and streamable query support.
Stars: ✭ 20 (-25.93%)
Mutual labels:  eventbus
game-executor
采用Reactor模式,注册readycreate, readyfinish事件到更新服务UpdateService,通过处理后进行模型缓存,然后将消息转化为 dispatchThread消息分配模型需要的create, update, finish的事件进行单线程循环调度 。调度过程使用了系统预置锁模型,来进行多线程唤醒机制,将所有的update循环检测进行多 线程调度,多线程更新服务使用future-listener机制,在完成调度后,根据模型状态,如果模型存活重新将消息转化为update 事件注册到dispatchThread消息分配模型进行循环处理。如果模型死亡将消息转化为readyfinish事件注册到更新服务UpdateServic进行销毁 。这个系统实现了模型自动缓存,多…
Stars: ✭ 28 (+3.7%)
Mutual labels:  eventbus
vxrifa
Utility library for Vert.X that allows using strong-typed interfaces in communication through EventBus
Stars: ✭ 15 (-44.44%)
Mutual labels:  eventbus
DelphiEventBus
Implementation of event bus pattern for Delphi XE
Stars: ✭ 32 (+18.52%)
Mutual labels:  eventbus
CEventCenter
一个Android事件分发中心库,基于对象池及接口回调实现。实现类似BroadcastReceiver/RxBus/EventBus等的消息事件传递功能,用于在Activity/Fragment/Service之间的消息传递通讯。
Stars: ✭ 116 (+329.63%)
Mutual labels:  eventbus
reacted
Actor based reactive java framework for microservices in local and distributed environment
Stars: ✭ 17 (-37.04%)
Mutual labels:  eventbus
database-all
Eloquent ORM for Java 【database-spring-boot-starter】
Stars: ✭ 151 (+459.26%)
Mutual labels:  threadsafe
e
A library which combines a eventBus/emitter, DOM events management, delegated events, and event-based utils into a single lightweight and performant library.
Stars: ✭ 37 (+37.04%)
Mutual labels:  eventbus
MASA.Contrib
The purpose of MASA.Contrib is based on MASA.BuildingBlocks to provide open, community driven reusable components for building mesh applications. These components will be used by the MASA Stack and MASA Labs projects.
Stars: ✭ 102 (+277.78%)
Mutual labels:  eventbus
concurrent-resource
A header-only C++ library that allows easily creating thread-safe, concurrency friendly resources.
Stars: ✭ 17 (-37.04%)
Mutual labels:  threadsafe
ReactiveBus
🚍 Reactive Event Bus for JVM (1.7+) and Android apps built with RxJava 2
Stars: ✭ 17 (-37.04%)
Mutual labels:  eventbus
microservice-architecture-quick-start
Demonstrates how to build a Microservices Architecture using the C # language and the ASP.NET Core environment.
Stars: ✭ 16 (-40.74%)
Mutual labels:  eventbus
telephone-ts
Telephone-ts: The "Event Emitter-less" TypeScript Event Architecture.
Stars: ✭ 22 (-18.52%)
Mutual labels:  eventbus
Alpine
Basic event system framework using functional interfaces
Stars: ✭ 79 (+192.59%)
Mutual labels:  eventbus
treap
A thread-safe, persistent Treap (tree + heap) for ordered key-value mapping and priority sorting.
Stars: ✭ 23 (-14.81%)
Mutual labels:  threadsafe
react-native-event-bus
Event bus for react native, cross-interface communication solution, it works on iOS and Android.
Stars: ✭ 48 (+77.78%)
Mutual labels:  eventbus
ontology-eventbus
The Go Language Implementation of Ontology Actor Model
Stars: ✭ 24 (-11.11%)
Mutual labels:  eventbus
IpcEventBus
Faster than Intents and easier than AIDLs.
Stars: ✭ 35 (+29.63%)
Mutual labels:  eventbus

EventBus

It's an event bus. Subscribe to events. Publish events. Quoting the documentation for Google's implementation of the EventBus concept in Guava:

EventBus allows publish-subscribe-style communication between components without requiring the components to explicitly register with one another (and thus be aware of each other). It is designed exclusively to replace traditional […] in-process event distribution using explicit registration. It is not a general-purpose publish-subscribe system, nor is it intended for interprocess communication.

Caution: there are downsides to every pattern or idiom. EventBuses are no different. Read about some of the down-sides and alternatives and really think about if this is an approach you want to adopt.

Features

This library is fairly small and being header-only should be easy to integrate into existing projects. A C++11 compiler is required. All operations are threadsafe -- establishing and/or ending subscriptions concurrent with event publication is safe for any number of threads. Moreover, event publication is wait-free within the event bus. It may be the case that event handlers are not wait-free.

Event subscriptions are aware of event-type polymorphism. That is to say that given a pair of event types called Base and Derived where Base is a base class of Derived, a subscription to Base event types will be invoked when an event of type Derived is published. This is accomplished with a slight augmentation to normal C++ inheritance -- Derived must extend Base via the mpm::enable_polymorphic_dispatch class rather than directly. Rather than the following "normal" inheritance:

struct Derived : Base
{
}

Derived should be defined as

struct Derived : mpm::enable_polymorphic_dispatch<Derived, Base>
{
}

Defining Derived in this manner will allow and event of this type to be delivered as both Derived and Base.

It is not required that mpm::enable_polymorphic_dispatch be used. Any instance of a C++ object type can be published, however if polymorphic delivery is desired then mpm::enable_polymorphic_dispatch must be used.

Example Usage

Let's define some events

struct my_base_event : mpm::enable_polymorphic_dispatch<my_base_event>
{
    int x = 12;
};

struct my_derived_event
    : mpm::enable_polymorphic_dispatch<my_derived_event, my_base_event>
{
    int y = 5;
};

struct my_object {};

struct my_non_polymorphic_event : my_object
{
    int foo = -1;
};

Here's a quick look at publishing and subscribing to a polymorphic event

mpm::eventbus ebus;

// two subscriptions - 1 for my_base_event and 1 for my_derived_event

auto base_subscription = mpm::scoped_subscription<my_base_event> {
    ebus, [](const my_base_event& mbe) noexcept {
        std::cout << "handling a base event" << mbe.x;
    }
);

auto derived_subscription = mpm::scoped_subscription<my_derived_event> {
    ebus, [](const my_derived_event& mde) noexcept {
        std::cout << "handling a derived event" << mde.y;
    }
);

// publish
ebus.publish(my_derived_event{});

// subscriptions terminate at scope exit

Some things worth noting here

  • Both event handlers will fire
  • If you have a C++14 compiler, the callback can be declared with auto (e.g. const auto& event), removing the duplication in specifying the event type.

For non-polymorphic dispatch, any object type can be published and it will be handled by handlers for only that exact type.

mpm::eventbus ebus;

// two subscriptions - 1 for my_object, 1 for my_non_polymorphic_event

auto base_subscription = mpm::scoped_subscription<my_object> {
    ebus, [](const my_object& mo) noexcept {
        std::cout << "handling a my_object";
    }
};

auto non_poly_subscription = mpm::scoped_subscription<my_non_polymorhpic_event> {
    ebus, [](const my_non_polymorphic_event& mnpe) noexcept {
        std::cout << "handling a my_non_polymorphic_event " << mnpe.foo;
    }
);

// publish
ebus.publish(my_non_polymorphic_event{});

// subscriptions terminate at scope exit

Note with the above example that only the handler for my_non_polymorphic_event will fire because the inheritance relationship was not established via mpm::enable_polymorphic_dispatch.

Building

There's really no build needed as this is a header-only library, however if you want to run the unit tests or generate docs you can use the cmake build. To perform an out-of-tree build

$ cd "$(mktemp -d)"
$ cmake /path/to/eventbus/repository
$ make && make test
$ make docs # generates doxygen documentation under $PWD/docs

TODO

  • As it stands, publishing events from within event handlers is allowed. It's not clear that this is good.
  • Implement an asynchronous publication proxy
  • Maybe allow non-noexcept subscribers but unsubscribe them if they throw?
  • Pull leftright as an external project rather than embedding it under thirdparty/
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].