diff --git a/api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java b/api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java index 4d81cf2..8db2262 100644 --- a/api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java +++ b/api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java @@ -7,6 +7,9 @@ import java.util.UUID; +/** + * Base class for event handlers that can be registered with {@link Octopus}. + */ @AllArgsConstructor @Getter public abstract class EventHandler { diff --git a/api/src/main/java/studio/o7/octopus/plugin/api/Octopus.java b/api/src/main/java/studio/o7/octopus/plugin/api/Octopus.java index f83efe1..725cca7 100644 --- a/api/src/main/java/studio/o7/octopus/plugin/api/Octopus.java +++ b/api/src/main/java/studio/o7/octopus/plugin/api/Octopus.java @@ -8,8 +8,44 @@ import java.util.UUID; +/** + * Main entry point for interacting with Octopus. + * + *
+ * Octopus provides operations to publish ("call") objects to a key, retrieve entries, and + * subscribe listeners to key patterns. + *
+ * + *Key format
+ *Wildcard patterns
+ *
+ * Example: {@code foo.*.bar} matches {@code foo.x.bar} but not {@code foo.x.y.bar}.
+ * Example: {@code foo.>} matches {@code foo}, {@code foo.bar}, {@code foo.bar.baz}, etc.
+ *
+ * The returned instance is the entry point for calling objects, retrieving entries, + * and registering listeners. + *
+ * + * @return the active {@link Octopus} instance + */ static Octopus instance() { return Unsafe.getInstance().get(); } @@ -31,59 +67,64 @@ static Octopus instance() { Result- * Stores an object on a key with new revision in the database - * and returns the stored version, including the new revision - * and ID. + * Publishes an object to the given key. * - *
Behavior
+ *Errors
+ *+ * Implementations may signal failures via an {@code OctopusError} (or another mechanism used by this API). + *
* - * @param obj Object that should be saved inside the database - * @return returns the created {@link studio.o7.octopus.sdk.v1.Entry} + * @param obj the affected object to publish + * @return the stored {@link Entry} on success, otherwise an {@link Error} */ Result- * Stores an object on a key with new revision in the database - * and just forgets it. All listeners will be called - * as usual without blocking this method. + * This operation is fire-and-forget: listeners are triggered asynchronously and this method + * does not block until they complete. + *
* - *Expired entries
+ *+ * If an entry should expire (for example, a permission), set its {@code expired_at} field. + * If it is not set, the entry will be flagged as expired. + *
* - *Deletion
+ *+ * To delete an entry, set its {@code deleted_at} field. The entry will then be flagged as deleted. + *
* - * @param obj Object that should be saved inside the database + * @param obj object that should be saved inside the database */ void write(studio.o7.octopus.sdk.v1.Object obj); /** - *- * A registration of a handler will subscribe to its given key pattern - * and receive all updates on the given key pattern. The handlers `onCall` - * method will be invoked on the incoming {@link studio.o7.octopus.sdk.v1.EventCall} - *
+ * Registers an {@link EventHandler} (listener) for a key pattern. + * + *Pattern rules
+ *
- * When subscribing, be reminded that the key pattern really matches the requested
- * EventCalls, using symbols such as `*` and `<` will subscribe on multiple keys
- * There's no safeguard to prevent subscribing to the same topic. So please make
- * shure you're not handling a topic twice!
+ * Example: {@code foo.*.bar} matches {@code foo.x.bar}.
+ * Example: {@code foo.>} matches {@code foo}, {@code foo.bar}, and {@code foo.bar.baz}.
*