Skip to content

Commit d81cb24

Browse files
committed
1. Updated public doc for LiveObjects, LiveMap and LiveCounter
2. Added live objects specific channel modes and flags to protocol message
1 parent bce4ba9 commit d81cb24

5 files changed

Lines changed: 109 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,33 @@ public interface LiveCounter {
1313

1414
/**
1515
* Increments the value of the counter by 1.
16+
* Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object.
17+
* This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when
18+
* the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular
19+
* operation application procedure.
1620
*/
1721
void increment();
1822

1923
/**
2024
* Increments the value of the counter by 1 asynchronously.
25+
* Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object.
26+
* This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when
27+
* the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular
28+
* operation application procedure.
2129
*
2230
* @param callback the callback to be invoked upon completion of the operation.
2331
*/
2432
void incrementAsync(@NotNull Callback<Void> callback);
2533

2634
/**
2735
* Decrements the value of the counter by 1.
36+
* An alias for calling {@link LiveCounter#increment()} with a negative amount.
2837
*/
2938
void decrement();
3039

3140
/**
3241
* Decrements the value of the counter by 1 asynchronously.
42+
* An alias for calling {@link LiveCounter#increment()} with a negative amount.
3343
*
3444
* @param callback the callback to be invoked upon completion of the operation.
3545
*/

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public interface LiveMap {
1616

1717
/**
1818
* Retrieves the value associated with the specified key.
19+
* If this map object is tombstoned (deleted), `undefined` is returned.
20+
* If no entry is associated with the specified key, `undefined` is returned.
21+
* If map entry is tombstoned (deleted), `undefined` is returned.
22+
* If the value associated with the provided key is an objectId string of another LiveObject, a reference to that LiveObject
23+
* is returned, provided it exists in the local pool and is not tombstoned. Otherwise, `undefined` is returned.
24+
* If the value is not an objectId, then that value is returned.
1925
*
2026
* @param keyName the key whose associated value is to be returned.
2127
* @return the value associated with the specified key, or null if the key does not exist.
@@ -52,6 +58,10 @@ public interface LiveMap {
5258

5359
/**
5460
* Sets the specified key to the given value in the map.
61+
* Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value.
62+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
63+
* the published MAP_SET operation is echoed back to the client and applied to the object following the regular
64+
* operation application procedure.
5565
*
5666
* @param keyName the key to be set.
5767
* @param value the value to be associated with the key.
@@ -60,6 +70,10 @@ public interface LiveMap {
6070

6171
/**
6272
* Removes the specified key and its associated value from the map.
73+
* Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object.
74+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
75+
* the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular
76+
* operation application procedure.
6377
*
6478
* @param keyName the key to be removed.
6579
*/
@@ -76,6 +90,10 @@ public interface LiveMap {
7690

7791
/**
7892
* Asynchronously sets the specified key to the given value in the map.
93+
* Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value.
94+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
95+
* the published MAP_SET operation is echoed back to the client and applied to the object following the regular
96+
* operation application procedure.
7997
*
8098
* @param keyName the key to be set.
8199
* @param value the value to be associated with the key.
@@ -85,6 +103,10 @@ public interface LiveMap {
85103

86104
/**
87105
* Asynchronously removes the specified key and its associated value from the map.
106+
* Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object.
107+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
108+
* the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular
109+
* operation application procedure.
88110
*
89111
* @param keyName the key to be removed.
90112
* @param callback the callback to handle the result or any errors.

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public interface LiveObjects {
1919

2020
/**
2121
* Retrieves the root LiveMap object.
22+
* When called without a type variable, we return a default root type which is based on globally defined interface for Objects feature.
23+
* A user can provide an explicit type for the getRoot method to explicitly set the type structure on this particular channel.
24+
* This is useful when working with multiple channels with different underlying data structure.
2225
*
2326
* @return the root LiveMap instance.
2427
*/
@@ -27,13 +30,19 @@ public interface LiveObjects {
2730

2831
/**
2932
* Initiates a batch operation and provides a BatchContext through a callback.
33+
* Provides access to the synchronous write API for Objects that can be used to batch multiple operations
34+
* together in a single channel message.
3035
*
3136
* @param batchContextCallback the builder to configure the batch operation.
3237
*/
3338
void batch(@NotNull BatchContextBuilder batchContextCallback);
3439

3540
/**
3641
* Creates a new LiveMap based on an existing LiveMap.
42+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
43+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
44+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
45+
* using the provided data and returns it.
3746
*
3847
* @param liveMap the existing LiveMap to base the new LiveMap on.
3948
* @return the newly created LiveMap instance.
@@ -43,6 +52,10 @@ public interface LiveObjects {
4352

4453
/**
4554
* Creates a new LiveMap based on a LiveCounter.
55+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
56+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
57+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
58+
* using the provided data and returns it.
4659
*
4760
* @param liveCounter the LiveCounter to base the new LiveMap on.
4861
* @return the newly created LiveMap instance.
@@ -52,6 +65,10 @@ public interface LiveObjects {
5265

5366
/**
5467
* Creates a new LiveMap based on a standard Java Map.
68+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
69+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
70+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
71+
* using the provided data and returns it.
5572
*
5673
* @param map the Java Map to base the new LiveMap on.
5774
* @return the newly created LiveMap instance.
@@ -61,6 +78,10 @@ public interface LiveObjects {
6178

6279
/**
6380
* Creates a new LiveCounter with an initial value.
81+
* Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool.
82+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
83+
* the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally
84+
* using the provided data and returns it.
6485
*
6586
* @param initialValue the initial value of the LiveCounter.
6687
* @return the newly created LiveCounter instance.
@@ -70,13 +91,18 @@ public interface LiveObjects {
7091

7192
/**
7293
* Asynchronously retrieves the root LiveMap object.
94+
* When called without a type variable, we return a default root type which is based on globally defined interface for Objects feature.
95+
* A user can provide an explicit type for the getRoot method to explicitly set the type structure on this particular channel.
96+
* This is useful when working with multiple channels with different underlying data structure.
7397
*
7498
* @param callback the callback to handle the result or error.
7599
*/
76100
void getRootAsync(@NotNull Callback<@NotNull LiveMap> callback);
77101

78102
/**
79103
* Initiates a batch operation asynchronously.
104+
* Provides access to the synchronous write API for Objects that can be used to batch multiple operations
105+
* together in a single channel message.
80106
*
81107
* @param batchContextCallback the builder to configure the batch operation.
82108
* @param callback the Callback to handle the completion or error of the batch operation.
@@ -85,6 +111,10 @@ public interface LiveObjects {
85111

86112
/**
87113
* Asynchronously creates a new LiveMap based on an existing LiveMap.
114+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
115+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
116+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
117+
* using the provided data and returns it.
88118
*
89119
* @param liveMap the existing LiveMap to base the new LiveMap on.
90120
* @param callback the callback to handle the result or error.
@@ -93,6 +123,10 @@ public interface LiveObjects {
93123

94124
/**
95125
* Asynchronously creates a new LiveMap based on a LiveCounter.
126+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
127+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
128+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
129+
* using the provided data and returns it.
96130
*
97131
* @param liveCounter the LiveCounter to base the new LiveMap on.
98132
* @param callback the callback to handle the result or error.
@@ -101,6 +135,10 @@ public interface LiveObjects {
101135

102136
/**
103137
* Asynchronously creates a new LiveMap based on a standard Java Map.
138+
* Send a MAP_CREATE operation to the realtime system to create a new map object in the pool.
139+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
140+
* the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally
141+
* using the provided data and returns it.
104142
*
105143
* @param map the Java Map to base the new LiveMap on.
106144
* @param callback the callback to handle the result or error.
@@ -109,6 +147,10 @@ public interface LiveObjects {
109147

110148
/**
111149
* Asynchronously creates a new LiveCounter with an initial value.
150+
* Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool.
151+
* Once the ACK message is received, the method returns the object from the local pool if it got created due to
152+
* the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally
153+
* using the provided data and returns it.
112154
*
113155
* @param initialValue the initial value of the LiveCounter.
114156
* @param callback the callback to handle the result or error.

lib/src/main/java/io/ably/lib/types/ChannelMode.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,27 @@ public enum ChannelMode {
2424
/**
2525
* The client can receive presence messages.
2626
*/
27-
presence_subscribe(Flag.presence_subscribe);
27+
presence_subscribe(Flag.presence_subscribe),
28+
29+
/**
30+
* The client can publish object messages.
31+
*/
32+
object_publish(Flag.object_publish),
33+
34+
/**
35+
* The client can subscribe to object messages.
36+
*/
37+
object_subscribe(Flag.object_subscribe),
38+
39+
/**
40+
* The client can publish annotation messages.
41+
*/
42+
annotation_publish(Flag.annotation_publish),
43+
44+
/**
45+
* The client can subscribe to annotation messages.
46+
*/
47+
annotation_subscribe(Flag.annotation_subscribe);
2848

2949
private final int mask;
3050

lib/src/main/java/io/ably/lib/types/ProtocolMessage.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public enum Action {
4545
presence,
4646
message,
4747
sync,
48-
auth;
48+
auth,
49+
activate,
50+
object,
51+
object_sync,
52+
annotation;
4953

5054
public int getValue() { return ordinal(); }
5155
public static Action findByValue(int value) { return values()[value]; }
@@ -57,12 +61,19 @@ public enum Flag {
5761
has_backlog(1),
5862
resumed(2),
5963
attach_resume(5),
60-
64+
/* Has object flag */
65+
has_objects(7),
6166
/* Channel mode flags */
6267
presence(16),
6368
publish(17),
6469
subscribe(18),
65-
presence_subscribe(19);
70+
presence_subscribe(19),
71+
/* Annotation flags */
72+
annotation_publish(21),
73+
annotation_subscribe(22),
74+
/* Object flags */
75+
object_subscribe(24),
76+
object_publish(25);
6677

6778
private final int mask;
6879

0 commit comments

Comments
 (0)