Class ListenerComponent

java.lang.Object
net.bitbylogic.rps.listener.ListenerComponent

public class ListenerComponent extends Object
  • Constructor Details

    • ListenerComponent

      public ListenerComponent()
    • ListenerComponent

      public ListenerComponent(@Nullable @Nullable String channel)
      Constructs a new ListenerComponent instance with the specified channel name.
      Parameters:
      channel - the name of the Redis channel associated with this ListenerComponent. Can be null if no channel is specified.
    • ListenerComponent

      public ListenerComponent(@Nullable @Nullable String targetServerId, @Nullable @Nullable String channel)
      Constructs a new ListenerComponent instance with the specified target server ID and channel.
      Parameters:
      targetServerId - the ID of the target server associated with this ListenerComponent. Can be null.
      channel - the name of the Redis channel associated with this ListenerComponent. Can be null.
    • ListenerComponent

      public ListenerComponent(@Nullable @Nullable String targetServerId, @Nullable @Nullable String channel, @NotNull @NotNull HashMap<String,String> data)
      Constructs a new ListenerComponent instance with the specified target server ID, channel, and data.
      Parameters:
      targetServerId - the ID of the target server associated with this ListenerComponent. Can be null.
      channel - the name of the Redis channel associated with this ListenerComponent. Can be null.
      data - a HashMap containing initial key-value pairs to populate the component's data. Cannot be null.
  • Method Details

    • addData

      @Contract("_, _ -> this") public ListenerComponent addData(@NotNull @NotNull String key, @NotNull @NotNull Object object)
      Adds a key-value pair to the internal data map. The key is a string, and the value is serialized into JSON format using Gson before being stored.
      Parameters:
      key - the key associated with the data to add; must not be null.
      object - the object to serialize and store as the value; must not be null.
      Returns:
      the current instance of ListenerComponent, allowing method chaining.
    • addDataRaw

      @Contract("_, _ -> this") public ListenerComponent addDataRaw(@NotNull @NotNull String key, @NotNull @NotNull String value)
      Adds a raw key-value pair to the internal data storage of the ListenerComponent.
      Parameters:
      key - the key to associate with the value. It cannot be null.
      value - the value to store, associated with the provided key. It cannot be null.
      Returns:
      the current instance of ListenerComponent to allow for method chaining.
    • addTimedRequest

      @Contract("_, _, _ -> this") public ListenerComponent addTimedRequest(@NotNull @NotNull TimeUnit unit, int time, @NotNull @NotNull RedisTimedRequest request)
      Adds a timed request to the listener component. The request will be tracked for the specified duration and can execute associated callbacks for success or timeout scenarios.
      Parameters:
      unit - the time unit for the duration, cannot be null.
      time - the duration for which the request is tracked, in the specified time unit.
      request - the RedisTimedRequest object to be tracked, cannot be null.
      Returns:
      the current instance of ListenerComponent, allowing for method chaining.
    • addTimedResponse

      @Contract("_ -> this") public ListenerComponent addTimedResponse(@NotNull @NotNull RedisTimedResponse response)
      Adds a timed response to the list of timed responses managed by the ListenerComponent.
      Parameters:
      response - the RedisTimedResponse to be added. Must not be null.
      Returns:
      the ListenerComponent instance for method-chaining.
    • selfActivation

      @Contract("_ -> this") public ListenerComponent selfActivation(boolean selfActivation)
      Configures whether self-activation is allowed for this ListenerComponent.
      Parameters:
      selfActivation - a boolean value indicating whether self-activation is enabled. If true, self-activation is allowed; otherwise, it is disabled.
      Returns:
      the current instance of ListenerComponent, allowing for method chaining.
    • getData

      @CheckReturnValue public <T> T getData(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type)
      Retrieves data stored in the component using the specified key and deserializes it into an object of the specified type.
      Type Parameters:
      T - the type of the object to be returned
      Parameters:
      key - the key identifying the stored data; must not be null
      type - the Class object representing the type to deserialize to; must not be null
      Returns:
      the deserialized object of type T, or null if the key is not found in the data
    • getDataOrElse

      @CheckReturnValue public <T> T getDataOrElse(@NotNull @NotNull String key, @NotNull @NotNull Class<T> type, @NotNull T fallback)
      Retrieves data associated with a specific key and attempts to deserialize it into the specified type. If the key is not present in the data, the provided fallback value is returned.
      Type Parameters:
      T - the type of the object to be returned
      Parameters:
      key - the key identifying the data to retrieve; must not be null
      type - the Class object representing the type to deserialize to; must not be null
      fallback - the fallback value to return if the key is not found in the data; must not be null
      Returns:
      the deserialized object of type T if the key is found, or the provided fallback value otherwise
    • getRequestByID

      @CheckReturnValue public RedisTimedRequest getRequestByID(@NotNull @NotNull String id)
      Retrieves a RedisTimedRequest from the internal collection of timed requests based on the provided unique identifier.
      Parameters:
      id - the unique identifier of the request to retrieve; must not be null.
      Returns:
      the RedisTimedRequest associated with the given ID, or null if no matching request is found.