|
RuneHive-Game
|
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< EventListener > | listeners = new LinkedHashSet<>() |
| The collection of listeners that are subscribed to this bus. | |
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.
Definition at line 30 of file DataBus.java.
|
private |
Prevent instantiation.
Definition at line 45 of file DataBus.java.
Referenced by getInstance().
|
static |
Gets the singleton object.
Definition at line 52 of file DataBus.java.
References DataBus(), and INSTANCE.
| 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.
| event | The event that will be sent to all listeners. |
Definition at line 92 of file DataBus.java.
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().
| 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.
| listener | The listener to subscribe to this bus. |
Definition at line 65 of file DataBus.java.
References listeners.
| 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.
| listener | The listener to unsubscribe from this bus. |
Definition at line 79 of file DataBus.java.
References listeners.
|
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().