-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Reimplemented octopus sdk #6
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| dependencies { | ||
| api("studio.o7:octopus-sdk:0.0.2") | ||
| api("studio.o7:octopus-sdk:0.1.2") | ||
| } | ||
|
|
||
| information { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,9 +1,15 @@ | ||||||||||||||||||
| package studio.o7.octopus.plugin.api; | ||||||||||||||||||
|
|
||||||||||||||||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||||||||||||||||
| import lombok.NonNull; | ||||||||||||||||||
| import org.jetbrains.annotations.ApiStatus; | ||||||||||||||||||
| import org.jetbrains.annotations.NotNull; | ||||||||||||||||||
| import org.jspecify.annotations.NullMarked; | ||||||||||||||||||
| import studio.o7.octopus.plugin.api.client.OctopusClient; | ||||||||||||||||||
| import studio.o7.octopus.plugin.Unsafe; | ||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.Entry; | ||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.Event; | ||||||||||||||||||
|
|
||||||||||||||||||
| import java.util.Collection; | ||||||||||||||||||
| import java.util.List; | ||||||||||||||||||
|
|
||||||||||||||||||
| @NullMarked | ||||||||||||||||||
| public interface Octopus { | ||||||||||||||||||
|
|
@@ -12,13 +18,38 @@ static Octopus get() { | |||||||||||||||||
| return Unsafe.getInstance().get(); | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| OctopusClient getClient(); | ||||||||||||||||||
|
|
||||||||||||||||||
| JavaPlugin getLibraryPlugin(); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Returns true if event has been published successfully. | ||||||||||||||||||
| */ | ||||||||||||||||||
| boolean publishEvent(@NonNull Event event); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Get entries by key, optionally filtered. | ||||||||||||||||||
| */ | ||||||||||||||||||
| @NotNull List<Entry> getEntry(@NonNull String key); | ||||||||||||||||||
|
Comment on lines
+26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation inconsistency with method signature The documentation mentions "optionally filtered" but the method signature doesn't include any filter parameters. Update the documentation to match the actual functionality: /**
- * Get entries by key, optionally filtered.
+ * Get entries by key.
*/📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Adds list of keys that should be subscribed. | ||||||||||||||||||
| */ | ||||||||||||||||||
| void addSubscriptions(@NonNull Collection<String> subscriptions); | ||||||||||||||||||
|
|
||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Removes list of keys that shouldn't be subscribed. | ||||||||||||||||||
| */ | ||||||||||||||||||
| void removeSubscriptions(@NonNull Collection<String> subscriptions); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Resets list of keys that should be subscribed completely. | ||||||||||||||||||
| * @apiNote Also resets all subscribed/unsubscribed keys | ||||||||||||||||||
| * which have been added by {@link Octopus#addSubscriptions} | ||||||||||||||||||
| * or removed by {@link Octopus#removeSubscriptions} | ||||||||||||||||||
| */ | ||||||||||||||||||
| @ApiStatus.Experimental | ||||||||||||||||||
| void setSubscriptions(@NonNull Collection<String> subscriptions); | ||||||||||||||||||
|
|
||||||||||||||||||
| /** | ||||||||||||||||||
| * Returns the identifier of this service (e.g. service-name) | ||||||||||||||||||
| */ | ||||||||||||||||||
| String getIdentifier(); | ||||||||||||||||||
|
|
||||||||||||||||||
| String getHost(); | ||||||||||||||||||
|
|
||||||||||||||||||
| int getPort(); | ||||||||||||||||||
| } | ||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,17 @@ | ||
| package studio.o7.octopus.plugin.api.client; | ||
|
|
||
| import studio.o7.octopus.sdk.gen.api.v1.EntryResponse; | ||
| import lombok.NonNull; | ||
| import studio.o7.octopus.sdk.gen.api.v1.Entry; | ||
| import studio.o7.octopus.sdk.gen.api.v1.Event; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.List; | ||
|
|
||
| public interface OctopusClient { | ||
|
|
||
| boolean emitEvent(Event event); | ||
| boolean publishEvent(@NonNull Event event); | ||
|
|
||
| EntryResponse getEntry(String key); | ||
| List<Entry> getEntry(@NonNull String key); | ||
|
|
||
| void initializeSubscription(List<String> subscriptions); | ||
|
|
||
| void updateSubscriptions(List<String> subscriptions); | ||
| void updateSubscriptions(@NonNull Collection<String> subscriptions); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,49 +1,90 @@ | ||||||||||||||||||||||||||||||||||||||||||
| package studio.o7.octopus.plugin; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import it.unimi.dsi.fastutil.objects.ObjectArraySet; | ||||||||||||||||||||||||||||||||||||||||||
| import lombok.NonNull; | ||||||||||||||||||||||||||||||||||||||||||
| import lombok.RequiredArgsConstructor; | ||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.plugin.Plugin; | ||||||||||||||||||||||||||||||||||||||||||
| import org.bukkit.plugin.java.JavaPlugin; | ||||||||||||||||||||||||||||||||||||||||||
| import org.jetbrains.annotations.NotNull; | ||||||||||||||||||||||||||||||||||||||||||
| import org.slf4j.Logger; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.plugin.api.Octopus; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.plugin.api.client.OctopusClient; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.plugin.client.OctopusClientImpl; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.sdk.OctopusSDK; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.Entry; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.EntryRequest; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.Event; | ||||||||||||||||||||||||||||||||||||||||||
| import studio.o7.octopus.sdk.gen.api.v1.OctopusServiceGrpc; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collection; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.Collections; | ||||||||||||||||||||||||||||||||||||||||||
| import java.util.List; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public final class OctopusImpl implements Octopus { | ||||||||||||||||||||||||||||||||||||||||||
| private final Plugin plugin; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private final OctopusServiceGrpc.OctopusServiceStub stub = OctopusSDK.stub(); | ||||||||||||||||||||||||||||||||||||||||||
| private final OctopusServiceGrpc.OctopusServiceBlockingStub blockingStub = OctopusSDK.blockingStub(); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private final Logger logger; | ||||||||||||||||||||||||||||||||||||||||||
| private final OctopusSubscriptions subscriptions; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private final OctopusClient client; | ||||||||||||||||||||||||||||||||||||||||||
| private final String identifier; | ||||||||||||||||||||||||||||||||||||||||||
| private final String host; | ||||||||||||||||||||||||||||||||||||||||||
| private final int port; | ||||||||||||||||||||||||||||||||||||||||||
| private String identifier; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| private final Collection<String> subscriptionList = Collections.synchronizedSet(new ObjectArraySet<>()); | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| public OctopusImpl(Plugin plugin) { | ||||||||||||||||||||||||||||||||||||||||||
| this.identifier = "test-minecraft-plugin"; | ||||||||||||||||||||||||||||||||||||||||||
| this.host = "127.0.0.1"; | ||||||||||||||||||||||||||||||||||||||||||
| this.port = 50051; | ||||||||||||||||||||||||||||||||||||||||||
| this.client = new OctopusClientImpl(host, port, plugin, identifier); | ||||||||||||||||||||||||||||||||||||||||||
| this.plugin = plugin; | ||||||||||||||||||||||||||||||||||||||||||
| logger = plugin.getSLF4JLogger(); | ||||||||||||||||||||||||||||||||||||||||||
| subscriptions = new OctopusSubscriptions(plugin, logger, stub); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull OctopusClient getClient() { | ||||||||||||||||||||||||||||||||||||||||||
| return client; | ||||||||||||||||||||||||||||||||||||||||||
| public boolean publishEvent(@NonNull Event event) { | ||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||
| var publishEventResponse = blockingStub.publishEvent(event); | ||||||||||||||||||||||||||||||||||||||||||
| logger.info("Published event on key {}", event.getKey()); | ||||||||||||||||||||||||||||||||||||||||||
| return publishEventResponse.getSuccess(); | ||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||
| logger.error("Failed to publish event on key {}", event.getKey(), e); | ||||||||||||||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull JavaPlugin getLibraryPlugin() { | ||||||||||||||||||||||||||||||||||||||||||
| return JavaPlugin.getPlugin(OctopusPlugin.class); | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull List<Entry> getEntry(@NonNull String key) { | ||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||
| return blockingStub.getEntry(EntryRequest.newBuilder().setKey(key).build()).getEntriesList(); | ||||||||||||||||||||||||||||||||||||||||||
| } catch (Exception e) { | ||||||||||||||||||||||||||||||||||||||||||
| logger.error("Failed to retrieve entry on key {}", key, e); | ||||||||||||||||||||||||||||||||||||||||||
| return Collections.emptyList(); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull String getIdentifier() { | ||||||||||||||||||||||||||||||||||||||||||
| return identifier; | ||||||||||||||||||||||||||||||||||||||||||
| public void addSubscriptions(@NonNull Collection<String> subscriptions) { | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptionList.addAll(subscriptions); | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptions.updateSubscriptions(subscriptionList); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull String getHost() { | ||||||||||||||||||||||||||||||||||||||||||
| return host; | ||||||||||||||||||||||||||||||||||||||||||
| public void removeSubscriptions(@NonNull Collection<String> subscriptions) { | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptionList.removeAll(subscriptions); | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptions.updateSubscriptions(subscriptionList); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public int getPort() { | ||||||||||||||||||||||||||||||||||||||||||
| return port; | ||||||||||||||||||||||||||||||||||||||||||
| public synchronized void setSubscriptions(@NonNull Collection<String> subscriptions) { | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptionList.clear(); | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptionList.addAll(subscriptions); | ||||||||||||||||||||||||||||||||||||||||||
| this.subscriptions.updateSubscriptions(subscriptionList); | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| @Override | ||||||||||||||||||||||||||||||||||||||||||
| public @NotNull String getIdentifier() { | ||||||||||||||||||||||||||||||||||||||||||
| if (this.identifier != null) return identifier; | ||||||||||||||||||||||||||||||||||||||||||
| identifier = System.getProperty("octopus.identifier"); | ||||||||||||||||||||||||||||||||||||||||||
| if (identifier == null || identifier.isEmpty()) | ||||||||||||||||||||||||||||||||||||||||||
| identifier = System.getenv("OCTOPUS_IDENTIFIER"); | ||||||||||||||||||||||||||||||||||||||||||
| if (identifier == null || identifier.isEmpty()) | ||||||||||||||||||||||||||||||||||||||||||
| identifier = "default"; | ||||||||||||||||||||||||||||||||||||||||||
| return identifier; | ||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+80
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add thread safety to lazy identifier initialization. The lazy initialization pattern is not thread-safe. Multiple threads could initialize the @Override
-public @NotNull String getIdentifier() {
+public synchronized @NotNull String getIdentifier() {
if (this.identifier != null) return identifier;
identifier = System.getProperty("octopus.identifier");
if (identifier == null || identifier.isEmpty())
identifier = System.getenv("OCTOPUS_IDENTIFIER");
if (identifier == null || identifier.isEmpty())
identifier = "default";
return identifier;
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Verify SDK version availability and breaking changes.
The SDK version jump from 0.0.2 to 0.1.2 corresponds to significant architectural changes. Please verify:
🏁 Script executed:
Length of output: 317
SDK 0.1.2 Verified on Maven Central; Release Notes Missing
Action items:
🤖 Prompt for AI Agents