Package net.bitbylogic.rps.listener
Class ListenerComponent
java.lang.Object
net.bitbylogic.rps.listener.ListenerComponent
-
Constructor Summary
ConstructorsConstructorDescriptionListenerComponent(@Nullable String channel) Constructs a newListenerComponentinstance with the specified channel name.ListenerComponent(@Nullable String targetServerId, @Nullable String channel) Constructs a newListenerComponentinstance with the specified target server ID and channel.ListenerComponent(@Nullable String targetServerId, @Nullable String channel, @NotNull HashMap<String, String> data) Constructs a newListenerComponentinstance with the specified target server ID, channel, and data. -
Method Summary
Modifier and TypeMethodDescriptionAdds a key-value pair to the internal data map.addDataRaw(@NotNull String key, @NotNull String value) Adds a raw key-value pair to the internal data storage of theListenerComponent.addTimedRequest(@NotNull TimeUnit unit, int time, @NotNull RedisTimedRequest request) Adds a timed request to the listener component.addTimedResponse(@NotNull RedisTimedResponse response) Adds a timed response to the list of timed responses managed by theListenerComponent.<T> TRetrieves data stored in the component using the specified key and deserializes it into an object of the specified type.<T> TgetDataOrElse(@NotNull String key, @NotNull Class<T> type, T fallback) Retrieves data associated with a specific key and attempts to deserialize it into the specified type.getRequestByID(@NotNull String id) Retrieves aRedisTimedRequestfrom the internal collection of timed requests based on the provided unique identifier.selfActivation(boolean selfActivation) Configures whether self-activation is allowed for thisListenerComponent.
-
Constructor Details
-
ListenerComponent
public ListenerComponent() -
ListenerComponent
Constructs a newListenerComponentinstance with the specified channel name.- Parameters:
channel- the name of the Redis channel associated with this ListenerComponent. Can benullif no channel is specified.
-
ListenerComponent
public ListenerComponent(@Nullable @Nullable String targetServerId, @Nullable @Nullable String channel) Constructs a newListenerComponentinstance with the specified target server ID and channel.- Parameters:
targetServerId- the ID of the target server associated with this ListenerComponent. Can benull.channel- the name of the Redis channel associated with this ListenerComponent. Can benull.
-
ListenerComponent
public ListenerComponent(@Nullable @Nullable String targetServerId, @Nullable @Nullable String channel, @NotNull @NotNull HashMap<String, String> data) Constructs a newListenerComponentinstance with the specified target server ID, channel, and data.- Parameters:
targetServerId- the ID of the target server associated with this ListenerComponent. Can benull.channel- the name of the Redis channel associated with this ListenerComponent. Can benull.data- aHashMapcontaining initial key-value pairs to populate the component's data. Cannot benull.
-
-
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 theListenerComponent.- 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
ListenerComponentto 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 benull.time- the duration for which the request is tracked, in the specified time unit.request- theRedisTimedRequestobject to be tracked, cannot benull.- 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 theListenerComponent.- Parameters:
response- theRedisTimedResponseto be added. Must not benull.- Returns:
- the
ListenerComponentinstance for method-chaining.
-
selfActivation
Configures whether self-activation is allowed for thisListenerComponent.- Parameters:
selfActivation- a boolean value indicating whether self-activation is enabled. Iftrue, 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 benulltype- theClassobject representing the type to deserialize to; must not benull- Returns:
- the deserialized object of type
T, ornullif 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 nulltype- theClassobject representing the type to deserialize to; must not be nullfallback- the fallback value to return if the key is not found in the data; must not be null- Returns:
- the deserialized object of type
Tif the key is found, or the provided fallback value otherwise
-
getRequestByID
Retrieves aRedisTimedRequestfrom the internal collection of timed requests based on the provided unique identifier.- Parameters:
id- the unique identifier of the request to retrieve; must not benull.- Returns:
- the
RedisTimedRequestassociated with the given ID, ornullif no matching request is found.
-