Joutsen v0.5.0+12-g5dd5f7e
Classes | Public Member Functions | List of all members
Joutsen.Events.DefaultEventBus Class Reference

A class that represents an event bus which can be used to register to events of other objects or listen to events of other objects without ever holding a reference to them. More...

Public Member Functions

 DefaultEventBus ()
 
void RegisterReceiver< TPayload > (string name, Action< string, TPayload > receiver)
 Registers a System.Action as the listener of the event with name and TPayload. More...
 
void RemoveReceiver< TPayload > (string name, Action< string, TPayload > receiver)
 Removes a listener for an event. More...
 
void SendEvent< TPayload > (string name, TPayload payload)
 Fires the event with the given payload. More...
 
Event< TPayload > GetEvent< TPayload > (string name)
 Fetches the event with the given name and TPayload from the bus. More...
 
void AddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event to the bus for other objects to listen for. More...
 
Event< TPayload > AddEvent< TPayload > (String newEventName)
 Creates a new Framework.System.Events.Event and adds it to the bus. More...
 
Event< TPayload > TryAddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event if no event with the same name and type of payload is registered yet. More...
 
Event< TPayload > TryAddEvent< TPayload > (String newEventName)
 Creates and adds a new event if no event with the same name and type of payload is registered yet. More...
 
bool RemoveEvent< TPayload > (Event< TPayload > existingEvent)
 Removes an event from the bus. More...
 
Event< TPayload > RemoveEvent< TPayload > (String name)
 Removes an event from the bus. More...
 
bool CanHandleEvent< TPayload > (Event< TPayload > existingEvent)
 Checks if an event with the same name and payload is registered on the bus. More...
 
bool CanHandleEvent< TPayload > (String eventName)
 Checks if an event with the given name and payload is registered on the bus. More...
 
void ClearEvents ()
 Removes all events from the bus. More...
 
- Public Member Functions inherited from Joutsen.Events.EventBus
void RegisterReceiver< TPayload > (String name, Action< string, TPayload > receiver)
 Removes a listener for an event. More...
 
void RemoveReceiver< TPayload > (String name, Action< string, TPayload > receiver)
 Removes a listener for an event. More...
 
void SendEvent< TPayload > (String name, TPayload payload)
 Fires the event with the given payload. More...
 
Event< TPayload > GetEvent< TPayload > (String name)
 Fetches the event with the given name and TPayload from the bus. More...
 
void AddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event to the bus for other objects listen for. More...
 
Event< TPayload > AddEvent< TPayload > (String newEventName)
 Creates a new Framework.System.Events.Event and adds it to the bus. More...
 
Event< TPayload > TryAddEvent< TPayload > (Event< TPayload > newEvent)
 Adds a new event if no event with the same name and type of payload is registered yet. More...
 
Event< TPayload > TryAddEvent< TPayload > (String newEventName)
 Creates and adds a new event if no event with the same name and type of payload is registered yet. More...
 
bool RemoveEvent< TPayload > (Event< TPayload > existingEvent)
 Removes an event from the bus. More...
 
Event< TPayload > RemoveEvent< TPayload > (String name)
 Removes an event from the bus. More...
 
bool CanHandleEvent< TPayload > (Event< TPayload > existingEvent)
 Checks if an event with the same name and payload is registered on the bus. More...
 
bool CanHandleEvent< TPayload > (String eventName)
 Checks if an event with the given name and payload is registered on the bus. More...
 

Detailed Description

A class that represents an event bus which can be used to register to events of other objects or listen to events of other objects without ever holding a reference to them.

Remarks
The Framework.System.Events.EventBus uses a static store to manage the events and listeners. Thus it is possible to create different instances which reference the same state. Objects using the event bus do not have to take care of sharing instances of the bus itself. This store is created lazily when the first instance of Framework.System.Events.EventBus is created.
Since
0.2.0

Constructor & Destructor Documentation

◆ DefaultEventBus()

Joutsen.Events.DefaultEventBus.DefaultEventBus ( )

Member Function Documentation

◆ AddEvent< TPayload >() [1/2]

void Joutsen.Events.DefaultEventBus.AddEvent< TPayload > ( Event< TPayload >  newEvent)

Adds a new event to the bus for other objects to listen for.

Template Parameters
TPayloadthe event's payload
Parameters
newEventthe new event that is added to bus
Exceptions
System.ArgumentNullExceptionif newEvent is null
System.ArgumentExceptionif newEvent is not unique in name and payload

Implements Joutsen.Events.EventBus.

◆ AddEvent< TPayload >() [2/2]

Event< TPayload > Joutsen.Events.DefaultEventBus.AddEvent< TPayload > ( String  newEventName)

Creates a new Framework.System.Events.Event and adds it to the bus.

Template Parameters
TPayloadthe event's payload
Parameters
newEventNamethe name of the new event
Returns
the new event
Exceptions
System.ArgumentNullExceptionif newEvent is null
System.ArgumentExceptionif newEvent is not unique in name and payload

Implements Joutsen.Events.EventBus.

◆ CanHandleEvent< TPayload >() [1/2]

bool Joutsen.Events.DefaultEventBus.CanHandleEvent< TPayload > ( Event< TPayload >  existingEvent)

Checks if an event with the same name and payload is registered on the bus.

Template Parameters
TPayloadthe event's payload
Parameters
existingEventthe existing event to look for on the bus
Returns
true if an event with the same name and payload is registered on the bus, otherwise false
Exceptions
System.ArgumentNullExceptionit existingEvent is null

Implements Joutsen.Events.EventBus.

◆ CanHandleEvent< TPayload >() [2/2]

bool Joutsen.Events.DefaultEventBus.CanHandleEvent< TPayload > ( String  eventName)

Checks if an event with the given name and payload is registered on the bus.

Template Parameters
TPayloadthe event's payload
Parameters
eventNamethe name of the event
Returns
true if an event with the given name and payload is registered on the bus, otherwise false
Exceptions
System.ArgumentNullExceptionif eventName is null

Implements Joutsen.Events.EventBus.

◆ ClearEvents()

void Joutsen.Events.DefaultEventBus.ClearEvents ( )

Removes all events from the bus.

◆ GetEvent< TPayload >()

Event< TPayload > Joutsen.Events.DefaultEventBus.GetEvent< TPayload > ( string  name)

Fetches the event with the given name and TPayload from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
Returns
the event with the given name and TPayload
Exceptions
System.ArgumentNullExceptionif name is null
System.ArgumentExceptionif no event with name and TPayload exists

◆ RegisterReceiver< TPayload >()

void Joutsen.Events.DefaultEventBus.RegisterReceiver< TPayload > ( string  name,
Action< string, TPayload >  receiver 
)

Registers a System.Action as the listener of the event with name and TPayload.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
receiverthe System.Action that is registered as the listener of the event
Exceptions
System.ArgumentNullExceptionif name is null

◆ RemoveEvent< TPayload >() [1/2]

bool Joutsen.Events.DefaultEventBus.RemoveEvent< TPayload > ( Event< TPayload >  existingEvent)

Removes an event from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
existingEventthe event to remove
Returns
true if the event was found on the bus and was removed, otherwise false
Exceptions
System.ArgumentNullExceptionif existingEvent is null

Implements Joutsen.Events.EventBus.

◆ RemoveEvent< TPayload >() [2/2]

Event< TPayload > Joutsen.Events.DefaultEventBus.RemoveEvent< TPayload > ( String  name)

Removes an event from the bus.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
Returns
the removed event
Exceptions
System.ArgumentNullExceptionif name is null

Implements Joutsen.Events.EventBus.

◆ RemoveReceiver< TPayload >()

void Joutsen.Events.DefaultEventBus.RemoveReceiver< TPayload > ( string  name,
Action< string, TPayload >  receiver 
)

Removes a listener for an event.

Template Parameters
TPayloadthe event's payload
Parameters
namethe name of the event
receiverthe listener that is to be removed

◆ SendEvent< TPayload >()

void Joutsen.Events.DefaultEventBus.SendEvent< TPayload > ( string  name,
TPayload  payload 
)

Fires the event with the given payload.

Template Parameters
TPayloadthe type of the event's payload
Parameters
namethe name of the event
payloadthe payload of the event
Remarks
The event is fired in a different thread. Therefore the mothod will return before the event was actually fired.

◆ TryAddEvent< TPayload >() [1/2]

Event< TPayload > Joutsen.Events.DefaultEventBus.TryAddEvent< TPayload > ( Event< TPayload >  newEvent)

Adds a new event if no event with the same name and type of payload is registered yet.

Template Parameters
TPayloadthe type of the event's payload
Parameters
newEventthe new event
Returns
the added event if no event with the same name and type of payload was already registered, otherwise the already registered event
Exceptions
System.ArgumentNullExceptionif newEvent is null

Implements Joutsen.Events.EventBus.

◆ TryAddEvent< TPayload >() [2/2]

Event< TPayload > Joutsen.Events.DefaultEventBus.TryAddEvent< TPayload > ( String  newEventName)

Creates and adds a new event if no event with the same name and type of payload is registered yet.

Template Parameters
TPayloadthe type of the event's payload
Parameters
newEventNamethe name of the event
Returns
the added event if no event with the same name and type of payload was already registered, otherwise the already registered event
Exceptions
System.ArgumentExceptionif newEventName is null

Implements Joutsen.Events.EventBus.