Class Event

java.lang.Object
org.omegazero.common.eventbus.Event

public class Event extends Object
Primarily used for calling event bus subscribers using an EventBus. An object of this class contains the method signature of the target method to call when dispatching this Event and several additional parameters for event execution.
Since:
2.1
  • Constructor Details

    • Event

      public Event(String methodName, Class<?>[] params)
      See Event(String, boolean, Class[], Class, boolean)

      The event defaults to being non-cancelable and configured to not collect all return values from subscribers (includeAllReturns is false). The default return type is void.

      Parameters:
      methodName - The name of the method that should be called when this event occurs
      params - The parameter types of the called method for this event. May be of length 0
    • Event

      public Event(String methodName, Class<?>[] params, Class<?> returnType)
      See Event(String, boolean, Class[], Class, boolean)

      The event defaults to being non-cancelable and configured to not collect all return values from subscribers (includeAllReturns is false).

      Parameters:
      methodName - The name of the method that should be called when this event occurs
      params - The parameter types of the called method for this event. May be of length 0
      returnType - The return type of event listener methods
    • Event

      public Event(String methodName, boolean cancelable, Class<?>[] params, Class<?> returnType, boolean includeAllReturns)
      Creates a general-purpose Event object.
      Parameters:
      methodName - The name of the method that should be called when this event occurs
      cancelable - Whether this event may be canceled using cancel()
      params - The parameter types of the called method for this event. May be of length 0
      returnType - The return type of event listener methods
      includeAllReturns - Include return values from all listener methods instead of just the first
  • Method Details

    • getMethodName

      public String getMethodName()
      Returns the method name of this event, which is the name of the method that is called when this event occurs.

      Further details are usage-defined.

      Returns:
      The method name of this event
    • isCancelable

      public boolean isCancelable()
      Whether this event was configured to allow cancellation using cancel().
      Returns:
      true if this event may be canceled
    • getParams

      public Class<?>[] getParams()
      Returns the method parameters of the target method of this event.
      Returns:
      The method parameters of this event
    • getReturnType

      public Class<?> getReturnType()
      Returns the return type of the target method of this event.
      Returns:
      The return type of this event
    • isIncludeAllReturns

      public boolean isIncludeAllReturns()
      Whether all event bus subscriber handlers should be called to collect a list of return values when dispatching this event. If this is false, event execution will be stopped when the first handler returns a non-null value.
      Returns:
      true if all return values should be collected
    • getEventSignature

      public String getEventSignature()
      Returns a string containing the method name and a string representation of method parameters and the return type of the target event method.
      Returns:
      The method signature
    • isCanceled

      public boolean isCanceled()
      Returns true if this event was canceled.
      Returns:
      true if this event was canceled
    • setCanceled

      public void setCanceled(boolean canceled)
      Sets whether this event is canceled. When an event handler calls this method with a value of true, subsequent event handlers will not be called.
      Parameters:
      canceled - Whether this event is canceled
      Throws:
      UnsupportedOperationException - If this method is called with a value of true but this event is not cancelable
    • cancel

      public void cancel()
      Cancels this event. An event may only be canceled if it is explicitly cancelable.

      A call to this method is equivalent to a call to

       setCanceled(true)
       
      Throws:
      UnsupportedOperationException - If this event is not cancelable
    • reset

      public void reset()
      Resets this event instance to initial values for reuse.
    • isStateful

      public boolean isStateful()
      Returns true if this event has a variable state. If it does not, this event object may be safely used multiple times and/or concurrently. Otherwise, it should not be used concurrently and reset() must be called before reuse.
      Returns:
      true if this event is stateful
    • createEventSignature

      public static String createEventSignature(String methodName, Class<?>[] params, Class<?> returnType)
      Creates a string containing unambiguous information about the given params, returnType and name of a method.
      Parameters:
      methodName - A method name
      params - The parameters of the method
      returnType - The return type
      Returns:
      The string
      See Also: