类 EventPoolService

java.lang.Object
pkg.exoad.poprock.core.EventPoolService

@ServiceClass(requiresArming=false) public final class EventPoolService extends Object

EventPool

- The main global event registry for Poprock both the library and app for dispatching events. It is structured using a Map making it so that listeners can subscribe to a specific payload type (a class/record that implements EventPoolService.EventPayload).

Events can be dispatched by anyone

, which is a downside to this method, but it proves robust for the most part in terms of ease of use. Especially because there are no special permissions and other shenanigans that goes into just dispatching a simple event.

Listeners must know their EventPool

, this is the only measure that goes into categorizing data passing through. Listeners must know the pool id registerEventPool(int) in order to subscribe to it.

Events can be listened to by anyone

, which can be a good or bad. Especially since there could be credentials being passed around, but look, this app is designed for simply creating gradients not being the next solution to fixing some security pandemic.

Listeners must know what they want can or cannot exist

, meaning something that wants to listen to anything in the event pool must know that the event they want to subscribe has to exist first. EventPoolService.EventPool.isRegisteredPayloadID(Class)
 EventPool
 .getPool(1)
 .attachListener(FooEventPayload.class, () -> {}); // ERROR
 

The above code snipper throws an error is because FooEventPayload has not been registered to the EventPool by someone registerEventPool(int)

Event Pools are finalized

Once a event pool is registered using registerEventPool(int), there is no going back... Unless you use something quirky reflection manipulation (which highly against!).

作者:
Jack Meng
  • 字段详细资料

  • 构造器详细资料

    • EventPoolService

      private EventPoolService()
  • 方法详细资料

    • inferEventPool

      public static Optional<Collection<Class<? extends EventPoolService.EventPayload>>> inferEventPool(int id)
      Returns all of the payload types within an existing event payload.

      Has a chance to throw an error because of getPool(int)

      参数:
      id - identifier of the event pool (int)
      返回:
      A list of all of the types in that event pool
    • getPool

      public static EventPoolService.EventPool getPool(int id)
      Retrieves a specific EventPool based on an ID.

      Please note that this function has a chance to panic if the requested pool is not found!(Class)

      参数:
      id - identifier of the event pool (int)
      返回:
      The requested EventPool if found
    • registerEventPool

      public static int registerEventPool(int id)
      Tries to allocate a new event pool with the specific ID.

      This function has a chance to panic if the requested ID to register with already exists! This is because of the immutable nature of the EventPool design.

      参数:
      id - identifier of the event pool to register as (int)
      返回:
      identifier (unmodified)