hyperledger/iroha
Iroha - A simple, decentralized ledger http://iroha.tech
iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver > Class Template Referencefinal

#include "subscription_engine.hpp"

Inheritance diagram for iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >:
Inheritance graph
Collaboration diagram for iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >:
Collaboration graph

Public Types

using EventKeyType = EventKey
 
using ReceiverType = Receiver
 
using SubscriberType = Receiver
 
using SubscriberWeakPtr = std::weak_ptr< SubscriberType >
 
using DispatcherType = typename std::decay< Dispatcher >::type
 
using DispatcherPtr = std::shared_ptr< DispatcherType >
 
using SubscribersContainer = std::list< std::tuple< typename Dispatcher::Tid, SubscriptionSetId, SubscriberWeakPtr > >
 
using IteratorType = typename SubscribersContainer::iterator
 

Public Member Functions

 SubscriptionEngine (DispatcherPtr const &dispatcher)
 
 ~SubscriptionEngine ()=default
 
void dispose () override
 
IteratorType subscribe (typename Dispatcher::Tid tid, SubscriptionSetId set_id, const EventKeyType &key, SubscriberWeakPtr ptr)
 
void unsubscribe (const EventKeyType &key, const IteratorType &it_remove)
 
size_t size (const EventKeyType &key) const
 
size_t size () const
 
template<typename... EventParams>
void notify (const EventKeyType &key, EventParams const &... args)
 
template<typename... EventParams>
void notifyDelayed (std::chrono::microseconds timeout, const EventKeyType &key, EventParams const &... args)
 

Detailed Description

template<typename EventKey, typename Dispatcher, typename Receiver>
class iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >

Template Parameters
EventKey- the type of a specific event from event set (e. g. a key from a storage or a particular kind of event from an enumeration)
Dispatcher- thread handler
Receiver- the type of an object that is a part of a Subscriber internal state and can be accessed on every event

Member Typedef Documentation

◆ DispatcherPtr

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::DispatcherPtr = std::shared_ptr<DispatcherType>

◆ DispatcherType

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::DispatcherType = typename std::decay<Dispatcher>::type

◆ EventKeyType

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::EventKeyType = EventKey

◆ IteratorType

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::IteratorType = typename SubscribersContainer::iterator

◆ ReceiverType

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::ReceiverType = Receiver

◆ SubscribersContainer

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::SubscribersContainer = std::list<std::tuple<typename Dispatcher::Tid, SubscriptionSetId, SubscriberWeakPtr> >

List is preferable here because this container iterators remain alive after removal from the middle of the container using custom allocator

◆ SubscriberType

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::SubscriberType = Receiver

◆ SubscriberWeakPtr

template<typename EventKey , typename Dispatcher , typename Receiver >
using iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::SubscriberWeakPtr = std::weak_ptr<SubscriberType>

Constructor & Destructor Documentation

◆ SubscriptionEngine()

template<typename EventKey , typename Dispatcher , typename Receiver >
iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::SubscriptionEngine ( DispatcherPtr const &  dispatcher)
inlineexplicit

◆ ~SubscriptionEngine()

template<typename EventKey , typename Dispatcher , typename Receiver >
iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::~SubscriptionEngine ( )
default

Member Function Documentation

◆ dispose()

template<typename EventKey , typename Dispatcher , typename Receiver >
void iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::dispose ( )
inlineoverridevirtual

◆ notify()

template<typename EventKey , typename Dispatcher , typename Receiver >
template<typename... EventParams>
void iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::notify ( const EventKeyType key,
EventParams const &...  args 
)
inline

Notify the event subscribers without delay

Template Parameters
EventParamsnotification event type
Parameters
keynotification event to be executed
argsevent data to transmit

◆ notifyDelayed()

template<typename EventKey , typename Dispatcher , typename Receiver >
template<typename... EventParams>
void iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::notifyDelayed ( std::chrono::microseconds  timeout,
const EventKeyType key,
EventParams const &...  args 
)
inline

Notify the event subscribers after a specified delay

Template Parameters
EventParamsnotification event type
Parameters
timeoutdelay before subscribers will be notified
keynotification event to be executed
argsevent data to transmit

◆ size() [1/2]

template<typename EventKey , typename Dispatcher , typename Receiver >
size_t iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::size ( const EventKeyType key) const
inline

Number of subscribers which listen to the current notification event

Parameters
keynotification event
Returns
number of subscribers

◆ size() [2/2]

template<typename EventKey , typename Dispatcher , typename Receiver >
size_t iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::size ( ) const
inline

Number of subscribers which listen to all notification events

Returns
number of subscribers

◆ subscribe()

template<typename EventKey , typename Dispatcher , typename Receiver >
IteratorType iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::subscribe ( typename Dispatcher::Tid  tid,
SubscriptionSetId  set_id,
const EventKeyType key,
SubscriberWeakPtr  ptr 
)
inline

Stores Subscriber object to retrieve later notifications

Parameters
tidThread ID in which subscribers callback will be executed
set_idsubscription set id is a group identifier in multiple subscriptions
keynotification event key that this subscriber will listen to
ptrsubscriber weak pointer
Returns
a position in an internal container with subscribers(!!! it must be kept valid in case the other subscriber will be deleted from this container)

◆ unsubscribe()

template<typename EventKey , typename Dispatcher , typename Receiver >
void iroha::subscription::SubscriptionEngine< EventKey, Dispatcher, Receiver >::unsubscribe ( const EventKeyType key,
const IteratorType it_remove 
)
inline

Stops the subscriber from listening to events

Parameters
keynotification event that must be unsubscribed
it_removeiterator to the subscribers position

The documentation for this class was generated from the following file: