-
Notifications
You must be signed in to change notification settings - Fork 44
Setup : LiveObject plugin #1085
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c435f5d
Created and configured liveobjects as a separate module to the project
ttypic bce4ba9
1. Added jetbrains-annoations dependency to clearly define interface …
sacOO7 d81cb24
1. Updated public doc for LiveObjects, LiveMap and LiveCounter
sacOO7 d87b365
1. Added coroutinex as a runtime and test dependency to liveobjects
sacOO7 cd7d075
1. Added blocking and non-blocking annotations to sync and async methods
sacOO7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| package io.ably.lib.objects; | ||
|
|
||
| import io.ably.lib.types.Callback; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Contract; | ||
|
|
||
| /** | ||
| * The LiveCounter interface provides methods to interact with a live counter. | ||
| * It allows incrementing, decrementing, and retrieving the current value of the counter, | ||
| * both synchronously and asynchronously. | ||
| */ | ||
| public interface LiveCounter { | ||
|
|
||
| /** | ||
| * Increments the value of the counter by 1. | ||
| * Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object. | ||
| * This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when | ||
| * the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| */ | ||
| void increment(); | ||
|
|
||
| /** | ||
| * Increments the value of the counter by 1 asynchronously. | ||
| * Send a COUNTER_INC operation to the realtime system to increment a value on this LiveCounter object. | ||
| * This does not modify the underlying data of this LiveCounter object. Instead, the change will be applied when | ||
| * the published COUNTER_INC operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| * | ||
| * @param callback the callback to be invoked upon completion of the operation. | ||
| */ | ||
| void incrementAsync(@NotNull Callback<Void> callback); | ||
|
|
||
| /** | ||
| * Decrements the value of the counter by 1. | ||
| * An alias for calling {@link LiveCounter#increment()} with a negative amount. | ||
| */ | ||
| void decrement(); | ||
|
|
||
| /** | ||
| * Decrements the value of the counter by 1 asynchronously. | ||
| * An alias for calling {@link LiveCounter#increment()} with a negative amount. | ||
| * | ||
| * @param callback the callback to be invoked upon completion of the operation. | ||
| */ | ||
| void decrementAsync(@NotNull Callback<Void> callback); | ||
|
|
||
| /** | ||
| * Retrieves the current value of the counter. | ||
| * | ||
| * @return the current value of the counter as a Long. | ||
| */ | ||
| @NotNull | ||
| @Contract(pure = true) // Indicates this method does not modify the state of the object. | ||
| Long value(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| package io.ably.lib.objects; | ||
|
|
||
| import io.ably.lib.types.Callback; | ||
| import org.jetbrains.annotations.Contract; | ||
| import org.jetbrains.annotations.NotNull; | ||
| import org.jetbrains.annotations.Nullable; | ||
| import org.jetbrains.annotations.Unmodifiable; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * The LiveMap interface provides methods to interact with a live, real-time map structure. | ||
| * It supports both synchronous and asynchronous operations for managing key-value pairs. | ||
| */ | ||
| public interface LiveMap { | ||
|
|
||
| /** | ||
| * Retrieves the value associated with the specified key. | ||
| * If this map object is tombstoned (deleted), `undefined` is returned. | ||
| * If no entry is associated with the specified key, `undefined` is returned. | ||
| * If map entry is tombstoned (deleted), `undefined` 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, `undefined` is returned. | ||
| * If the value is not an objectId, then that value is returned. | ||
| * | ||
| * @param keyName the key whose associated value is to be returned. | ||
| * @return the value associated with the specified key, or null if the key does not exist. | ||
| */ | ||
| @Nullable | ||
| Object get(@NotNull String keyName); | ||
|
|
||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| /** | ||
| * Retrieves all entries (key-value pairs) in the map. | ||
| * | ||
| * @return an iterable collection of all entries in the map. | ||
| */ | ||
| @NotNull | ||
| @Unmodifiable | ||
| Iterable<Map.Entry<String, Object>> entries(); | ||
|
|
||
| /** | ||
| * Retrieves all keys in the map. | ||
| * | ||
| * @return an iterable collection of all keys in the map. | ||
| */ | ||
| @NotNull | ||
| @Unmodifiable | ||
| Iterable<String> keys(); | ||
|
|
||
| /** | ||
| * Retrieves all values in the map. | ||
| * | ||
| * @return an iterable collection of all values in the map. | ||
| */ | ||
| @NotNull | ||
| @Unmodifiable | ||
| Iterable<Object> values(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Sets the specified key to the given value in the map. | ||
| * Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value. | ||
| * This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when | ||
| * the published MAP_SET operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| * | ||
| * @param keyName the key to be set. | ||
| * @param value the value to be associated with the key. | ||
| */ | ||
| void set(@NotNull String keyName, @NotNull Object value); | ||
|
|
||
| /** | ||
| * Removes the specified key and its associated value from the map. | ||
| * Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object. | ||
| * This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when | ||
| * the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| * | ||
| * @param keyName the key to be removed. | ||
| */ | ||
| void remove(@NotNull String keyName); | ||
|
|
||
| /** | ||
| * Retrieves the number of entries in the map. | ||
| * | ||
| * @return the size of the map. | ||
| */ | ||
| @Contract(pure = true) // Indicates this method does not modify the state of the object. | ||
| @NotNull | ||
| Long size(); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Asynchronously sets the specified key to the given value in the map. | ||
| * Send a MAP_SET operation to the realtime system to set a key on this LiveMap object to a specified value. | ||
| * This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when | ||
| * the published MAP_SET operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| * | ||
| * @param keyName the key to be set. | ||
| * @param value the value to be associated with the key. | ||
| * @param callback the callback to handle the result or any errors. | ||
| */ | ||
| void setAsync(@NotNull String keyName, @NotNull Object value, @NotNull Callback<Void> callback); | ||
|
|
||
| /** | ||
| * Asynchronously removes the specified key and its associated value from the map. | ||
| * Send a MAP_REMOVE operation to the realtime system to tombstone a key on this LiveMap object. | ||
| * This does not modify the underlying data of this LiveMap object. Instead, the change will be applied when | ||
| * the published MAP_REMOVE operation is echoed back to the client and applied to the object following the regular | ||
| * operation application procedure. | ||
| * | ||
| * @param keyName the key to be removed. | ||
| * @param callback the callback to handle the result or any errors. | ||
| */ | ||
| void removeAsync(@NotNull String keyName, @NotNull Callback<Void> callback); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,159 @@ | ||
| package io.ably.lib.objects; | ||
|
|
||
| import io.ably.lib.objects.batch.BatchContextBuilder; | ||
| import io.ably.lib.types.Callback; | ||
| import org.jetbrains.annotations.NotNull; | ||
|
|
||
|
|
||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * The LiveObjects 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 { | ||
|
sacOO7 marked this conversation as resolved.
|
||
|
|
||
| /** | ||
| * Retrieves the root LiveMap object. | ||
| * When called without a type variable, we return a default root type which is based on globally defined interface for Objects feature. | ||
| * A user can provide an explicit type for the getRoot method to explicitly set the type structure on this particular channel. | ||
| * This is useful when working with multiple channels with different underlying data structure. | ||
| * | ||
| * @return the root LiveMap instance. | ||
| */ | ||
| @NotNull | ||
| LiveMap getRoot(); | ||
|
|
||
| /** | ||
| * Initiates a batch operation and provides a BatchContext through a callback. | ||
| * Provides access to the synchronous write API for Objects that can be used to batch multiple operations | ||
| * together in a single channel message. | ||
| * | ||
| * @param batchContextCallback the builder to configure the batch operation. | ||
| */ | ||
| void batch(@NotNull BatchContextBuilder batchContextCallback); | ||
|
|
||
| /** | ||
| * Creates a new LiveMap based on an existing LiveMap. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param liveMap the existing LiveMap to base the new LiveMap on. | ||
| * @return the newly created LiveMap instance. | ||
| */ | ||
| @NotNull | ||
| LiveMap createMap(@NotNull LiveMap liveMap); | ||
|
|
||
| /** | ||
| * Creates a new LiveMap based on a LiveCounter. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param liveCounter the LiveCounter to base the new LiveMap on. | ||
| * @return the newly created LiveMap instance. | ||
| */ | ||
| @NotNull | ||
| LiveMap createMap(@NotNull LiveCounter liveCounter); | ||
|
|
||
| /** | ||
| * Creates a new LiveMap based on a standard Java Map. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param map the Java Map to base the new LiveMap on. | ||
| * @return the newly created LiveMap instance. | ||
| */ | ||
| @NotNull | ||
| LiveMap createMap(@NotNull Map<String, Object> map); | ||
|
|
||
|
sacOO7 marked this conversation as resolved.
|
||
| /** | ||
| * Creates a new LiveCounter with an initial value. | ||
| * Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param initialValue the initial value of the LiveCounter. | ||
| * @return the newly created LiveCounter instance. | ||
| */ | ||
| @NotNull | ||
| LiveCounter createCounter(@NotNull Long initialValue); | ||
|
|
||
| /** | ||
| * Asynchronously retrieves the root LiveMap object. | ||
| * When called without a type variable, we return a default root type which is based on globally defined interface for Objects feature. | ||
| * A user can provide an explicit type for the getRoot method to explicitly set the type structure on this particular channel. | ||
| * This is useful when working with multiple channels with different underlying data structure. | ||
| * | ||
| * @param callback the callback to handle the result or error. | ||
| */ | ||
| void getRootAsync(@NotNull Callback<@NotNull LiveMap> callback); | ||
|
|
||
| /** | ||
| * Initiates a batch operation asynchronously. | ||
| * Provides access to the synchronous write API for Objects that can be used to batch multiple operations | ||
| * together in a single channel message. | ||
| * | ||
| * @param batchContextCallback the builder to configure the batch operation. | ||
| * @param callback the Callback to handle the completion or error of the batch operation. | ||
| */ | ||
| void batchAsync(@NotNull BatchContextBuilder batchContextCallback, @NotNull Callback<Void> callback); | ||
|
|
||
| /** | ||
| * Asynchronously creates a new LiveMap based on an existing LiveMap. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param liveMap the existing LiveMap to base the new LiveMap on. | ||
| * @param callback the callback to handle the result or error. | ||
| */ | ||
| void createMapAsync(@NotNull LiveMap liveMap, @NotNull Callback<@NotNull LiveMap> callback); | ||
|
|
||
| /** | ||
| * Asynchronously creates a new LiveMap based on a LiveCounter. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param liveCounter the LiveCounter to base the new LiveMap on. | ||
| * @param callback the callback to handle the result or error. | ||
| */ | ||
| void createMapAsync(@NotNull LiveCounter liveCounter, @NotNull Callback<@NotNull LiveMap> callback); | ||
|
|
||
| /** | ||
| * Asynchronously creates a new LiveMap based on a standard Java Map. | ||
| * Send a MAP_CREATE operation to the realtime system to create a new map object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed MAP_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param map the Java Map to base the new LiveMap on. | ||
| * @param callback the callback to handle the result or error. | ||
| */ | ||
| void createMapAsync(@NotNull Map<String, Object> map, @NotNull Callback<@NotNull LiveMap> callback); | ||
|
|
||
|
sacOO7 marked this conversation as resolved.
|
||
| /** | ||
| * Asynchronously creates a new LiveCounter with an initial value. | ||
| * Send a COUNTER_CREATE operation to the realtime system to create a new counter object in the pool. | ||
| * Once the ACK message is received, the method returns the object from the local pool if it got created due to | ||
| * the echoed COUNTER_CREATE operation, or if it wasn't received yet, the method creates a new object locally | ||
| * using the provided data and returns it. | ||
| * | ||
| * @param initialValue the initial value of the LiveCounter. | ||
| * @param callback the callback to handle the result or error. | ||
| */ | ||
| void createCounterAsync(@NotNull Long initialValue, @NotNull Callback<@NotNull LiveCounter> callback); | ||
| } | ||
|
sacOO7 marked this conversation as resolved.
sacOO7 marked this conversation as resolved.
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.