Skip to content

Commit 819ec3d

Browse files
committed
[ECO-5458] Added public interfaces for map and counter subscriptions
1 parent fd1d2cf commit 819ec3d

17 files changed

Lines changed: 122 additions & 10 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.ably.lib.objects;
22

33
import io.ably.lib.objects.state.ObjectsStateChange;
4+
import io.ably.lib.objects.type.counter.LiveCounter;
5+
import io.ably.lib.objects.type.map.LiveMap;
46
import io.ably.lib.types.Callback;
57
import org.jetbrains.annotations.Blocking;
68
import org.jetbrains.annotations.NonBlocking;

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

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

33
import io.ably.lib.types.Callback;
44
import org.jetbrains.annotations.Blocking;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.ably.lib.objects.type.counter;
2+
3+
import io.ably.lib.objects.ObjectsSubscription;
4+
import org.jetbrains.annotations.NonBlocking;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public interface LiveCounterChange {
8+
9+
@NonBlocking
10+
@NotNull ObjectsSubscription subscribe(@NotNull Listener listener);
11+
12+
@NonBlocking
13+
void unsubscribe(@NotNull Listener listener);
14+
15+
@NonBlocking
16+
void unsubscribeAll();
17+
18+
interface Listener {
19+
void onUpdated(@NotNull LiveCounterUpdate update);
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.ably.lib.objects.type.counter;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
/**
6+
* Spec: RTLC11, RTLC11a
7+
*/
8+
public class LiveCounterUpdate {
9+
@NotNull
10+
private final Long amount; // RTLC11b, RTLC11b1
11+
12+
public LiveCounterUpdate(@NotNull Long amount) {
13+
this.amount = amount;
14+
}
15+
16+
@NotNull
17+
public Long getUpdate() {
18+
return amount;
19+
}
20+
}

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

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

33
import io.ably.lib.types.Callback;
44
import org.jetbrains.annotations.Blocking;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package io.ably.lib.objects.type.map;
2+
3+
import io.ably.lib.objects.ObjectsSubscription;
4+
import org.jetbrains.annotations.NonBlocking;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public interface LiveMapChange {
8+
9+
@NonBlocking
10+
@NotNull ObjectsSubscription subscribe(@NotNull Listener listener);
11+
12+
@NonBlocking
13+
void unsubscribe(@NotNull Listener listener);
14+
15+
@NonBlocking
16+
void unsubscribeAll();
17+
18+
interface Listener {
19+
void onUpdated(@NotNull LiveMapUpdate update);
20+
}
21+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.ably.lib.objects.type.map;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* Spec: RTLM18, RTLM18a
9+
*/
10+
public class LiveMapUpdate {
11+
12+
@NotNull
13+
private final Map<String, Change> update;
14+
15+
/**
16+
* Constructor for LiveMapUpdate
17+
* @param update The map of updates
18+
*/
19+
public LiveMapUpdate(@NotNull Map<String, Change> update) {
20+
this.update = update;
21+
}
22+
23+
/**
24+
* Get the map of updates
25+
* @return The update map
26+
*/
27+
@NotNull
28+
public Map<String, Change> getUpdate() {
29+
return update;
30+
}
31+
32+
/**
33+
* Spec: RTLM18b
34+
*/
35+
public enum Change {
36+
UPDATED,
37+
REMOVED
38+
}
39+
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package io.ably.lib.objects
22

33
import io.ably.lib.objects.state.ObjectsStateChange
44
import io.ably.lib.objects.state.ObjectsStateEvent
5+
import io.ably.lib.objects.type.counter.LiveCounter
6+
import io.ably.lib.objects.type.map.LiveMap
57
import io.ably.lib.realtime.ChannelState
68
import io.ably.lib.types.Callback
79
import io.ably.lib.types.ProtocolMessage
@@ -167,7 +169,7 @@ internal class DefaultLiveObjects(internal val channelName: String, internal val
167169
objectsManager.clearBufferedObjectOperations() // RTO4b5
168170
// defer the state change event until the next tick if we started a new sequence just now due to being in initialized state.
169171
// this allows any event listeners to process the start of the new sequence event that was emitted earlier during this event loop.
170-
objectsManager.endSync(fromInitializedState) // RTO4b4
172+
objectsManager.endSync(fromInitializedState) // RTO4b4, RTO4b2a
171173
}
172174
}
173175

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ internal class ObjectsManager(private val liveObjects: DefaultLiveObjects): Obje
125125
}
126126

127127
val receivedObjectIds = mutableSetOf<String>()
128+
// RTO5c1a2 - List to collect updates for existing objects
128129
val existingObjectUpdates = mutableListOf<Pair<BaseLiveObject, Any>>()
129130

130131
// RTO5c1
@@ -148,7 +149,7 @@ internal class ObjectsManager(private val liveObjects: DefaultLiveObjects): Obje
148149
// RTO5c2 - need to remove LiveObject instances from the ObjectsPool for which objectIds were not received during the sync sequence
149150
liveObjects.objectsPool.deleteExtraObjectIds(receivedObjectIds)
150151

151-
// call subscription callbacks for all updated existing objects
152+
// RTO5c7 - call subscription callbacks for all updated existing objects
152153
existingObjectUpdates.forEach { (obj, update) ->
153154
obj.notifyUpdated(update)
154155
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.ably.lib.objects.ObjectOperation
55
import io.ably.lib.objects.ObjectState
66
import io.ably.lib.objects.type.BaseLiveObject
77
import io.ably.lib.objects.type.ObjectType
8+
import io.ably.lib.objects.type.counter.LiveCounter
89
import io.ably.lib.types.Callback
910
import java.util.concurrent.atomic.AtomicLong
1011

0 commit comments

Comments
 (0)