Skip to content

Commit 86a035e

Browse files
committed
Moved liveobject interfaces under plugins package
1. Added jetbrains-annoations dependency to clearly define interface methods 2. Added internet connectivity check to test setup
1 parent c435f5d commit 86a035e

15 files changed

Lines changed: 122 additions & 59 deletions

File tree

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.ably.lib.realtime;
22

3-
import io.ably.lib.objects.LiveObjectsPlugin;
3+
import io.ably.lib.plugins.objects.LiveObjectsPlugin;
44
import io.ably.lib.types.AblyException;
55
import io.ably.lib.types.ChannelOptions;
66

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

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

33
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Contract;
46

57
/**
68
* The LiveCounter interface provides methods to interact with a live counter.
@@ -19,7 +21,7 @@ public interface LiveCounter {
1921
*
2022
* @param callback the callback to be invoked upon completion of the operation.
2123
*/
22-
void incrementAsync(Callback<Void> callback);
24+
void incrementAsync(@NotNull Callback<Void> callback);
2325

2426
/**
2527
* Decrements the value of the counter by 1.
@@ -31,12 +33,14 @@ public interface LiveCounter {
3133
*
3234
* @param callback the callback to be invoked upon completion of the operation.
3335
*/
34-
void decrementAsync(Callback<Void> callback);
36+
void decrementAsync(@NotNull Callback<Void> callback);
3537

3638
/**
3739
* Retrieves the current value of the counter.
3840
*
3941
* @return the current value of the counter as a Long.
4042
*/
43+
@NotNull
44+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
4145
Long value();
4246
}

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

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

33
import io.ably.lib.types.Callback;
4+
import org.jetbrains.annotations.Contract;
5+
import org.jetbrains.annotations.NotNull;
46

57
import java.util.Map;
68

@@ -16,7 +18,7 @@ public interface LiveMap {
1618
* @param keyName the key whose associated value is to be returned.
1719
* @return the value associated with the specified key, or null if the key does not exist.
1820
*/
19-
Object get(String keyName);
21+
Object get(@NotNull String keyName);
2022

2123
/**
2224
* Retrieves all entries (key-value pairs) in the map.
@@ -45,21 +47,21 @@ public interface LiveMap {
4547
* @param keyName the key to be set.
4648
* @param value the value to be associated with the key.
4749
*/
48-
void set(String keyName, Object value);
50+
void set(@NotNull String keyName, @NotNull Object value);
4951

5052
/**
5153
* Removes the specified key and its associated value from the map.
5254
*
5355
* @param keyName the key to be removed.
54-
* @param value the value associated with the key to be removed.
5556
*/
56-
void remove(String keyName, Object value);
57+
void remove(@NotNull String keyName);
5758

5859
/**
5960
* Retrieves the number of entries in the map.
6061
*
6162
* @return the size of the map.
6263
*/
64+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
6365
Long size();
6466

6567
/**
@@ -69,14 +71,13 @@ public interface LiveMap {
6971
* @param value the value to be associated with the key.
7072
* @param callback the callback to handle the result or any errors.
7173
*/
72-
void setAsync(String keyName, Object value, Callback<Void> callback);
74+
void setAsync(@NotNull String keyName, @NotNull Object value, @NotNull Callback<Void> callback);
7375

7476
/**
7577
* Asynchronously removes the specified key and its associated value from the map.
7678
*
77-
* @param keyName the key to be removed.
78-
* @param value the value associated with the key to be removed.
79+
* @param keyName the key to be removed.
7980
* @param callback the callback to handle the result or any errors.
8081
*/
81-
void removeAsync(String keyName, Object value, Callback<Void> callback);
82+
void removeAsync(@NotNull String keyName, @NotNull Callback<Void> callback);
8283
}

lib/src/main/java/io/ably/lib/objects/LiveObjects.java renamed to lib/src/main/java/io/ably/lib/plugins/objects/LiveObjects.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package io.ably.lib.objects;
1+
package io.ably.lib.plugins.objects;
22

3-
import io.ably.lib.objects.batch.BatchContextBuilder;
3+
import io.ably.lib.plugins.objects.batch.BatchContextBuilder;
44
import io.ably.lib.types.Callback;
5+
import org.jetbrains.annotations.NotNull;
6+
57

68
import java.util.Map;
79

@@ -24,84 +26,84 @@ public interface LiveObjects {
2426
*
2527
* @param batchContextCallback the callback to handle the BatchContext or error.
2628
*/
27-
void batch(BatchContextBuilder batchContextCallback);
29+
void batch(@NotNull BatchContextBuilder batchContextCallback);
2830

2931
/**
3032
* Creates a new LiveMap based on an existing LiveMap.
3133
*
3234
* @param liveMap the existing LiveMap to base the new LiveMap on.
3335
* @return the newly created LiveMap instance.
3436
*/
35-
LiveMap createMap(LiveMap liveMap);
37+
LiveMap createMap(@NotNull LiveMap liveMap);
3638

3739
/**
3840
* Creates a new LiveMap based on a LiveCounter.
3941
*
4042
* @param liveCounter the LiveCounter to base the new LiveMap on.
4143
* @return the newly created LiveMap instance.
4244
*/
43-
LiveMap createMap(LiveCounter liveCounter);
45+
LiveMap createMap(@NotNull LiveCounter liveCounter);
4446

4547
/**
4648
* Creates a new LiveMap based on a standard Java Map.
4749
*
4850
* @param map the Java Map to base the new LiveMap on.
4951
* @return the newly created LiveMap instance.
5052
*/
51-
LiveMap createMap(Map<String, Object> map);
53+
LiveMap createMap(@NotNull Map<String, Object> map);
5254

5355
/**
5456
* Creates a new LiveCounter with an initial value.
5557
*
5658
* @param initialValue the initial value of the LiveCounter.
5759
* @return the newly created LiveCounter instance.
5860
*/
59-
LiveCounter createCounter(Long initialValue);
61+
LiveCounter createCounter(@NotNull Long initialValue);
6062

6163
/**
6264
* Asynchronously retrieves the root LiveMap object.
6365
*
6466
* @param callback the callback to handle the result or error.
6567
*/
66-
void getRootAsync(Callback<LiveMap> callback);
68+
void getRootAsync(@NotNull Callback<LiveMap> callback);
6769

6870
/**
6971
* Initiates a batch operation asynchronously.
7072
*
7173
* @param batchContextCallback the BatchContextBuilder to build the BatchContext.
7274
* @param callback the Callback to handle the completion or error of the batch operation.
7375
*/
74-
void batchAsync(BatchContextBuilder batchContextCallback, Callback<Void> callback);
76+
void batchAsync(@NotNull BatchContextBuilder batchContextCallback, @NotNull Callback<Void> callback);
7577

7678
/**
7779
* Asynchronously creates a new LiveMap based on an existing LiveMap.
7880
*
7981
* @param liveMap the existing LiveMap to base the new LiveMap on.
8082
* @param callback the callback to handle the result or error.
8183
*/
82-
void createMapAsync(LiveMap liveMap, Callback<LiveMap> callback);
84+
void createMapAsync(@NotNull LiveMap liveMap, @NotNull Callback<LiveMap> callback);
8385

8486
/**
8587
* Asynchronously creates a new LiveMap based on a LiveCounter.
8688
*
8789
* @param liveCounter the LiveCounter to base the new LiveMap on.
8890
* @param callback the callback to handle the result or error.
8991
*/
90-
void createMapAsync(LiveCounter liveCounter, Callback<LiveMap> callback);
92+
void createMapAsync(@NotNull LiveCounter liveCounter, @NotNull Callback<LiveMap> callback);
9193

9294
/**
9395
* Asynchronously creates a new LiveMap based on a standard Java Map.
9496
*
9597
* @param map the Java Map to base the new LiveMap on.
9698
* @param callback the callback to handle the result or error.
9799
*/
98-
void createMapAsync(Map<String, Object> map, Callback<LiveMap> callback);
100+
void createMapAsync(@NotNull Map<String, Object> map, @NotNull Callback<LiveMap> callback);
99101

100102
/**
101103
* Asynchronously creates a new LiveCounter with an initial value.
102104
*
103105
* @param initialValue the initial value of the LiveCounter.
104106
* @param callback the callback to handle the result or error.
105107
*/
106-
void createCounterAsync(Long initialValue, Callback<LiveCounter> callback);
108+
void createCounterAsync(@NotNull Long initialValue, @NotNull Callback<LiveCounter> callback);
107109
}

lib/src/main/java/io/ably/lib/objects/LiveObjectsPlugin.java renamed to lib/src/main/java/io/ably/lib/plugins/objects/LiveObjectsPlugin.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
package io.ably.lib.objects;
1+
package io.ably.lib.plugins.objects;
2+
3+
import org.jetbrains.annotations.NotNull;
24

35
/**
46
* The LiveObjectsPlugin interface provides a mechanism to retrieve instances of LiveObjects
@@ -13,13 +15,12 @@ public interface LiveObjectsPlugin {
1315
* @param channelName the name of the channel for which the LiveObjects instance is to be retrieved.
1416
* @return the LiveObjects instance associated with the specified channel name.
1517
*/
16-
LiveObjects getInstance(String channelName);
17-
18+
LiveObjects getInstance(@NotNull String channelName);
1819

1920
/**
2021
* Disposes of the LiveObjects instance associated with the specified channel name.
2122
*
2223
* @param channelName the name of the channel whose LiveObjects instance is to be removed.
2324
*/
24-
void dispose(String channelName);
25+
void dispose(@NotNull String channelName);
2526
}

lib/src/main/java/io/ably/lib/objects/batch/BatchContext.java renamed to lib/src/main/java/io/ably/lib/plugins/objects/batch/BatchContext.java

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

3+
import org.jetbrains.annotations.NotNull;
34

45
/**
56
* The BatchContext interface represents the context for batch operations
@@ -13,5 +14,6 @@ public interface BatchContext {
1314
*
1415
* @return the root LiveMap instance.
1516
*/
17+
@NotNull
1618
BatchContextLiveMap getRoot();
1719
}

lib/src/main/java/io/ably/lib/objects/batch/BatchContextBuilder.java renamed to lib/src/main/java/io/ably/lib/plugins/objects/batch/BatchContextBuilder.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
package io.ably.lib.objects.batch;
1+
package io.ably.lib.plugins.objects.batch;
2+
3+
import org.jetbrains.annotations.NotNull;
24

35
/**
4-
* A functional interface for building and handling a BatchContext.*
6+
* A functional interface for building and handling a BatchContext.
57
*/
68
@FunctionalInterface
79
public interface BatchContextBuilder {
@@ -10,5 +12,5 @@ public interface BatchContextBuilder {
1012
*
1113
* @param batchContext the BatchContext to handle.
1214
*/
13-
void build(BatchContext batchContext);
15+
void build(@NotNull BatchContext batchContext);
1416
}

lib/src/main/java/io/ably/lib/objects/batch/BatchContextLiveMap.java renamed to lib/src/main/java/io/ably/lib/plugins/objects/batch/BatchContextLiveMap.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
package io.ably.lib.objects.batch;
1+
package io.ably.lib.plugins.objects.batch;
2+
3+
import org.jetbrains.annotations.Contract;
4+
import org.jetbrains.annotations.NotNull;
5+
import org.jetbrains.annotations.Nullable;
6+
import org.jetbrains.annotations.Unmodifiable;
27

38
import java.util.Map;
49

@@ -15,27 +20,34 @@ public interface BatchContextLiveMap {
1520
* @param keyName the name of the key whose value is to be retrieved.
1621
* @return the value associated with the specified key, or null if the key does not exist.
1722
*/
18-
Object get(String keyName);
23+
@Nullable
24+
Object get(@NotNull String keyName);
1925

2026
/**
2127
* Retrieves all entries (key-value pairs) in the live map.
2228
*
23-
* @return an iterable collection of map entries.
29+
* @return an unmodifiable iterable collection of map entries.
2430
*/
31+
@NotNull
32+
@Unmodifiable
2533
Iterable<Map.Entry<String, Object>> entries();
2634

2735
/**
2836
* Retrieves all keys in the live map.
2937
*
30-
* @return an iterable collection of keys.
38+
* @return an unmodifiable iterable collection of keys.
3139
*/
40+
@NotNull
41+
@Unmodifiable
3242
Iterable<String> keys();
3343

3444
/**
3545
* Retrieves all values in the live map.
3646
*
37-
* @return an iterable collection of values.
47+
* @return an unmodifiable iterable collection of values.
3848
*/
49+
@NotNull
50+
@Unmodifiable
3951
Iterable<Object> values();
4052

4153
/**
@@ -44,20 +56,21 @@ public interface BatchContextLiveMap {
4456
* @param keyName the name of the key to set.
4557
* @param value the value to associate with the specified key.
4658
*/
47-
void set(String keyName, Object value);
59+
void set(@NotNull String keyName, @NotNull Object value);
4860

4961
/**
5062
* Removes the specified key-value pair from the live map.
5163
*
5264
* @param keyName the name of the key to remove.
53-
* @param value the value associated with the key to remove.
5465
*/
55-
void remove(String keyName, Object value);
66+
void remove(@NotNull String keyName);
5667

5768
/**
5869
* Retrieves the number of entries in the live map.
5970
*
6071
* @return the size of the live map as a Long.
6172
*/
73+
@NotNull
74+
@Contract(pure = true) // Indicates this method does not modify the state of the object.
6275
Long size();
6376
}

0 commit comments

Comments
 (0)