Skip to content

Commit 03d3e61

Browse files
Merge pull request #20 from o7studios/feat/octopusv2
Feat/octopusv2
2 parents 4bae308 + 0dff83b commit 03d3e61

27 files changed

Lines changed: 462 additions & 515 deletions

.devcontainer/devcontainer.json

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

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ on:
55
types: [ opened, reopened ]
66

77
env:
8-
JAVA_VERSION: '23'
8+
JAVA_VERSION: '25'
99
JAVA_DISTRIBUTION: 'temurin'
1010

1111
permissions:

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.vscode
33
.gradle
44
build
5+
/plugin/run

README.md

Lines changed: 13 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,53 +16,24 @@ dependencies {
1616
}
1717
```
1818

19-
Add _depend_ inside `plugin.yml`:
19+
Add _depend on_ inside `plugin.yml`:
2020

2121
```yaml
2222
depend:
2323
- Octopus
2424
```
2525
26-
## Development
26+
### Config
2727
28-
Full development setup available as [Development Container](https://containers.dev/).
29-
Please use it for being able to tell "It works on my machine".
28+
Make sure this is inside of the `/plugins/octopus/config.yml`
3029

31-
**Docker is required to be installed on your machine!**
32-
33-
### Create ~/dev.env
34-
35-
The development container is using a local env file on your
36-
host machine for reading e.g. GitHub Tokens, Usernames, Email.
37-
So please make sure it exists with your credentials in `~/dev.env`:
38-
39-
```text
40-
GITHUB_EMAIL=your-mail@your-domain.com
41-
GITHUB_USERNAME=YOUR_GITHUB_USERNAME
42-
GITHUB_TOKEN=ghp_***
43-
```
44-
45-
The `GITHUB_TOKEN` must've set following permission:
46-
47-
- `repo`
48-
- `read:packages`
49-
- `read:user`
50-
- `user:email`
51-
52-
### IntelliJ IDEA
53-
54-
- Open IntelliJ (Welcome screen)
55-
- Navigate to `Remote Development` - `Dev Containers`
56-
- Press `New Dev Container`
57-
- Select `From VCS Project`
58-
- Select and connect with `Docker`
59-
- Select `IntelliJ IDEA`
60-
- Enter `Git Repository`: `https://github.com/o7studios/octopus-plugin`
61-
- Select `Detection for devcontainer.json file` `Automatic`
62-
- Press `Build Container and Continue`
63-
64-
### Development Container Issues
65-
66-
If you encounter an issue with setting up a development container, please
67-
try to rebuild it first before opening a GitHub Issue. It's not uncommon
68-
that some issues may fix themselves after a fresh container rebuild.
30+
```yml
31+
# Configuration of Octopus-Service
32+
octopus:
33+
# Host of Octopus-gRPC Server
34+
host: "127.0.0.1"
35+
# Port of Octopus-gRPC Server
36+
port: 50051
37+
# Replace to Octopus-API token
38+
token: "development"
39+
```

api/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ repositories {
33
}
44

55
dependencies {
6-
api("studio.o7:octopus-sdk:0.3.3")
7-
compileOnly("io.papermc.paper:paper-api:1.21.8-R0.1-SNAPSHOT")
6+
api("studio.o7:octopus-sdk:0.5.9")
7+
api("studio.o7:gentle:0.0.2")
8+
compileOnly("io.papermc.paper:paper-api:1.21.11-R0.1-SNAPSHOT")
89
}
910

1011
information {

api/src/main/java/studio/o7/octopus/plugin/api/listener/Listener.java renamed to api/src/main/java/studio/o7/octopus/plugin/api/EventHandler.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
package studio.o7.octopus.plugin.api.listener;
1+
package studio.o7.octopus.plugin.api;
22

33
import lombok.AllArgsConstructor;
44
import lombok.Getter;
55
import lombok.NonNull;
6-
import studio.o7.octopus.sdk.gen.api.v1.Object;
6+
import studio.o7.octopus.sdk.v1.Object;
77

88
import java.util.UUID;
99

1010
@AllArgsConstructor
1111
@Getter
12-
public abstract class Listener {
12+
public abstract class EventHandler {
1313
/**
1414
* ID for identifying this listener.
1515
* (Made for internal purposes)
@@ -26,11 +26,6 @@ public abstract class Listener {
2626
*/
2727
protected final String keyPattern;
2828

29-
/**
30-
* Priority of this listener (e.g. determines event order; lower is later)
31-
*/
32-
protected final int priority;
33-
3429
/**
3530
* @param obj The affected object.
3631
*/
Lines changed: 75 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,105 @@
11
package studio.o7.octopus.plugin.api;
22

3-
import org.jspecify.annotations.NullMarked;
3+
import gentle.Error;
4+
import gentle.Result;
45
import studio.o7.octopus.plugin.Unsafe;
5-
import studio.o7.octopus.plugin.api.listener.Listener;
6-
import studio.o7.octopus.sdk.gen.api.v1.Entry;
7-
import studio.o7.octopus.sdk.gen.api.v1.Object;
6+
import studio.o7.octopus.sdk.v1.Entry;
7+
import studio.o7.octopus.sdk.v1.QueryResponse;
88

9-
import javax.annotation.Nullable;
10-
import java.time.Instant;
11-
import java.util.Collection;
129
import java.util.UUID;
1310

14-
@NullMarked
1511
public interface Octopus {
1612

17-
static Octopus get() {
13+
static Octopus instance() {
1814
return Unsafe.getInstance().get();
1915
}
2016

2117
/**
22-
* Retrieves existing entries from the database matching a
23-
* key pattern.
18+
* Gets a unique entry of the given key
19+
*
20+
* @param key exact key pattern that will match between entries until one is found
21+
* @return Returns the first {@link studio.o7.octopus.sdk.v1.Entry} that matches the key
2422
*/
25-
default Collection<Entry> get(String keyPattern) {
26-
return get(keyPattern, false);
27-
}
28-
29-
/**
30-
* Retrieves existing entries from the database matching a
31-
* key pattern. Can optionally include expired objects.
32-
*/
33-
default Collection<Entry> get(String keyPattern, boolean includeExpired) {
34-
return get(keyPattern, includeExpired, null, null);
35-
}
23+
Result<studio.o7.octopus.sdk.v1.Object, Error> get(String key);
3624

3725
/**
38-
* Retrieves existing entries from the database matching a
39-
* key pattern. Can optionally include expired objects and
40-
* filter by revision creation time.
26+
* Query multiple Entries
27+
*
28+
* @param queryParameter Query parameter to build the query request
29+
* @return Returns a collection of matches for this query request
4130
*/
42-
Collection<Entry> get(String keyPattern, boolean includeExpired, @Nullable Instant createdRangeStart, @Nullable Instant createdRangeEnd);
43-
44-
45-
void registerListener(Listener listener);
46-
47-
default void unregisterListener(Listener listener) {
48-
unregisterListener(listener.getListenerUniqueId());
49-
}
50-
51-
void unregisterListener(UUID listenerUniqueId);
31+
Result<QueryResponse, Error> query(QueryParameter queryParameter);
5232

5333
/**
34+
* <h1>Call</h1>
35+
* <p>
5436
* Stores an object on a key with new revision in the database
5537
* and returns the stored version, including the new revision
5638
* and ID.
39+
*
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
43+
*
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
47+
*
48+
* @param obj Object that should be saved inside the database
49+
* @return returns the created {@link studio.o7.octopus.sdk.v1.Entry}
5750
*/
58-
Entry call(Object obj);
51+
Result<Entry, Error> call(studio.o7.octopus.sdk.v1.Object obj);
5952

6053
/**
54+
* <h1>Call</h1>
55+
* <p>
6156
* Stores an object on a key with new revision in the database
6257
* and just forgets it. All listeners will be called
6358
* as usual without blocking this method.
59+
*
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
63+
*
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
67+
*
68+
* @param obj Object that should be saved inside the database
6469
*/
65-
void callAndForget(Object obj);
70+
void write(studio.o7.octopus.sdk.v1.Object obj);
6671

72+
/**
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>
78+
*
79+
* <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!
84+
* </p>
85+
*
86+
* @param eventHandler Handler that will be invoked on matching incoming event
87+
*/
88+
void registerHandler(EventHandler eventHandler);
89+
90+
/**
91+
* Unregister a handler
92+
*
93+
* @param eventHandler Handler to unregister
94+
*/
95+
default void unregisterHandler(EventHandler eventHandler) {
96+
unregisterHandler(eventHandler.getListenerUniqueId());
97+
}
98+
99+
/**
100+
* Unregister a handler
101+
*
102+
* @param listenerUniqueId ID of the handler to unregister
103+
*/
104+
void unregisterHandler(UUID listenerUniqueId);
67105
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package studio.o7.octopus.plugin.api;
2+
3+
import gentle.Error;
4+
import lombok.NonNull;
5+
6+
public enum OctopusError implements Error {
7+
8+
GET_REQUEST_FAILED(0, "While trying to get an entry, a gRPC-Error occurred"),
9+
QUERY_REQUEST_FAILED(1, "While trying to query an entry, a gRPC-Error occurred"),
10+
CALL_REQUEST_FAILED(1, "While trying to call an object, a gRPC-Error occurred"),
11+
12+
;
13+
14+
private final int code;
15+
private final String message;
16+
17+
OctopusError(int code, String message) {
18+
this.code = code;
19+
this.message = message;
20+
}
21+
22+
@Override
23+
public int code() {
24+
return this.code;
25+
}
26+
27+
@Override
28+
public @NonNull String message() {
29+
return this.message;
30+
}
31+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package studio.o7.octopus.plugin.api;
2+
import lombok.Builder;
3+
import lombok.Getter;
4+
5+
@Getter
6+
@Builder
7+
public class QueryParameter {
8+
9+
private String keyPattern;
10+
private String dataFilter;
11+
12+
private boolean includeExpired;
13+
14+
private int page;
15+
private int pageSize;
16+
17+
private com.google.protobuf.Timestamp createdAtStart;
18+
private com.google.protobuf.Timestamp createdAtEnd;
19+
20+
}

api/src/main/java/studio/o7/octopus/plugin/api/adapters/ComponentAdapter.java

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

0 commit comments

Comments
 (0)