Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions android/src/main/java/io/ably/lib/realtime/Channel.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.ably.lib.types.AblyException;
import io.ably.lib.types.ChannelOptions;
import io.ably.lib.push.PushChannel;
import io.ably.lib.objects.LiveObjectsPlugin;
import io.ably.lib.objects.ObjectsPlugin;


public class Channel extends ChannelBase {
Expand All @@ -14,8 +14,8 @@ public class Channel extends ChannelBase {
*/
public final PushChannel push;

Channel(AblyRealtime ably, String name, ChannelOptions options, LiveObjectsPlugin liveObjectsPlugin) throws AblyException {
super(ably, name, options, liveObjectsPlugin);
Channel(AblyRealtime ably, String name, ChannelOptions options, ObjectsPlugin objectsPlugin) throws AblyException {
super(ably, name, options, objectsPlugin);
this.push = ((io.ably.lib.rest.AblyRest) ably).channels.get(name, options).push;
}

Expand Down
7 changes: 4 additions & 3 deletions java/src/main/java/io/ably/lib/realtime/Channel.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package io.ably.lib.realtime;

import io.ably.lib.objects.LiveObjectsPlugin;
import io.ably.lib.objects.ObjectsPlugin;
import io.ably.lib.types.AblyException;
import io.ably.lib.types.ChannelOptions;
import org.jetbrains.annotations.Nullable;

public class Channel extends ChannelBase {
Channel(AblyRealtime ably, String name, ChannelOptions options, LiveObjectsPlugin liveObjectsPlugin) throws AblyException {
super(ably, name, options, liveObjectsPlugin);
Channel(AblyRealtime ably, String name, ChannelOptions options, @Nullable ObjectsPlugin objectsPlugin) throws AblyException {
super(ably, name, options, objectsPlugin);
}

public interface MessageListener extends ChannelBase.MessageListener {}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/objects/Adapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import io.ably.lib.util.Log;
import org.jetbrains.annotations.NotNull;

public class Adapter implements LiveObjectsAdapter {
public class Adapter implements ObjectsAdapter {
private final AblyRealtime ably;
private static final String TAG = LiveObjectsAdapter.class.getName();
private static final String TAG = ObjectsAdapter.class.getName();

public Adapter(@NotNull AblyRealtime ably) {
this.ably = ably;
Expand Down
45 changes: 0 additions & 45 deletions lib/src/main/java/io/ably/lib/objects/LiveObjectsHelper.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import org.jetbrains.annotations.Blocking;
import org.jetbrains.annotations.NotNull;

public interface LiveObjectsAdapter {
public interface ObjectsAdapter {
/**
* Retrieves the client options configured for the Ably client.
* Used to access client configuration parameters such as echoMessages setting
* that affect the behavior of LiveObjects operations.
* that affect the behavior of Objects operations.
*
* @return the client options containing configuration parameters
*/
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/objects/ObjectsCallback.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import io.ably.lib.types.AblyException;

/**
* Callback interface for handling results of asynchronous LiveObjects operations.
* Callback interface for handling results of asynchronous Objects operations.
* Used for operations like creating LiveMaps/LiveCounters, modifying entries, and retrieving objects.
* Callbacks are executed on background threads managed by the LiveObjects system.
* Callbacks are executed on background threads managed by the Objects system.
*
* @param <T> the type of the result returned by the asynchronous operation
*/
Expand Down
48 changes: 48 additions & 0 deletions lib/src/main/java/io/ably/lib/objects/ObjectsHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.ably.lib.objects;

import io.ably.lib.realtime.AblyRealtime;
import io.ably.lib.util.Log;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.InvocationTargetException;

public class ObjectsHelper {

private static final String TAG = ObjectsHelper.class.getName();
private static volatile ObjectsSerializer objectsSerializer;

@Nullable
public static ObjectsPlugin tryInitializeObjectsPlugin(AblyRealtime ablyRealtime) {
try {
Class<?> objectsImplementation = Class.forName("io.ably.lib.objects.DefaultObjectsPlugin");
ObjectsAdapter adapter = new Adapter(ablyRealtime);
return (ObjectsPlugin) objectsImplementation
.getDeclaredConstructor(ObjectsAdapter.class)
.newInstance(adapter);
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | NoSuchMethodException |
InvocationTargetException e) {
Log.i(TAG, "LiveObjects plugin not found in classpath. LiveObjects functionality will not be available.", e);
return null;
}
}

@Nullable
public static ObjectsSerializer getSerializer() {
if (objectsSerializer == null) {
synchronized (ObjectsHelper.class) {
if (objectsSerializer == null) { // Double-Checked Locking (DCL)
try {
Class<?> serializerClass = Class.forName("io.ably.lib.objects.serialization.DefaultObjectsSerializer");
objectsSerializer = (ObjectsSerializer) serializerClass.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
NoSuchMethodException |
InvocationTargetException e) {
Log.w(TAG, "Failed to init ObjectsSerializer, LiveObjects plugin not included in the classpath", e);
return null;
}
}
}
}
return objectsSerializer;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

import java.lang.reflect.Type;

public class LiveObjectsJsonSerializer implements JsonSerializer<Object[]>, JsonDeserializer<Object[]> {
private static final String TAG = LiveObjectsJsonSerializer.class.getName();
public class ObjectsJsonSerializer implements JsonSerializer<Object[]>, JsonDeserializer<Object[]> {
private static final String TAG = ObjectsJsonSerializer.class.getName();

@Override
public Object[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
LiveObjectSerializer serializer = LiveObjectsHelper.getLiveObjectSerializer();
ObjectsSerializer serializer = ObjectsHelper.getSerializer();
if (serializer == null) {
Log.w(TAG, "Skipping 'state' field json deserialization because LiveObjectsSerializer not found.");
Log.w(TAG, "Skipping 'state' field json deserialization because ObjectsSerializer not found.");
return null;
}
if (!json.isJsonArray()) {
Expand All @@ -29,9 +29,9 @@ public Object[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationC

@Override
public JsonElement serialize(Object[] src, Type typeOfSrc, JsonSerializationContext context) {
LiveObjectSerializer serializer = LiveObjectsHelper.getLiveObjectSerializer();
ObjectsSerializer serializer = ObjectsHelper.getSerializer();
if (serializer == null) {
Log.w(TAG, "Skipping 'state' field json serialization because LiveObjectsSerializer not found.");
Log.w(TAG, "Skipping 'state' field json serialization because ObjectsSerializer not found.");
return JsonNull.INSTANCE;
}
return serializer.asJsonArray(src);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
import org.jetbrains.annotations.NotNull;

/**
* The LiveObjectsPlugin interface provides a mechanism for managing and interacting with
* The ObjectsPlugin interface provides a mechanism for managing and interacting with
* live data objects in a real-time environment. It allows for the retrieval, disposal, and
* management of LiveObjects instances associated with specific channel names.
* management of Objects instances associated with specific channel names.
*/
public interface LiveObjectsPlugin {
public interface ObjectsPlugin {

/**
* Retrieves an instance of LiveObjects associated with the specified channel name.
* This method ensures that a LiveObjects instance is available for the given channel,
* Retrieves an instance of RealtimeObjects associated with the specified channel name.
* This method ensures that a RealtimeObjects instance is available for the given channel,
* creating one if it does not already exist.
*
* @param channelName the name of the channel for which the LiveObjects instance is to be retrieved.
* @return the LiveObjects instance associated with the specified channel name.
* @param channelName the name of the channel for which the RealtimeObjects instance is to be retrieved.
* @return the RealtimeObjects instance associated with the specified channel name.
*/
@NotNull
LiveObjects getInstance(@NotNull String channelName);
RealtimeObjects getInstance(@NotNull String channelName);

/**
* Handles a protocol message.
Expand All @@ -34,7 +34,7 @@ public interface LiveObjectsPlugin {
/**
* Handles state changes for a specific channel.
* This method is invoked whenever a channel's state changes, allowing the implementation
* to update the LiveObjects instances accordingly based on the new state and presence of objects.
* to update the RealtimeObjects instances accordingly based on the new state and presence of objects.
*
* @param channelName the name of the channel whose state has changed.
* @param state the new state of the channel.
Expand All @@ -43,12 +43,12 @@ public interface LiveObjectsPlugin {
void handleStateChange(@NotNull String channelName, @NotNull ChannelState state, boolean hasObjects);

/**
* Disposes of the LiveObjects instance associated with the specified channel name.
* This method removes the LiveObjects instance for the given channel, releasing any
* Disposes of the RealtimeObjects instance associated with the specified channel name.
* This method removes the RealtimeObjects instance for the given channel, releasing any
* resources associated with it.
* This is invoked when ablyRealtimeClient.channels.release(channelName) is called
*
* @param channelName the name of the channel whose LiveObjects instance is to be removed.
* @param channelName the name of the channel whose RealtimeObjects instance is to be removed.
*/
void dispose(@NotNull String channelName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@
import java.io.IOException;

/**
* Serializer interface for converting between LiveObject arrays and their
* MessagePack or JSON representations.
* Serializer interface for converting between objects and their MessagePack or JSON representations.
*/
public interface LiveObjectSerializer {
public interface ObjectsSerializer {
/**
* Reads a MessagePack array from the given unpacker and deserializes it into an Object array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import java.util.Map;

/**
* The LiveObjects interface provides methods to interact with live data objects,
* The RealtimeObjects interface provides methods to interact with live data objects,
* such as maps and counters, in a real-time environment. It supports both synchronous
* and asynchronous operations for retrieving and creating live objects.
*
* <p>Implementations of this interface must be thread-safe as they may be accessed
* from multiple threads concurrently.
*/
public interface LiveObjects extends ObjectsStateChange {
public interface RealtimeObjects extends ObjectsStateChange {

/**
* Retrieves the root LiveMap object.
Expand Down Expand Up @@ -62,10 +62,10 @@ public interface LiveObjects extends ObjectsStateChange {
* "binary", LiveMapValue.of(new byte[]{1, 2, 3}),
* "array", LiveMapValue.of(new JsonArray()),
* "object", LiveMapValue.of(new JsonObject()),
* "counter", LiveMapValue.of(liveObjects.createCounter()),
* "nested", LiveMapValue.of(liveObjects.createMap())
* "counter", LiveMapValue.of(realtimeObjects.createCounter()),
* "nested", LiveMapValue.of(realtimeObjects.createMap())
* );
* LiveMap map = liveObjects.createMap(entries);
* LiveMap map = realtimeObjects.createMap(entries);
* }</pre>
*
* @param entries the type-safe map entries with values that can be Boolean, Binary, Number, String, JsonArray, JsonObject, LiveCounter, or LiveMap.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import org.jetbrains.annotations.Nullable;

/**
* Abstract base class for all LiveObject update notifications.
* Abstract base class for all LiveMap/LiveCounter update notifications.
* Provides common structure for updates that occur on LiveMap and LiveCounter objects.
* Contains the update data that describes what changed in the live object.
* Spec: RTLO4b4
*/
public abstract class LiveObjectUpdate {
public abstract class ObjectUpdate {
/**
* The update data containing details about the change that occurred
* Spec: RTLO4b4a
Expand All @@ -17,11 +17,11 @@ public abstract class LiveObjectUpdate {
protected final Object update;

/**
* Creates a LiveObjectUpdate with the specified update data.
* Creates a ObjectUpdate with the specified update data.
*
* @param update the data describing the change, or null for no-op updates
*/
protected LiveObjectUpdate(@Nullable Object update) {
protected ObjectUpdate(@Nullable Object update) {
this.update = update;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.ably.lib.objects.type.counter;

import io.ably.lib.objects.type.LiveObjectUpdate;
import io.ably.lib.objects.type.ObjectUpdate;
import org.jetbrains.annotations.NotNull;

/**
Expand All @@ -10,7 +10,7 @@
*
* @spec RTLC11, RTLC11a - LiveCounter update structure and behavior
*/
public class LiveCounterUpdate extends LiveObjectUpdate {
public class LiveCounterUpdate extends ObjectUpdate {

/**
* Creates a no-op LiveCounterUpdate representing no actual change.
Expand Down
4 changes: 2 additions & 2 deletions lib/src/main/java/io/ably/lib/objects/type/map/LiveMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public interface LiveMap extends LiveMapChange {
* If this map object is tombstoned (deleted), null is returned.
* If no entry is associated with the specified key, null is returned.
* If map entry is tombstoned (deleted), null is returned.
* If the value associated with the provided key is an objectId string of another LiveObject, a reference to that LiveObject
* is returned, provided it exists in the local pool and is not tombstoned. Otherwise, null is returned.
* If the value associated with the provided key is an objectId string of another RealtimeObject, a reference to
* that RealtimeObject is returned, provided it exists in the local pool and is not tombstoned. Otherwise, null is returned.
* If the value is not an objectId, then that value is returned.
* Spec: RTLM5, RTLM5a
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.ably.lib.objects.type.map;

import io.ably.lib.objects.type.LiveObjectUpdate;
import io.ably.lib.objects.type.ObjectUpdate;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
Expand All @@ -11,7 +11,7 @@
*
* @spec RTLM18, RTLM18a - LiveMap update structure and behavior
*/
public class LiveMapUpdate extends LiveObjectUpdate {
public class LiveMapUpdate extends ObjectUpdate {

/**
* Creates a no-op LiveMapUpdate representing no actual change.
Expand Down
Loading
Loading