Skip to content

Commit ac0ece7

Browse files
authored
Merge pull request #1085 from ably/feature/liveobject-plugin-setup
Setup : LiveObject plugin
2 parents 333dc54 + cd7d075 commit ac0ece7

File tree

23 files changed

+669
-16
lines changed

23 files changed

+669
-16
lines changed

android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ android {
5151
dependencies {
5252
api(libs.gson)
5353
implementation(libs.bundles.common)
54+
compileOnly(libs.jetbrains)
5455
testImplementation(libs.bundles.tests)
5556
implementation(project(":network-client-core"))
5657
runtimeOnly(project(":network-client-default"))

android/src/main/java/io/ably/lib/realtime/Channel.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import io.ably.lib.types.AblyException;
44
import io.ably.lib.types.ChannelOptions;
55
import io.ably.lib.push.PushChannel;
6+
import io.ably.lib.objects.LiveObjectsPlugin;
7+
68

79
public class Channel extends ChannelBase {
810
/**
@@ -12,8 +14,8 @@ public class Channel extends ChannelBase {
1214
*/
1315
public final PushChannel push;
1416

15-
Channel(AblyRealtime ably, String name, ChannelOptions options) throws AblyException {
16-
super(ably, name, options);
17+
Channel(AblyRealtime ably, String name, ChannelOptions options, LiveObjectsPlugin liveObjectsPlugin) throws AblyException {
18+
super(ably, name, options, liveObjectsPlugin);
1719
this.push = ((io.ably.lib.rest.AblyRest) ably).channels.get(name, options).push;
1820
}
1921

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ test-retry = "1.6.0"
2222
kotlin = "2.1.10"
2323
coroutine = "1.9.0"
2424
turbine = "1.2.0"
25+
jetbrains-annoations = "26.0.2"
2526

2627
[libraries]
2728
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
@@ -47,6 +48,7 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
4748
coroutine-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutine" }
4849
coroutine-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "coroutine" }
4950
turbine = { group = "app.cash.turbine", name = "turbine", version.ref = "turbine" }
51+
jetbrains = { group = "org.jetbrains", name = "annotations", version.ref = "jetbrains-annoations" }
5052

5153
[bundles]
5254
common = ["msgpack", "vcdiff-core"]

java/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tasks.withType<Jar> {
2020
dependencies {
2121
api(libs.gson)
2222
implementation(libs.bundles.common)
23+
compileOnly(libs.jetbrains)
2324
implementation(project(":network-client-core"))
2425
if (findProperty("okhttp") == null) {
2526
runtimeOnly(project(":network-client-default"))

java/src/main/java/io/ably/lib/realtime/Channel.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package io.ably.lib.realtime;
22

3+
import io.ably.lib.objects.LiveObjectsPlugin;
34
import io.ably.lib.types.AblyException;
45
import io.ably.lib.types.ChannelOptions;
56

67
public class Channel extends ChannelBase {
7-
Channel(AblyRealtime ably, String name, ChannelOptions options) throws AblyException {
8-
super(ably, name, options);
8+
Channel(AblyRealtime ably, String name, ChannelOptions options, LiveObjectsPlugin liveObjectsPlugin) throws AblyException {
9+
super(ably, name, options, liveObjectsPlugin);
910
}
1011

1112
public interface MessageListener extends ChannelBase.MessageListener {}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.Blocking;
5+
import org.jetbrains.annotations.NonBlocking;
6+
import org.jetbrains.annotations.NotNull;
7+
import org.jetbrains.annotations.Contract;
8+
9+
/**
10+
* The LiveCounter interface provides methods to interact with a live counter.
11+
* It allows incrementing, decrementing, and retrieving the current value of the counter,
12+
* both synchronously and asynchronously.
13+
*/
14+
public interface LiveCounter {
15+
16+
/**
17+
* Increments the value of the counter by 1.
18+
* Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object.
19+
* This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when
20+
* the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular
21+
* operation application procedure.
22+
*/
23+
@Blocking
24+
void increment();
25+
26+
/**
27+
* Increments the value of the counter by 1 asynchronously.
28+
* Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object.
29+
* This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when
30+
* the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular
31+
* operation application procedure.
32+
*
33+
* @param callback the callback to be invoked upon completion of the operation.
34+
*/
35+
@NonBlocking
36+
void incrementAsync(@NotNull Callback<Void> callback);
37+
38+
/**
39+
* Decrements the value of the counter by 1.
40+
* An alias for calling {@link LiveCounter#increment()} with a negative amount.
41+
*/
42+
@Blocking
43+
void decrement();
44+
45+
/**
46+
* Decrements the value of the counter by 1 asynchronously.
47+
* An alias for calling {@link LiveCounter#increment()} with a negative amount.
48+
*
49+
* @param callback the callback to be invoked upon completion of the operation.
50+
*/
51+
@NonBlocking
52+
void decrementAsync(@NotNull Callback<Void> callback);
53+
54+
/**
55+
* Retrieves the current value of the counter.
56+
*
57+
* @return the current value of the counter as a Long.
58+
*/
59+
@NotNull
60+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
61+
Long value();
62+
}
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.Blocking;
5+
import org.jetbrains.annotations.NonBlocking;
6+
import org.jetbrains.annotations.Contract;
7+
import org.jetbrains.annotations.NotNull;
8+
import org.jetbrains.annotations.Nullable;
9+
import org.jetbrains.annotations.Unmodifiable;
10+
11+
import java.util.Map;
12+
13+
/**
14+
* The LiveMap interface provides methods to interact with a live, real-time map structure.
15+
* It supports both synchronous and asynchronous operations for managing key-value pairs.
16+
*/
17+
public interface LiveMap {
18+
19+
/**
20+
* Retrieves the value associated with the specified key.
21+
* If this map object is tombstoned (deleted), `undefined` is returned.
22+
* If no entry is associated with the specified key, `undefined` is returned.
23+
* If map entry is tombstoned (deleted), `undefined` is returned.
24+
* If the value associated with the provided key is an objectId string of another LiveObject, a reference to that LiveObject
25+
* is returned, provided it exists in the local pool and is not tombstoned. Otherwise, `undefined` is returned.
26+
* If the value is not an objectId, then that value is returned.
27+
*
28+
* @param keyName the key whose associated value is to be returned.
29+
* @return the value associated with the specified key, or null if the key does not exist.
30+
*/
31+
@Nullable
32+
Object get(@NotNull String keyName);
33+
34+
/**
35+
* Retrieves all entries (key-value pairs) in the map.
36+
*
37+
* @return an iterable collection of all entries in the map.
38+
*/
39+
@NotNull
40+
@Unmodifiable
41+
Iterable<Map.Entry<String, Object>> entries();
42+
43+
/**
44+
* Retrieves all keys in the map.
45+
*
46+
* @return an iterable collection of all keys in the map.
47+
*/
48+
@NotNull
49+
@Unmodifiable
50+
Iterable<String> keys();
51+
52+
/**
53+
* Retrieves all values in the map.
54+
*
55+
* @return an iterable collection of all values in the map.
56+
*/
57+
@NotNull
58+
@Unmodifiable
59+
Iterable<Object> values();
60+
61+
/**
62+
* Sets the specified key to the given value in the map.
63+
* Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value.
64+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
65+
* the published MAP_SET operation is echoed back to the client and applied to the object following the regular
66+
* operation application procedure.
67+
*
68+
* @param keyName the key to be set.
69+
* @param value the value to be associated with the key.
70+
*/
71+
@Blocking
72+
void set(@NotNull String keyName, @NotNull Object value);
73+
74+
/**
75+
* Removes the specified key and its associated value from the map.
76+
* Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object.
77+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
78+
* the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular
79+
* operation application procedure.
80+
*
81+
* @param keyName the key to be removed.
82+
*/
83+
@Blocking
84+
void remove(@NotNull String keyName);
85+
86+
/**
87+
* Retrieves the number of entries in the map.
88+
*
89+
* @return the size of the map.
90+
*/
91+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
92+
@NotNull
93+
Long size();
94+
95+
/**
96+
* Asynchronously sets the specified key to the given value in the map.
97+
* Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value.
98+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
99+
* the published MAP_SET operation is echoed back to the client and applied to the object following the regular
100+
* operation application procedure.
101+
*
102+
* @param keyName the key to be set.
103+
* @param value the value to be associated with the key.
104+
* @param callback the callback to handle the result or any errors.
105+
*/
106+
@NonBlocking
107+
void setAsync(@NotNull String keyName, @NotNull Object value, @NotNull Callback<Void> callback);
108+
109+
/**
110+
* Asynchronously removes the specified key and its associated value from the map.
111+
* Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object.
112+
* This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when
113+
* the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular
114+
* operation application procedure.
115+
*
116+
* @param keyName the key to be removed.
117+
* @param callback the callback to handle the result or any errors.
118+
*/
119+
@NonBlocking
120+
void removeAsync(@NotNull String keyName, @NotNull Callback<Void> callback);
121+
}

0 commit comments

Comments
 (0)