Skip to content

Commit 1197fe0

Browse files
committed
[ECO-5458] Added missing doc for subscription specific public interfaces
1 parent abdf445 commit 1197fe0

7 files changed

Lines changed: 142 additions & 13 deletions

File tree

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
package io.ably.lib.objects.type;
22

3+
import org.jetbrains.annotations.Nullable;
4+
5+
/**
6+
* Abstract base class for all LiveObject update notifications.
7+
* 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.
9+
*/
310
public abstract class LiveObjectUpdate {
11+
/** The update data containing details about the change that occurred */
12+
@Nullable
413
protected final Object update;
514

6-
protected LiveObjectUpdate(Object update) {
15+
/**
16+
* Creates a LiveObjectUpdate with the specified update data.
17+
*
18+
* @param update the data describing the change, or null for no-op updates
19+
*/
20+
protected LiveObjectUpdate(@Nullable Object update) {
721
this.update = update;
822
}
923
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,49 @@
44
import org.jetbrains.annotations.NonBlocking;
55
import org.jetbrains.annotations.NotNull;
66

7+
/**
8+
* Provides methods to subscribe to real-time updates on LiveCounter objects.
9+
* Enables clients to receive notifications when counter values change due to
10+
* operations performed by any client connected to the same channel.
11+
*/
712
public interface LiveCounterChange {
813

14+
/**
15+
* Subscribes to real-time updates on this LiveCounter object.
16+
* Multiple listeners can be subscribed to the same object independently.
17+
*
18+
* @param listener the listener to be notified of counter updates
19+
* @return an ObjectsSubscription for managing this specific listener
20+
*/
921
@NonBlocking
1022
@NotNull ObjectsSubscription subscribe(@NotNull Listener listener);
1123

24+
/**
25+
* Unsubscribes a specific listener from receiving updates.
26+
* Has no effect if the listener is not currently subscribed.
27+
*
28+
* @param listener the listener to be unsubscribed
29+
*/
1230
@NonBlocking
1331
void unsubscribe(@NotNull Listener listener);
1432

33+
/**
34+
* Unsubscribes all listeners from receiving updates.
35+
* No notifications will be delivered until new listeners are subscribed.
36+
*/
1537
@NonBlocking
1638
void unsubscribeAll();
1739

40+
/**
41+
* Listener interface for receiving LiveCounter updates.
42+
*/
1843
interface Listener {
44+
/**
45+
* Called when the LiveCounter has been updated.
46+
* Should execute quickly as it's called from the real-time processing thread.
47+
*
48+
* @param update details about the counter change
49+
*/
1950
void onUpdated(@NotNull LiveCounterUpdate update);
2051
}
2152
}

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

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,63 @@
44
import org.jetbrains.annotations.NotNull;
55

66
/**
7-
* Spec: RTLC11, RTLC11a
7+
* Represents an update that occurred on a LiveCounter object.
8+
* Contains information about counter value changes from increment/decrement operations.
9+
* Updates can represent positive changes (increments) or negative changes (decrements).
10+
*
11+
* @spec RTLC11, RTLC11a - LiveCounter update structure and behavior
812
*/
913
public class LiveCounterUpdate extends LiveObjectUpdate {
1014

15+
/**
16+
* Creates a no-op LiveCounterUpdate representing no actual change.
17+
*/
1118
public LiveCounterUpdate() {
1219
super(null);
1320
}
1421

22+
/**
23+
* Creates a LiveCounterUpdate with the specified amount change.
24+
*
25+
* @param amount the amount by which the counter changed (positive = increment, negative = decrement)
26+
*/
1527
public LiveCounterUpdate(@NotNull Long amount) {
1628
super(new Update(amount));
1729
}
1830

31+
/**
32+
* Gets the update information containing the amount of change.
33+
*
34+
* @return the Update object with the counter modification amount
35+
*/
1936
@NotNull
2037
public LiveCounterUpdate.Update getUpdate() {
2138
return (Update) update;
2239
}
2340

2441
/**
25-
* Spec: RTLC11b, RTLC11b1
42+
* Contains the specific details of a counter update operation.
43+
*
44+
* @spec RTLC11b, RTLC11b1 - Counter update data structure
2645
*/
2746
public static class Update {
2847
@NotNull
2948
private final Long amount;
3049

50+
/**
51+
* Creates an Update with the specified amount.
52+
*
53+
* @param amount the counter change amount (positive = increment, negative = decrement)
54+
*/
3155
public Update(@NotNull Long amount) {
3256
this.amount = amount;
3357
}
3458

59+
/**
60+
* Gets the amount by which the counter value was modified.
61+
*
62+
* @return the change amount (positive for increments, negative for decrements)
63+
*/
3564
public @NotNull Long getAmount() {
3665
return amount;
3766
}

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,49 @@
44
import org.jetbrains.annotations.NonBlocking;
55
import org.jetbrains.annotations.NotNull;
66

7+
/**
8+
* Provides methods to subscribe to real-time updates on LiveMap objects.
9+
* Enables clients to receive notifications when map entries are added, updated, or removed.
10+
* Uses last-write-wins conflict resolution when multiple clients modify the same key.
11+
*/
712
public interface LiveMapChange {
813

14+
/**
15+
* Subscribes to real-time updates on this LiveMap object.
16+
* Multiple listeners can be subscribed to the same object independently.
17+
*
18+
* @param listener the listener to be notified of map updates
19+
* @return an ObjectsSubscription for managing this specific listener
20+
*/
921
@NonBlocking
1022
@NotNull ObjectsSubscription subscribe(@NotNull Listener listener);
1123

24+
/**
25+
* Unsubscribes a specific listener from receiving updates.
26+
* Has no effect if the listener is not currently subscribed.
27+
*
28+
* @param listener the listener to be unsubscribed
29+
*/
1230
@NonBlocking
1331
void unsubscribe(@NotNull Listener listener);
1432

33+
/**
34+
* Unsubscribes all listeners from receiving updates.
35+
* No notifications will be delivered until new listeners are subscribed.
36+
*/
1537
@NonBlocking
1638
void unsubscribeAll();
1739

40+
/**
41+
* Listener interface for receiving LiveMap updates.
42+
*/
1843
interface Listener {
44+
/**
45+
* Called when the LiveMap has been updated.
46+
* Should execute quickly as it's called from the real-time processing thread.
47+
*
48+
* @param update details about which keys were modified and how
49+
*/
1950
void onUpdated(@NotNull LiveMapUpdate update);
2051
}
2152
}

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,48 @@
66
import java.util.Map;
77

88
/**
9-
* Spec: RTLM18, RTLM18a
9+
* Represents an update that occurred on a LiveMap object.
10+
* Contains information about which keys were modified and whether they were updated or removed.
11+
*
12+
* @spec RTLM18, RTLM18a - LiveMap update structure and behavior
1013
*/
1114
public class LiveMapUpdate extends LiveObjectUpdate {
1215

16+
/**
17+
* Creates a no-op LiveMapUpdate representing no actual change.
18+
*/
1319
public LiveMapUpdate() {
1420
super(null);
1521
}
1622

1723
/**
18-
* Constructor for LiveMapUpdate
19-
* @param update The map of updates
24+
* Creates a LiveMapUpdate with the specified key changes.
25+
*
26+
* @param update map of key names to their change types (UPDATED or REMOVED)
2027
*/
2128
public LiveMapUpdate(@NotNull Map<String, Change> update) {
2229
super(update);
2330
}
2431

2532
/**
26-
* Get the map of updates
27-
* @return The update map
33+
* Gets the map of key changes that occurred in this update.
34+
*
35+
* @return map of key names to their change types
2836
*/
2937
@NotNull
3038
public Map<String, Change> getUpdate() {
3139
return (Map<String, Change>) update;
3240
}
3341

3442
/**
35-
* Spec: RTLM18b
43+
* Indicates the type of change that occurred to a map key.
44+
*
45+
* @spec RTLM18b - Map change types
3646
*/
3747
public enum Change {
48+
/** The key was added or its value was modified */
3849
UPDATED,
50+
/** The key was removed from the map */
3951
REMOVED
4052
}
4153
}

live-objects/src/main/kotlin/io/ably/lib/objects/type/livecounter/LiveCounterChangeCoordinator.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import io.ably.lib.util.Log
88

99
internal val noOpCounterUpdate = LiveCounterUpdate()
1010

11+
/**
12+
* Interface for handling live counter changes by notifying subscribers of updates.
13+
* Implementations typically propagate updates through event emission to registered listeners.
14+
*/
1115
internal interface HandlesLiveCounterChange {
16+
/**
17+
* Notifies all registered listeners about a counter update by propagating the change through the event system.
18+
* This method is called when counter data changes and triggers the emission of update events to subscribers.
19+
*/
1220
fun notify(update: LiveCounterUpdate)
1321
}
1422

1523
internal abstract class LiveCounterChangeCoordinator: LiveCounterChange, HandlesLiveCounterChange {
16-
private val tag = "DefaultLiveCounterChangeCoordinator"
17-
1824
private val counterChangeEmitter = LiveCounterChangeEmitter()
1925

2026
override fun subscribe(listener: LiveCounterChange.Listener): ObjectsSubscription {

live-objects/src/main/kotlin/io/ably/lib/objects/type/livemap/LiveMapChangeCoordinator.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,19 @@ import io.ably.lib.util.Log
88

99
internal val noOpMapUpdate = LiveMapUpdate()
1010

11+
/**
12+
* Interface for handling live map changes by notifying subscribers of updates.
13+
* Implementations typically propagate updates through event emission to registered listeners.
14+
*/
1115
internal interface HandlesLiveMapChange {
16+
/**
17+
* Notifies all registered listeners about a map update by propagating the change through the event system.
18+
* This method is called when map data changes and triggers the emission of update events to subscribers.
19+
*/
1220
fun notify(update: LiveMapUpdate)
1321
}
1422

1523
internal abstract class LiveMapChangeCoordinator: LiveMapChange, HandlesLiveMapChange {
16-
private val tag = "DefaultLiveMapChangeCoordinator"
17-
1824
private val mapChangeEmitter = LiveMapChangeEmitter()
1925

2026
override fun subscribe(listener: LiveMapChange.Listener): ObjectsSubscription {

0 commit comments

Comments
 (0)