Skip to content

Commit 7f9a94c

Browse files
committed
docs: added correct javadocs
1 parent bc7ef1b commit 7f9a94c

2 files changed

Lines changed: 78 additions & 34 deletions

File tree

api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
import java.util.UUID;
99

10+
/**
11+
* Base class for event handlers that can be registered with {@link Octopus}.
12+
*/
1013
@AllArgsConstructor
1114
@Getter
1215
public abstract class EventHandler {

api/src/main/java/studio/o7/octopus/plugin/api/Octopus.java

Lines changed: 75 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,44 @@
88

99
import java.util.UUID;
1010

11+
/**
12+
* Main entry point for interacting with Octopus.
13+
*
14+
* <p>
15+
* Octopus provides operations to publish ("call") objects to a key, retrieve entries, and
16+
* subscribe listeners to key patterns.
17+
* </p>
18+
*
19+
* <p><b>Key format</b></p>
20+
* <ul>
21+
* <li>Keys are dot-separated tokens, e.g. {@code foo.bar.baz}.</li>
22+
* <li>Patterns may include wildcards (see subscription methods / {@link EventHandler}).</li>
23+
* </ul>
24+
*
25+
* <p><b>Wildcard patterns</b></p>
26+
* <ul>
27+
* <li>{@code *} matches exactly one token (between dots).</li>
28+
* <li>{@code &gt;} matches zero or more tokens until the end of the key.</li>
29+
* </ul>
30+
*
31+
* <p>
32+
* Example: {@code foo.*.bar} matches {@code foo.x.bar} but not {@code foo.x.y.bar}.<br>
33+
* Example: {@code foo.&gt;} matches {@code foo}, {@code foo.bar}, {@code foo.bar.baz}, etc.
34+
* </p>
35+
*/
36+
1137
public interface Octopus {
1238

39+
/**
40+
* Returns the active {@link Octopus} implementation.
41+
*
42+
* <p>
43+
* The returned instance is the entry point for calling objects, retrieving entries,
44+
* and registering listeners.
45+
* </p>
46+
*
47+
* @return the active {@link Octopus} instance
48+
*/
1349
static Octopus instance() {
1450
return Unsafe.getInstance().get();
1551
}
@@ -31,59 +67,64 @@ static Octopus instance() {
3167
Result<QueryResponse, Error> query(QueryParameter queryParameter);
3268

3369
/**
34-
* <h1>Call</h1>
35-
* <p>
36-
* Stores an object on a key with new revision in the database
37-
* and returns the stored version, including the new revision
38-
* and ID.
70+
* Publishes an object to the given key.
3971
*
40-
* <h2>Expired</h2>
41-
* If an entry is expired. For example a permission, set the expired_at field
42-
* if it's not set and the entry will be flagged as expired
72+
* <p><b>Behavior</b></p>
73+
* <ul>
74+
* <li>Listeners are matched by their {@code keyPattern} (see {@link EventHandler}).</li>
75+
* <li>Wildcard patterns are supported:
76+
* {@code *} matches exactly one token; {@code &gt;} matches zero or more tokens until the end.</li>
77+
* </ul>
4378
*
44-
* <h2>Deletion</h2>
45-
* If an entry should be deleted, just set the deleted_at field and it will be
46-
* flagged as deleted
79+
* <p><b>Errors</b></p>
80+
* <p>
81+
* Implementations may signal failures via an {@code OctopusError} (or another mechanism used by this API).
82+
* </p>
4783
*
48-
* @param obj Object that should be saved inside the database
49-
* @return returns the created {@link studio.o7.octopus.sdk.v1.Entry}
84+
* @param obj the affected object to publish
85+
* @return the stored {@link Entry} on success, otherwise an {@link Error}
5086
*/
5187
Result<Entry, Error> call(studio.o7.octopus.sdk.v1.Object obj);
5288

5389
/**
54-
* <h1>Call</h1>
90+
* Publishes an object to the given key.
91+
*
5592
* <p>
56-
* Stores an object on a key with new revision in the database
57-
* and just forgets it. All listeners will be called
58-
* as usual without blocking this method.
93+
* This operation is fire-and-forget: listeners are triggered asynchronously and this method
94+
* does not block until they complete.
95+
* </p>
5996
*
60-
* <h2>Expired</h2>
61-
* If an entry is expired. For example a permission, set the expired_at field
62-
* if it's not set and the entry will be flagged as expired
97+
* <p><b>Expired entries</b></p>
98+
* <p>
99+
* If an entry should expire (for example, a permission), set its {@code expired_at} field.
100+
* If it is not set, the entry will be flagged as expired.
101+
* </p>
63102
*
64-
* <h2>Deletion</h2>
65-
* If an entry should be deleted, just set the deleted_at field and it will be
66-
* flagged as deleted
103+
* <p><b>Deletion</b></p>
104+
* <p>
105+
* To delete an entry, set its {@code deleted_at} field. The entry will then be flagged as deleted.
106+
* </p>
67107
*
68-
* @param obj Object that should be saved inside the database
108+
* @param obj object that should be saved inside the database
69109
*/
70110
void write(studio.o7.octopus.sdk.v1.Object obj);
71111

72112
/**
73-
* <p>
74-
* A registration of a handler will subscribe to its given key pattern
75-
* and receive all updates on the given key pattern. The handlers `onCall`
76-
* method will be invoked on the incoming {@link studio.o7.octopus.sdk.v1.EventCall}
77-
* </p>
113+
* Registers an {@link EventHandler} (listener) for a key pattern.
114+
*
115+
* <p><b>Pattern rules</b></p>
116+
* <ul>
117+
* <li>Tokens are dot-separated.</li>
118+
* <li>{@code *} matches exactly one token.</li>
119+
* <li>{@code &gt;} matches zero or more tokens until the end of the key.</li>
120+
* </ul>
78121
*
79122
* <p>
80-
* When subscribing, be reminded that the key pattern really matches the requested
81-
* EventCalls, using symbols such as `*` and `<` will subscribe on multiple keys
82-
* There's no safeguard to prevent subscribing to the same topic. So please make
83-
* shure you're not handling a topic twice!
123+
* Example: {@code foo.*.bar} matches {@code foo.x.bar}.<br>
124+
* Example: {@code foo.&gt;} matches {@code foo}, {@code foo.bar}, and {@code foo.bar.baz}.
84125
* </p>
85126
*
86-
* @param eventHandler Handler that will be invoked on matching incoming event
127+
* @param eventHandler the handler to register
87128
*/
88129
void registerHandler(EventHandler eventHandler);
89130

0 commit comments

Comments
 (0)