Class DietrichEvents2

java.lang.Object
de.florianmichael.dietrichevents2.DietrichEvents2

public class DietrichEvents2 extends Object
This class is the main class of DietrichEvents2.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    The errorHandler consumer will be called when an exception is thrown in a subscriber.
  • Constructor Summary

    Constructors
    Constructor
    Description
    DietrichEvents2(int trackingDefault, Consumer<Throwable> errorHandler)
    Creates a new instance of DietrichEvents2.
  • Method Summary

    Modifier and Type
    Method
    Description
     
    boolean
    hasSubscriber(int id)
     
    void
    post(int id, AbstractEvent event)
    This method is the recommended method for event calling, it calls the postInternal method but has some sanity checks and calls the errorHandler if an error occurs.
    void
    postInternal(int id, AbstractEvent event)
    This method calls all events, with the difference that it has no sanity checks for errors.
    protected void
    resizeArrays(int maxLength)
    Internal method that automatically resizes the array with all subscribers, this method should never be called simply because the event system calls it itself.
    void
    subscribe(int id, Object object)
    Subscribes a listener with the given ID to the given class, can be called multiple times.
    void
    subscribe(int id, Object object, int priority)
    Subscribes a listener with the given ID to the given class, can be called multiple times.
    void
    unsubscribe(int id, Object object)
    Unsubscribes a listener with the given ID from the given class, can be called multiple times.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • errorHandler

      public Consumer<Throwable> errorHandler
      The errorHandler consumer will be called when an exception is thrown in a subscriber.
  • Constructor Details

    • DietrichEvents2

      public DietrichEvents2(int trackingDefault, Consumer<Throwable> errorHandler)
      Creates a new instance of DietrichEvents2. The trackingDefault parameter is the default size of the array that stores all subscribers.
      Parameters:
      trackingDefault - The default size of the array that stores all subscribers.
      errorHandler - The errorHandler consumer will be called when an exception is thrown in a subscriber.
  • Method Details

    • global

      public static DietrichEvents2 global()
    • hasSubscriber

      public boolean hasSubscriber(int id)
      Parameters:
      id - The id of the event.
      Returns:
      Whether the event has subscribers.
    • subscribe

      public void subscribe(int id, Object object)
      Subscribes a listener with the given ID to the given class, can be called multiple times.
      Parameters:
      id - The id of the event.
      object - The object to subscribe.
    • resizeArrays

      protected void resizeArrays(int maxLength)
      Internal method that automatically resizes the array with all subscribers, this method should never be called simply because the event system calls it itself.
      Parameters:
      maxLength - The new maximum length of the array.
    • subscribe

      public void subscribe(int id, Object object, int priority)
      Subscribes a listener with the given ID to the given class, can be called multiple times. For priorities see Priorities. The higher a priority is, the earlier an event is called.
      Parameters:
      id - The id of the event.
      object - The object to subscribe.
      priority - The priority of the subscriber.
    • unsubscribe

      public void unsubscribe(int id, Object object)
      Unsubscribes a listener with the given ID from the given class, can be called multiple times.
      Parameters:
      id - The id of the event.
      object - The object to unsubscribe.
    • post

      public void post(int id, AbstractEvent event)
      This method is the recommended method for event calling, it calls the postInternal method but has some sanity checks and calls the errorHandler if an error occurs.
      Parameters:
      id - The id of the event.
      event - The event to post.
    • postInternal

      public void postInternal(int id, AbstractEvent event)
      This method calls all events, with the difference that it has no sanity checks for errors.
      Parameters:
      id - The id of the event.
      event - The event to post.