|
| 1 | +package io.ably.lib.objects.type; |
| 2 | + |
| 3 | +import io.ably.lib.objects.ObjectsSubscription; |
| 4 | +import org.jetbrains.annotations.NonBlocking; |
| 5 | +import org.jetbrains.annotations.NotNull; |
| 6 | + |
| 7 | +/** |
| 8 | + * Interface for managing subscriptions to Object lifecycle events. |
| 9 | + * <p> |
| 10 | + * This interface provides methods to subscribe to and manage notifications about significant lifecycle |
| 11 | + * changes that occur to Object, such as deletion. More events can be added in the future. |
| 12 | + * Multiple listeners can be registered independently, and each can be managed separately. |
| 13 | + * <p> |
| 14 | + * Lifecycle events are different from data update events - they represent changes |
| 15 | + * to the object's existence state rather than changes to the object's data content. |
| 16 | + * |
| 17 | + * @see ObjectLifecycleEvent for the available lifecycle events |
| 18 | + */ |
| 19 | +public interface ObjectLifecycleChange { |
| 20 | + /** |
| 21 | + * Subscribes to a specific Object lifecycle event. |
| 22 | + * |
| 23 | + * <p>This method registers the provided listener to be notified when the specified |
| 24 | + * lifecycle event occurs. The returned subscription can be used to |
| 25 | + * unsubscribe later when the notifications are no longer needed. |
| 26 | + * |
| 27 | + * @param event the lifecycle event to subscribe to |
| 28 | + * @param listener the listener that will be called when the event occurs |
| 29 | + * @return a subscription object that can be used to unsubscribe from the event |
| 30 | + */ |
| 31 | + @NonBlocking |
| 32 | + ObjectsSubscription on(@NotNull ObjectLifecycleEvent event, @NotNull ObjectLifecycleChange.Listener listener); |
| 33 | + |
| 34 | + /** |
| 35 | + * Unsubscribes the specified listener from all lifecycle events. |
| 36 | + * |
| 37 | + * <p>After calling this method, the provided listener will no longer receive |
| 38 | + * any lifecycle event notifications. |
| 39 | + * |
| 40 | + * @param listener the listener to unregister from all events |
| 41 | + */ |
| 42 | + @NonBlocking |
| 43 | + void off(@NotNull ObjectLifecycleChange.Listener listener); |
| 44 | + |
| 45 | + /** |
| 46 | + * Unsubscribes all listeners from all lifecycle events. |
| 47 | + * |
| 48 | + * <p>After calling this method, no listeners will receive any lifecycle |
| 49 | + * event notifications until new listeners are registered. |
| 50 | + */ |
| 51 | + @NonBlocking |
| 52 | + void offAll(); |
| 53 | + |
| 54 | + /** |
| 55 | + * Interface for receiving notifications about Object lifecycle changes. |
| 56 | + * <p> |
| 57 | + * Implement this interface and register it with an ObjectLifecycleChange provider |
| 58 | + * to be notified when lifecycle events occur, such as object creation or deletion. |
| 59 | + */ |
| 60 | + @FunctionalInterface |
| 61 | + interface Listener { |
| 62 | + /** |
| 63 | + * Called when a lifecycle event occurs. |
| 64 | + * |
| 65 | + * @param lifecycleEvent The lifecycle event that occurred |
| 66 | + */ |
| 67 | + void onLifecycleEvent(@NotNull ObjectLifecycleEvent lifecycleEvent); |
| 68 | + } |
| 69 | +} |
0 commit comments