Skip to content

Commit 90b7cf5

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

File tree

17 files changed

+113
-10
lines changed

17 files changed

+113
-10
lines changed

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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.ably.lib.objects.type.counter;
2+
3+
/**
4+
* Spec: RTLC11, RTLC11a
5+
*/
6+
public class LiveCounterUpdate {
7+
private final Long amount; // RTLC11b, RTLC11b1
8+
9+
public LiveCounterUpdate(Long amount) {
10+
this.amount = amount;
11+
}
12+
13+
public Long getUpdate() {
14+
return amount;
15+
}
16+
}

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: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.ably.lib.objects.type.map;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* Spec: RTLM18, RTLM18a
7+
*/
8+
public class LiveMapUpdate {
9+
private final Map<String, Change> update;
10+
11+
/**
12+
* Constructor for LiveMapUpdate
13+
* @param update The map of updates
14+
*/
15+
public LiveMapUpdate(Map<String, Change> update) {
16+
this.update = update;
17+
}
18+
19+
/**
20+
* Get the map of updates
21+
* @return The update map
22+
*/
23+
public Map<String, Change> getUpdate() {
24+
return update;
25+
}
26+
27+
/**
28+
* Spec: RTLM18b
29+
*/
30+
public enum Change {
31+
UPDATED,
32+
REMOVED
33+
}
34+
}

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)