Skip to content

Commit abe200c

Browse files
ttypicsacOO7
authored andcommitted
Created and configured liveobjects as a separate module to the project
1. Declared required liveobject java interfaces 2. Implemented liveobject interface for LiveObjectsPlugin
1 parent aedfd9b commit abe200c

15 files changed

Lines changed: 465 additions & 6 deletions

File tree

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

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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.types.Callback;
4+
5+
/**
6+
* The LiveCounter interface provides methods to interact with a live counter.
7+
* It allows incrementing, decrementing, and retrieving the current value of the counter,
8+
* both synchronously and asynchronously.
9+
*/
10+
public interface LiveCounter {
11+
12+
/**
13+
* Increments the value of the counter by 1.
14+
*/
15+
void increment();
16+
17+
/**
18+
* Increments the value of the counter by 1 asynchronously.
19+
*
20+
* @param callback the callback to be invoked upon completion of the operation.
21+
*/
22+
void incrementAsync(Callback<Void> callback);
23+
24+
/**
25+
* Decrements the value of the counter by 1.
26+
*/
27+
void decrement();
28+
29+
/**
30+
* Decrements the value of the counter by 1 asynchronously.
31+
*
32+
* @param callback the callback to be invoked upon completion of the operation.
33+
*/
34+
void decrementAsync(Callback<Void> callback);
35+
36+
/**
37+
* Retrieves the current value of the counter.
38+
*
39+
* @return the current value of the counter as a Long.
40+
*/
41+
Long value();
42+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.types.Callback;
4+
5+
import java.util.Map;
6+
7+
/**
8+
* The LiveMap interface provides methods to interact with a live, real-time map structure.
9+
* It supports both synchronous and asynchronous operations for managing key-value pairs.
10+
*/
11+
public interface LiveMap {
12+
13+
/**
14+
* Retrieves the value associated with the specified key.
15+
*
16+
* @param keyName the key whose associated value is to be returned.
17+
* @return the value associated with the specified key, or null if the key does not exist.
18+
*/
19+
Object get(String keyName);
20+
21+
/**
22+
* Retrieves all entries (key-value pairs) in the map.
23+
*
24+
* @return an iterable collection of all entries in the map.
25+
*/
26+
Iterable<Map.Entry<String, Object>> entries();
27+
28+
/**
29+
* Retrieves all keys in the map.
30+
*
31+
* @return an iterable collection of all keys in the map.
32+
*/
33+
Iterable<String> keys();
34+
35+
/**
36+
* Retrieves all values in the map.
37+
*
38+
* @return an iterable collection of all values in the map.
39+
*/
40+
Iterable<Object> values();
41+
42+
/**
43+
* Sets the specified key to the given value in the map.
44+
*
45+
* @param keyName the key to be set.
46+
* @param value the value to be associated with the key.
47+
*/
48+
void set(String keyName, Object value);
49+
50+
/**
51+
* Removes the specified key and its associated value from the map.
52+
*
53+
* @param keyName the key to be removed.
54+
* @param value the value associated with the key to be removed.
55+
*/
56+
void remove(String keyName, Object value);
57+
58+
/**
59+
* Retrieves the number of entries in the map.
60+
*
61+
* @return the size of the map.
62+
*/
63+
Long size();
64+
65+
/**
66+
* Asynchronously sets the specified key to the given value in the map.
67+
*
68+
* @param keyName the key to be set.
69+
* @param value the value to be associated with the key.
70+
* @param callback the callback to handle the result or any errors.
71+
*/
72+
void setAsync(String keyName, Object value, Callback<Void> callback);
73+
74+
/**
75+
* Asynchronously removes the specified key and its associated value from the map.
76+
*
77+
* @param keyName the key to be removed.
78+
* @param value the value associated with the key to be removed.
79+
* @param callback the callback to handle the result or any errors.
80+
*/
81+
void removeAsync(String keyName, Object value, Callback<Void> callback);
82+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.objects.batch.BatchContext;
4+
import io.ably.lib.types.Callback;
5+
6+
import java.util.Map;
7+
8+
/**
9+
* The LiveObjects interface provides methods to interact with live data objects,
10+
* such as maps and counters, in a real-time environment. It supports both synchronous
11+
* and asynchronous operations for retrieving and creating live objects.
12+
*/
13+
public interface LiveObjects {
14+
15+
/**
16+
* Retrieves the root LiveMap object.
17+
*
18+
* @return the root LiveMap instance.
19+
*/
20+
LiveMap getRoot();
21+
22+
/**
23+
* Initiates a batch operation and provides a BatchContext through a callback.
24+
*
25+
* @param batchContextCallback the callback to handle the BatchContext or error.
26+
*/
27+
void batch(Callback<BatchContext> batchContextCallback);
28+
29+
/**
30+
* Creates a new LiveMap based on an existing LiveMap.
31+
*
32+
* @param liveMap the existing LiveMap to base the new LiveMap on.
33+
* @return the newly created LiveMap instance.
34+
*/
35+
LiveMap createMap(LiveMap liveMap);
36+
37+
/**
38+
* Creates a new LiveMap based on a LiveCounter.
39+
*
40+
* @param liveCounter the LiveCounter to base the new LiveMap on.
41+
* @return the newly created LiveMap instance.
42+
*/
43+
LiveMap createMap(LiveCounter liveCounter);
44+
45+
/**
46+
* Creates a new LiveMap based on a standard Java Map.
47+
*
48+
* @param map the Java Map to base the new LiveMap on.
49+
* @return the newly created LiveMap instance.
50+
*/
51+
LiveMap createMap(Map<String, Object> map);
52+
53+
/**
54+
* Creates a new LiveCounter with an initial value.
55+
*
56+
* @param initialValue the initial value of the LiveCounter.
57+
* @return the newly created LiveCounter instance.
58+
*/
59+
LiveCounter createCounter(Long initialValue);
60+
61+
/**
62+
* Asynchronously retrieves the root LiveMap object.
63+
*
64+
* @param callback the callback to handle the result or error.
65+
*/
66+
void getRootAsync(Callback<LiveMap> callback);
67+
68+
/**
69+
* Asynchronously creates a new LiveMap based on an existing LiveMap.
70+
*
71+
* @param liveMap the existing LiveMap to base the new LiveMap on.
72+
* @param callback the callback to handle the result or error.
73+
*/
74+
void createMapAsync(LiveMap liveMap, Callback<LiveMap> callback);
75+
76+
/**
77+
* Asynchronously creates a new LiveMap based on a LiveCounter.
78+
*
79+
* @param liveCounter the LiveCounter to base the new LiveMap on.
80+
* @param callback the callback to handle the result or error.
81+
*/
82+
void createMapAsync(LiveCounter liveCounter, Callback<LiveMap> callback);
83+
84+
/**
85+
* Asynchronously creates a new LiveMap based on a standard Java Map.
86+
*
87+
* @param map the Java Map to base the new LiveMap on.
88+
* @param callback the callback to handle the result or error.
89+
*/
90+
void createMapAsync(Map<String, Object> map, Callback<LiveMap> callback);
91+
92+
/**
93+
* Asynchronously creates a new LiveCounter with an initial value.
94+
*
95+
* @param initialValue the initial value of the LiveCounter.
96+
* @param callback the callback to handle the result or error.
97+
*/
98+
void createCounterAsync(Long initialValue, Callback<LiveCounter> callback);
99+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.ably.lib.objects;
2+
3+
/**
4+
* The LiveObjectsPlugin interface provides a mechanism to retrieve instances of LiveObjects
5+
* associated with specific channel names. This allows for interaction with live data objects
6+
* in a real-time environment.
7+
*/
8+
public interface LiveObjectsPlugin {
9+
10+
/**
11+
* Retrieves an instance of LiveObjects associated with the specified channel name.
12+
*
13+
* @param channelName the name of the channel for which the LiveObjects instance is to be retrieved.
14+
* @return the LiveObjects instance associated with the specified channel name.
15+
*/
16+
LiveObjects getInstance(String channelName);
17+
18+
19+
/**
20+
* Disposes of the LiveObjects instance associated with the specified channel name.
21+
*
22+
* @param channelName the name of the channel whose LiveObjects instance is to be removed.
23+
*/
24+
void dispose(String channelName);
25+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package io.ably.lib.objects.batch;
2+
3+
4+
/**
5+
* The BatchContext interface represents the context for batch operations
6+
* on live data objects. It provides access to the root LiveMap, which serves
7+
* as the entry point for interacting with the batch context.
8+
*/
9+
public interface BatchContext {
10+
11+
/**
12+
* Retrieves the root LiveMap associated with this batch context.
13+
*
14+
* @return the root LiveMap instance.
15+
*/
16+
BatchContextLiveMap getRoot();
17+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.ably.lib.objects.batch;
2+
3+
import java.util.Map;
4+
5+
/**
6+
* The BatchContextLiveMap interface provides methods to interact with a live map
7+
* in the context of batch operations. It allows retrieving, modifying, and querying
8+
* key-value pairs in the map.
9+
*/
10+
public interface BatchContextLiveMap {
11+
12+
/**
13+
* Retrieves the value associated with the specified key.
14+
*
15+
* @param keyName the name of the key whose value is to be retrieved.
16+
* @return the value associated with the specified key, or null if the key does not exist.
17+
*/
18+
Object get(String keyName);
19+
20+
/**
21+
* Retrieves all entries (key-value pairs) in the live map.
22+
*
23+
* @return an iterable collection of map entries.
24+
*/
25+
Iterable<Map.Entry<String, Object>> entries();
26+
27+
/**
28+
* Retrieves all keys in the live map.
29+
*
30+
* @return an iterable collection of keys.
31+
*/
32+
Iterable<String> keys();
33+
34+
/**
35+
* Retrieves all values in the live map.
36+
*
37+
* @return an iterable collection of values.
38+
*/
39+
Iterable<Object> values();
40+
41+
/**
42+
* Sets the specified key to the given value in the live map.
43+
*
44+
* @param keyName the name of the key to set.
45+
* @param value the value to associate with the specified key.
46+
*/
47+
void set(String keyName, Object value);
48+
49+
/**
50+
* Removes the specified key-value pair from the live map.
51+
*
52+
* @param keyName the name of the key to remove.
53+
* @param value the value associated with the key to remove.
54+
*/
55+
void remove(String keyName, Object value);
56+
57+
/**
58+
* Retrieves the number of entries in the live map.
59+
*
60+
* @return the size of the live map as a Long.
61+
*/
62+
Long size();
63+
}

0 commit comments

Comments
 (0)