Skip to content

Commit 6fdc57d

Browse files
committed
[ECO-5375] Updated code as per review comments
1. Updated enum ObjectOperationAction with PascalCase values 2. Created separate file for adapter that extends LiveObjectsAdapter
1 parent 375328e commit 6fdc57d

7 files changed

Lines changed: 75 additions & 88 deletions

File tree

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package io.ably.lib.objects;
2+
3+
import io.ably.lib.realtime.AblyRealtime;
4+
import io.ably.lib.realtime.CompletionListener;
5+
import io.ably.lib.types.AblyException;
6+
import io.ably.lib.types.ProtocolMessage;
7+
import io.ably.lib.util.Log;
8+
import org.jetbrains.annotations.NotNull;
9+
10+
public class Adapter implements LiveObjectsAdapter {
11+
private final AblyRealtime ably;
12+
private static final String TAG = LiveObjectsAdapter.class.getName();
13+
14+
public Adapter(@NotNull AblyRealtime ably) {
15+
this.ably = ably;
16+
}
17+
18+
@Override
19+
public void setChannelSerial(@NotNull String channelName, @NotNull String channelSerial) {
20+
if (ably.channels.containsKey(channelName)) {
21+
ably.channels.get(channelName).properties.channelSerial = channelSerial;
22+
} else {
23+
Log.e(TAG, "setChannelSerial(): channel not found: " + channelName);
24+
}
25+
}
26+
27+
@Override
28+
public void send(ProtocolMessage msg, CompletionListener listener) throws AblyException {
29+
// Always queue LiveObjects messages to ensure reliable state synchronization and proper acknowledgment
30+
ably.connection.connectionManager.send(msg, true, listener);
31+
}
32+
}
Lines changed: 18 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,27 @@
11
package io.ably.lib.objects;
22

3-
import io.ably.lib.plugins.PluginConnectionAdapter;
4-
import io.ably.lib.realtime.AblyRealtime;
53
import io.ably.lib.realtime.CompletionListener;
64
import io.ably.lib.types.AblyException;
75
import io.ably.lib.types.ProtocolMessage;
8-
import io.ably.lib.util.Log;
96
import org.jetbrains.annotations.NotNull;
107

11-
public interface LiveObjectsAdapter extends PluginConnectionAdapter {
12-
void setChannelSerial(@NotNull String channelName, @NotNull String channelSerial);
13-
14-
class Adapter implements LiveObjectsAdapter {
15-
private final AblyRealtime ably;
16-
private static final String TAG = LiveObjectsAdapter.class.getName();
17-
18-
public Adapter(@NotNull AblyRealtime ably) {
19-
this.ably = ably;
20-
}
8+
public interface LiveObjectsAdapter {
9+
/**
10+
* Sends a protocol message to its intended recipient.
11+
* This method transmits a protocol message, allowing for queuing events if necessary,
12+
* and notifies the provided listener upon the success or failure of the send operation.
13+
*
14+
* @param msg the protocol message to send.
15+
* @param listener a listener to be notified of the success or failure of the send operation.
16+
* @throws AblyException if an error occurs during the send operation.
17+
*/
18+
void send(ProtocolMessage msg, CompletionListener listener) throws AblyException;
2119

22-
@Override
23-
public void setChannelSerial(@NotNull String channelName, @NotNull String channelSerial) {
24-
if (ably.channels.containsKey(channelName)) {
25-
ably.channels.get(channelName).properties.channelSerial = channelSerial;
26-
} else {
27-
Log.e(TAG, "setChannelSerial(): channel not found: " + channelName);
28-
}
29-
}
30-
31-
@Override
32-
public void send(ProtocolMessage msg, CompletionListener listener) throws AblyException {
33-
// Always queue LiveObjects messages to ensure reliable state synchronization and proper acknowledgment
34-
ably.connection.connectionManager.send(msg, true, listener);
35-
}
36-
}
20+
/**
21+
* Sets the channel serial for a specific channel.
22+
* @param channelName the name of the channel for which to set the serial
23+
* @param channelSerial the serial to set for the channel
24+
*/
25+
void setChannelSerial(@NotNull String channelName, @NotNull String channelSerial);
3726
}
27+

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

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

3-
import io.ably.lib.plugins.PluginInstance;
3+
import io.ably.lib.types.ProtocolMessage;
44
import org.jetbrains.annotations.NotNull;
55

66
/**
77
* The LiveObjectsPlugin interface provides a mechanism for managing and interacting with
88
* live data objects in a real-time environment. It allows for the retrieval, disposal, and
99
* management of LiveObjects instances associated with specific channel names.
1010
*/
11-
public interface LiveObjectsPlugin extends PluginInstance {
11+
public interface LiveObjectsPlugin {
1212

1313
/**
1414
* Retrieves an instance of LiveObjects associated with the specified channel name.
@@ -21,6 +21,15 @@ public interface LiveObjectsPlugin extends PluginInstance {
2121
@NotNull
2222
LiveObjects getInstance(@NotNull String channelName);
2323

24+
/**
25+
* Handles a protocol message.
26+
* This method is invoked whenever a protocol message is received, allowing the implementation
27+
* to process the message and take appropriate actions.
28+
*
29+
* @param message the protocol message to handle.
30+
*/
31+
void handle(@NotNull ProtocolMessage message);
32+
2433
/**
2534
* Disposes of the LiveObjects instance associated with the specified channel name.
2635
* This method removes the LiveObjects instance for the given channel, releasing any
@@ -29,4 +38,9 @@ public interface LiveObjectsPlugin extends PluginInstance {
2938
* @param channelName the name of the channel whose LiveObjects instance is to be removed.
3039
*/
3140
void dispose(@NotNull String channelName);
41+
42+
/**
43+
* Disposes of the plugin instance and all underlying resources.
44+
*/
45+
void dispose();
3246
}

lib/src/main/java/io/ably/lib/plugins/PluginConnectionAdapter.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

lib/src/main/java/io/ably/lib/plugins/PluginInstance.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.util.List;
77
import java.util.Map;
88

9+
import io.ably.lib.objects.Adapter;
910
import io.ably.lib.objects.LiveObjectsAdapter;
1011
import io.ably.lib.objects.LiveObjectsPlugin;
1112
import io.ably.lib.rest.AblyRest;
@@ -187,7 +188,7 @@ public interface Channels extends ReadOnlyMap<String, Channel> {
187188
private LiveObjectsPlugin tryInitializeLiveObjectsPlugin() {
188189
try {
189190
Class<?> liveObjectsImplementation = Class.forName("io.ably.lib.objects.DefaultLiveObjectsPlugin");
190-
LiveObjectsAdapter adapter = new LiveObjectsAdapter.Adapter(this);
191+
LiveObjectsAdapter adapter = new Adapter(this);
191192
return (LiveObjectsPlugin) liveObjectsImplementation
192193
.getDeclaredConstructor(LiveObjectsAdapter.class)
193194
.newInstance(adapter);

live-objects/src/main/kotlin/io/ably/lib/objects/ObjectMessage.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import java.nio.ByteBuffer
77
* Spec: OOP2
88
*/
99
internal enum class ObjectOperationAction(val code: Int) {
10-
MAP_CREATE(0),
11-
MAP_SET(1),
12-
MAP_REMOVE(2),
13-
COUNTER_CREATE(3),
14-
COUNTER_INC(4),
15-
OBJECT_DELETE(5);
10+
MapCreate(0),
11+
MapSet(1),
12+
MapRemove(2),
13+
CounterCreate(3),
14+
CounterInc(4),
15+
ObjectDelete(5);
1616
}
1717

1818
/**
@@ -301,7 +301,7 @@ internal data class ObjectMessage(
301301
* the `ProtocolMessage` encapsulating it is `OBJECT_SYNC`.
302302
* Spec: OM2g
303303
*/
304-
val `object`: ObjectState? = null,
304+
val objectState: ObjectState? = null,
305305

306306
/**
307307
* An opaque string that uniquely identifies this object message.

0 commit comments

Comments
 (0)