Skip to content

Commit 8803630

Browse files
committed
[ECO-5482] Updated LiveObjects interface as per spec
- Implemented LiveMapValue as a separate type representing map values - Updated interface method signatures
1 parent 5045f8e commit 8803630

3 files changed

Lines changed: 486 additions & 41 deletions

File tree

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

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
import io.ably.lib.objects.state.ObjectsStateChange;
44
import io.ably.lib.objects.type.counter.LiveCounter;
55
import io.ably.lib.objects.type.map.LiveMap;
6+
import io.ably.lib.objects.type.map.LiveMapValue;
67
import io.ably.lib.types.Callback;
78
import org.jetbrains.annotations.Blocking;
89
import org.jetbrains.annotations.NonBlocking;
910
import org.jetbrains.annotations.NotNull;
1011

11-
1212
import java.util.Map;
1313

1414
/**
@@ -34,46 +34,45 @@ public interface LiveObjects extends ObjectsStateChange {
3434
LiveMap getRoot();
3535

3636
/**
37-
* Creates a new LiveMap based on an existing LiveMap.
37+
* Creates a new empty LiveMap with no entries.
3838
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
3939
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
4040
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
41-
* using the provided data and returns it.
41+
* and returns it.
4242
*
43-
* @param liveMap the existing LiveMap to base the new LiveMap on.
44-
* @return the newly created LiveMap instance.
43+
* @return the newly created empty LiveMap instance.
4544
*/
4645
@Blocking
4746
@NotNull
48-
LiveMap createMap(@NotNull LiveMap liveMap);
47+
LiveMap createMap();
4948

5049
/**
51-
* Creates a new LiveMap based on a LiveCounter.
50+
* Creates a new LiveMap with type-safe entries that can be Boolean, Binary, Number, String, JsonArray, JsonObject, LiveCounter, or LiveMap.
51+
* Implements spec RTO11 : createMap(Dict<String, Boolean | Binary | Number | String | JsonArray | JsonObject | LiveCounter | LiveMap> entries?)
5252
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
5353
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
5454
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
5555
* using the provided data and returns it.
5656
*
57-
* @param liveCounter the LiveCounter to base the new LiveMap on.
57+
* @param entries the type-safe map entries with values that can be Boolean, Binary, Number, String, JsonArray, JsonObject, LiveCounter, or LiveMap.
5858
* @return the newly created LiveMap instance.
5959
*/
6060
@Blocking
6161
@NotNull
62-
LiveMap createMap(@NotNull LiveCounter liveCounter);
62+
LiveMap createMap(@NotNull Map<String, LiveMapValue> entries);
6363

6464
/**
65-
* Creates a new LiveMap based on a standard Java Map.
66-
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
65+
* Creates a new LiveCounter with an initial value of 0.
66+
* Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool.
6767
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
68-
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
68+
* the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally
6969
* using the provided data and returns it.
7070
*
71-
* @param map the Java Map to base the new LiveMap on.
72-
* @return the newly created LiveMap instance.
71+
* @return the newly created LiveCounter instance with initial value of 0.
7372
*/
7473
@Blocking
7574
@NotNull
76-
LiveMap createMap(@NotNull Map<String, Object> map);
75+
LiveCounter createCounter();
7776

7877
/**
7978
* Creates a new LiveCounter with an initial value.
@@ -87,7 +86,7 @@ public interface LiveObjects extends ObjectsStateChange {
8786
*/
8887
@Blocking
8988
@NotNull
90-
LiveCounter createCounter(@NotNull Long initialValue);
89+
LiveCounter createCounter(@NotNull Number initialValue);
9190

9291
/**
9392
* Asynchronously retrieves the root LiveMap object.
@@ -101,43 +100,42 @@ public interface LiveObjects extends ObjectsStateChange {
101100
void getRootAsync(@NotNull Callback<@NotNull LiveMap> callback);
102101

103102
/**
104-
* Asynchronously creates a new LiveMap based on an existing LiveMap.
103+
* Asynchronously creates a new empty LiveMap with no entries.
105104
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
106105
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
107106
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
108-
* using the provided data and returns it.
107+
* and returns it.
109108
*
110-
* @param liveMap the existing LiveMap to base the new LiveMap on.
111109
* @param callback the callback to handle the result or error.
112110
*/
113111
@NonBlocking
114-
void createMapAsync(@NotNull LiveMap liveMap, @NotNull Callback<@NotNull LiveMap> callback);
112+
void createMapAsync(@NotNull Callback<@NotNull LiveMap> callback);
115113

116114
/**
117-
* Asynchronously creates a new LiveMap based on a LiveCounter.
115+
* Asynchronously creates a new LiveMap with type-safe entries that can be Boolean, Binary, Number, String, JsonArray, JsonObject, LiveCounter, or LiveMap.
116+
* This method implements the spec RTO11 signature: createMap(Dict<String, Boolean | Binary | Number | String | JsonArray | JsonObject | LiveCounter | LiveMap> entries?)
118117
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
119118
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
120119
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
121120
* using the provided data and returns it.
122121
*
123-
* @param liveCounter the LiveCounter to base the new LiveMap on.
122+
* @param entries the type-safe map entries with values that can be Boolean, Binary, Number, String, JsonArray, JsonObject, LiveCounter, or LiveMap.
124123
* @param callback the callback to handle the result or error.
125124
*/
126125
@NonBlocking
127-
void createMapAsync(@NotNull LiveCounter liveCounter, @NotNull Callback<@NotNull LiveMap> callback);
126+
void createMapAsync(@NotNull Map<String, LiveMapValue> entries, @NotNull Callback<@NotNull LiveMap> callback);
128127

129128
/**
130-
* Asynchronously creates a new LiveMap based on a standard Java Map.
131-
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
129+
* Asynchronously creates a new LiveCounter with an initial value of 0.
130+
* Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool.
132131
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
133-
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
132+
* the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally
134133
* using the provided data and returns it.
135134
*
136-
* @param map the Java Map to base the new LiveMap on.
137135
* @param callback the callback to handle the result or error.
138136
*/
139137
@NonBlocking
140-
void createMapAsync(@NotNull Map<String, Object> map, @NotNull Callback<@NotNull LiveMap> callback);
138+
void createCounterAsync(@NotNull Callback<@NotNull LiveCounter> callback);
141139

142140
/**
143141
* Asynchronously creates a new LiveCounter with an initial value.
@@ -150,5 +148,5 @@ public interface LiveObjects extends ObjectsStateChange {
150148
* @param callback the callback to handle the result or error.
151149
*/
152150
@NonBlocking
153-
void createCounterAsync(@NotNull Long initialValue, @NotNull Callback<@NotNull LiveCounter> callback);
151+
void createCounterAsync(@NotNull Number initialValue, @NotNull Callback<@NotNull LiveCounter> callback);
154152
}

0 commit comments

Comments
 (0)