Skip to content

Commit 6a601bb

Browse files
authored
Merge pull request #1151 from ably/feature/liveobject-lifecycle-events
[ECO-5479][LiveObjects] Implement object lifecycle events
2 parents edf8568 + 915f305 commit 6a601bb

18 files changed

Lines changed: 224 additions & 29 deletions

File tree

lib/src/main/java/io/ably/lib/objects/ObjectsPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public interface ObjectsPlugin {
3838
*
3939
* @param channelName the name of the channel whose state has changed.
4040
* @param state the new state of the channel.
41-
* @param hasObjects flag indicates whether the channel has any associated live objects.
41+
* @param hasObjects flag indicates whether the channel has any associated objects.
4242
*/
4343
void handleStateChange(@NotNull String channelName, @NotNull ChannelState state, boolean hasObjects);
4444

lib/src/main/java/io/ably/lib/objects/RealtimeObjects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
/**
1414
* The RealtimeObjects interface provides methods to interact with live data objects,
1515
* such as maps and counters, in a real-time environment. It supports both synchronous
16-
* and asynchronous operations for retrieving and creating live objects.
16+
* and asynchronous operations for retrieving and creating objects.
1717
*
1818
* <p>Implementations of this interface must be thread-safe as they may be accessed
1919
* from multiple threads concurrently.

lib/src/main/java/io/ably/lib/objects/state/ObjectsStateChange.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
public interface ObjectsStateChange {
88
/**
9-
* Subscribes to a specific Live Objects synchronization state event.
9+
* Subscribes to a specific Objects synchronization state event.
1010
*
1111
* <p>This method registers the provided listener to be notified when the specified
1212
* synchronization state event occurs. The returned subscription can be used to
@@ -40,7 +40,7 @@ public interface ObjectsStateChange {
4040
void offAll();
4141

4242
/**
43-
* Interface for receiving notifications about Live Objects synchronization state changes.
43+
* Interface for receiving notifications about Objects synchronization state changes.
4444
* <p>
4545
* Implement this interface and register it with an ObjectsStateEmitter to be notified
4646
* when synchronization state transitions occur.

lib/src/main/java/io/ably/lib/objects/state/ObjectsStateEvent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.ably.lib.objects.state;
22

33
/**
4-
* Represents the synchronization state of Ably Live Objects.
4+
* Represents the synchronization state of Ably Objects.
55
* <p>
66
* This enum is used to notify listeners about state changes in the synchronization process.
77
* Clients can register an {@link ObjectsStateChange.Listener} to receive these events.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.ably.lib.objects.type;
2+
3+
/**
4+
* Represents lifecycle events for an Ably Object.
5+
* <p>
6+
* This enum notifies listeners about significant lifecycle changes that occur to an Object during its lifetime.
7+
* Clients can register a {@link ObjectLifecycleChange.Listener} to receive these events.
8+
*/
9+
public enum ObjectLifecycleEvent {
10+
/**
11+
* Indicates that an Object has been deleted (tombstoned).
12+
* Emitted once when the object is tombstoned server-side (i.e., deleted and no longer addressable).
13+
* Not re-emitted during client-side garbage collection of tombstones.
14+
*/
15+
DELETED
16+
}

lib/src/main/java/io/ably/lib/objects/type/ObjectUpdate.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
/**
66
* Abstract base class for all LiveMap/LiveCounter update notifications.
77
* Provides common structure for updates that occur on LiveMap and LiveCounter objects.
8-
* Contains the update data that describes what changed in the live object.
8+
* Contains the update data that describes what changed in the object.
99
* Spec: RTLO4b4
1010
*/
1111
public abstract class ObjectUpdate {

lib/src/main/java/io/ably/lib/objects/type/counter/LiveCounter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.ably.lib.objects.type.counter;
22

33
import io.ably.lib.objects.ObjectsCallback;
4+
import io.ably.lib.objects.type.ObjectLifecycleChange;
45
import org.jetbrains.annotations.Blocking;
56
import org.jetbrains.annotations.NonBlocking;
67
import org.jetbrains.annotations.NotNull;
@@ -11,7 +12,7 @@
1112
* It allows incrementing, decrementing, and retrieving the current value of the counter,
1213
* both synchronously and asynchronously.
1314
*/
14-
public interface LiveCounter extends LiveCounterChange {
15+
public interface LiveCounter extends LiveCounterChange, ObjectLifecycleChange {
1516

1617
/**
1718
* Increments the value of the counter by the specified amount.

lib/src/main/java/io/ably/lib/objects/type/map/LiveMap.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.ably.lib.objects.type.map;
22

33
import io.ably.lib.objects.ObjectsCallback;
4+
import io.ably.lib.objects.type.ObjectLifecycleChange;
45
import org.jetbrains.annotations.Blocking;
56
import org.jetbrains.annotations.NonBlocking;
67
import org.jetbrains.annotations.Contract;
@@ -14,7 +15,7 @@
1415
* The LiveMap interface provides methods to interact with a live, real-time map structure.
1516
* It supports both synchronous and asynchronous operations for managing key-value pairs.
1617
*/
17-
public interface LiveMap extends LiveMapChange {
18+
public interface LiveMap extends LiveMapChange, ObjectLifecycleChange {
1819

1920
/**
2021
* Retrieves the value associated with the specified key.

live-objects/src/main/kotlin/io/ably/lib/objects/DefaultRealtimeObjects.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import java.util.concurrent.CancellationException
2020

2121
/**
2222
* Default implementation of RealtimeObjects interface.
23-
* Provides the core functionality for managing live objects on a channel.
23+
* Provides the core functionality for managing objects on a channel.
2424
*/
2525
internal class DefaultRealtimeObjects(internal val channelName: String, internal val adapter: ObjectsAdapter): RealtimeObjects {
2626
private val tag = "DefaultRealtimeObjects"
2727
/**
28-
* @spec RTO3 - Objects pool storing all live objects by object ID
28+
* @spec RTO3 - Objects pool storing all objects by object ID
2929
*/
3030
internal val objectsPool = ObjectsPool(this)
3131

0 commit comments

Comments
 (0)