RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.game.event.bus.DataBus Class Reference
Collaboration diagram for com.runehive.game.event.bus.DataBus:

Public Member Functions

void publish (Event event)
 Sends an Event to all subscribed listeners.
void subscribe (EventListener listener)
 Subscribes an EventListener to this bus.
void unsubscribe (EventListener listener)
 Unsubscribe an EventListener from this bus.

Static Public Member Functions

static DataBus getInstance ()
 Gets the singleton object.

Private Member Functions

 DataBus ()
 Prevent instantiation.

Static Private Attributes

static final DataBus INSTANCE = new DataBus()
 The singleton object.
static final Set< EventListenerlisteners = new LinkedHashSet<>()
 The collection of listeners that are subscribed to this bus.

Detailed Description

A Databus implementation for sending events.

The difference between a DataBus and publish/subscribe model is that. A DataBus is a form of publish/subscribe, the only difference is that the bus decouples the publisher and subscriber.

This pattern is different from the observer pattern in the sense that the observer pattern only allows for a one-to-many relationship wheres the DataBus allows for a many-to-many relationship.

EventListener's must subscribe to the bus in order to receive Event's send by the bus. EventListener's can then decide which Event's they are interested in.

See also
DataBusPattern
Author
nshusa

Definition at line 30 of file DataBus.java.

Constructor & Destructor Documentation

◆ DataBus()

com.runehive.game.event.bus.DataBus.DataBus ( )
private

Prevent instantiation.

Definition at line 45 of file DataBus.java.

45 {
46
47 }

Referenced by getInstance().

Here is the caller graph for this function:

Member Function Documentation

◆ getInstance()

DataBus com.runehive.game.event.bus.DataBus.getInstance ( )
static

Gets the singleton object.

Definition at line 52 of file DataBus.java.

52 {
53 return INSTANCE;
54 }

References DataBus(), and INSTANCE.

Here is the call graph for this function:

◆ publish()

void com.runehive.game.event.bus.DataBus.publish ( Event event)

Sends an Event to all subscribed listeners.

The listener's will choose which event. they are interested in.

Parameters
eventThe event that will be sent to all listeners.

Definition at line 92 of file DataBus.java.

92 {
93 listeners.forEach(it -> it.accept(event));
94 }

References listeners.

Referenced by com.runehive.game.world.entity.mob.player.exchange.trade.TradeSession.accept(), com.runehive.game.world.items.ground.GroundItem.create(), com.runehive.game.world.items.ground.GroundItem.createGlobal(), com.runehive.game.plugin.PluginContext.handleCommandEvent(), com.runehive.game.plugin.PluginContext.handlePickupItemEvent(), and com.runehive.game.world.entity.mob.player.relations.PlayerRelation.message().

Here is the caller graph for this function:

◆ subscribe()

void com.runehive.game.event.bus.DataBus.subscribe ( EventListener listener)

Subscribes an EventListener to this bus.

If a listener is subscribed to this bus, then the listener can choose which Event's its interested in.

Parameters
listenerThe listener to subscribe to this bus.

Definition at line 65 of file DataBus.java.

65 {
66 listeners.add(listener);
67 }

References listeners.

◆ unsubscribe()

void com.runehive.game.event.bus.DataBus.unsubscribe ( EventListener listener)

Unsubscribe an EventListener from this bus.

If a listener is no longer subscribed to this bus then the listener will no longer receive any events sent from the bus.

Parameters
listenerThe listener to unsubscribe from this bus.

Definition at line 79 of file DataBus.java.

79 {
80 listeners.remove(listener);
81 }

References listeners.

Member Data Documentation

◆ INSTANCE

final DataBus com.runehive.game.event.bus.DataBus.INSTANCE = new DataBus()
staticprivate

The singleton object.

Definition at line 40 of file DataBus.java.

Referenced by getInstance().

◆ listeners

final Set<EventListener> com.runehive.game.event.bus.DataBus.listeners = new LinkedHashSet<>()
staticprivate

The collection of listeners that are subscribed to this bus.

Definition at line 35 of file DataBus.java.

Referenced by publish(), subscribe(), and unsubscribe().


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