-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0279bb4
commit ad0be31
Showing
6 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,3 +13,4 @@ toast/log/ | |
toast/groovy/ | ||
toast/preferences/ | ||
run/ | ||
libs/groovy-2.4.1.jar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
toast.version=0.1.0a | ||
toast.version=0.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/jaci/openrio/toast/core/shared/ModuleEventBus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package jaci.openrio.toast.core.shared; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* The Module Event Bus is a bus that allows for Modules to raise events | ||
* globally. This Event Bus allows for Modules to be optional dependencies, but | ||
* still have methods invoked/listened for | ||
* | ||
* @author Jaci | ||
*/ | ||
public class ModuleEventBus { | ||
|
||
static volatile ArrayList<ModuleEventListener> listeners = new ArrayList<>(); | ||
|
||
/** | ||
* Register a {@link jaci.openrio.toast.core.shared.ModuleEventListener} to the | ||
* bus. This is required for a class to be able to listen for events | ||
*/ | ||
public static void registerListener(ModuleEventListener listener) { | ||
listeners.add(listener); | ||
} | ||
|
||
/** | ||
* Raise an event to all listeners on the bus | ||
* @param sender The sender of the event. This is usually your Module's name unless otherwise | ||
* defined | ||
* @param event_type The type of event to raise. This should be a unique identifier | ||
* @param data The data passed to the event, or null if none are provided | ||
*/ | ||
public static void raiseEvent(String sender, String event_type, Object... data) { | ||
for (ModuleEventListener listener : listeners) | ||
listener.onModuleEvent(sender, event_type, data); | ||
} | ||
|
||
/** | ||
* Raise an event to all listeners on the bus, in a new Thread | ||
* @param sender The sender of the event. This is usually your Module's name unless otherwise | ||
* defined | ||
* @param event_type The type of event to raise. This should be a unique identifier | ||
* @param data The data passed to the event, or null if none are provided | ||
*/ | ||
public static void raiseConcurrentEvent(String sender, String event_type, Object... data) { | ||
new Thread() { | ||
public void run() { | ||
for (ModuleEventListener listener : listeners) | ||
listener.onModuleEvent(sender, event_type, data); | ||
} | ||
}.start(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/jaci/openrio/toast/core/shared/ModuleEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package jaci.openrio.toast.core.shared; | ||
|
||
/** | ||
* Implement this on classes you wish to act as listeners on the {@link jaci.openrio.toast.core.shared.ModuleEventBus} | ||
* | ||
* These classes are simple listeners for the events broadcast to all modules. This allows for optional dependencies | ||
* to trigger/listen for method invocations by other modules or Toast itself | ||
* | ||
* @author Jaci | ||
*/ | ||
public interface ModuleEventListener { | ||
|
||
/** | ||
* Invoked when an event is broadcast to this listener | ||
* @param sender The sender of the event. This is usually the Name of a Module | ||
* @param event_type The type of event that was raised. These are unique. See module | ||
* documentation for more details | ||
* @param data The data passed with the event. Keep in mind this can be null if no data | ||
* was provided. See module documentation for more details | ||
*/ | ||
public void onModuleEvent(String sender, String event_type, Object... data); | ||
|
||
} |