Skip to content

Added support for running callbacks after registration, ping and deregistration#27

Merged
orpiske merged 1 commit intowanaku-ai:mainfrom
orpiske:ci-issue-637-add-data-store
Nov 20, 2025
Merged

Added support for running callbacks after registration, ping and deregistration#27
orpiske merged 1 commit intowanaku-ai:mainfrom
orpiske:ci-issue-637-add-data-store

Conversation

@orpiske
Copy link
Copy Markdown
Contributor

@orpiske orpiske commented Nov 7, 2025

Ref: wanaku-ai/wanaku#637

Summary by Sourcery

Enable extensible post-event handling in ZeroDepRegistrationManager by adding a callback registry, exposing an addCallBack method, and providing a default log callback implementation

New Features:

  • Introduce a callback mechanism to invoke hooks after registration, ping, and deregistration events
  • Add an addCallBack method to allow external registration of custom callbacks
  • Include a default RegistrationLogCallback for logging registration, ping, and deregistration outcomes

Enhancements:

  • Refactor ZeroDepRegistrationManager to invoke callbacks instead of inline logging
  • Encapsulate logging logic in a standalone RegistrationLogCallback implementation

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai bot commented Nov 7, 2025

Reviewer's Guide

This PR refactors the ZeroDepRegistrationManager to support callback hooks for registration lifecycle events by introducing a callback registry, replacing inline logging with callback invocations, and providing a default logging callback implementation.

Sequence diagram for registration event with callback invocation

sequenceDiagram
    participant Manager as ZeroDepRegistrationManager
    participant Callback as RegistrationCallback
    participant Target as ServiceTarget
    Manager->>Target: Attempt registration
    Manager->>Callback: onRegistration(manager, target)
Loading

Sequence diagram for ping event with callback invocation

sequenceDiagram
    participant Manager as ZeroDepRegistrationManager
    participant Callback as RegistrationCallback
    participant Target as ServiceTarget
    Manager->>Target: Ping router
    Manager->>Callback: onPing(manager, target, status)
Loading

Sequence diagram for deregistration event with callback invocation

sequenceDiagram
    participant Manager as ZeroDepRegistrationManager
    participant Callback as RegistrationCallback
    participant Target as ServiceTarget
    Manager->>Target: Deregister service
    Manager->>Callback: onDeregistration(manager, target, status)
Loading

Class diagram for updated registration lifecycle with callbacks

classDiagram
    class ZeroDepRegistrationManager {
        -boolean registered
        -ScheduledExecutorService scheduler
        -ScheduledFuture registrationTask
        -List~RegistrationCallback~ callbacks
        +ZeroDepRegistrationManager(DiscoveryServiceHttpClient, ServiceTarget, InstanceDataManager)
        +addCallBack(RegistrationCallback)
        -runCallBack(Consumer~RegistrationCallback~)
    }
    class RegistrationCallback {
        <<interface>>
        +onPing(RegistrationManager, ServiceTarget, int)
        +onRegistration(RegistrationManager, ServiceTarget)
        +onDeregistration(RegistrationManager, ServiceTarget, int)
    }
    class RegistrationLogCallback {
        +onPing(RegistrationManager, ServiceTarget, int)
        +onRegistration(RegistrationManager, ServiceTarget)
        +onDeregistration(RegistrationManager, ServiceTarget, int)
    }
    ZeroDepRegistrationManager --> "*" RegistrationCallback : uses
    RegistrationLogCallback ..|> RegistrationCallback : implements
Loading

File-Level Changes

Change Details Files
Added callback registry and management in ZeroDepRegistrationManager
  • Declared a CopyOnWriteArrayList field to hold RegistrationCallback instances
  • Initialized callbacks list and added default RegistrationLogCallback in the constructor
  • Implemented addCallBack() to allow external registration of callbacks
  • Created runCallBack() helper to invoke each callback safely with exception handling
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/ZeroDepRegistrationManager.java
Replaced direct logs with callback invocations for lifecycle events
  • Replaced LOG.debug on successful registration with runCallBack invoking onRegistration
  • Replaced status-code checks and LOG.warn/LOG.trace in ping() with runCallBack invoking onPing
  • Replaced deregistration status handling logs with runCallBack invoking onDeregistration
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/ZeroDepRegistrationManager.java
Introduced RegistrationLogCallback for default lifecycle event logging
  • Added RegistrationLogCallback implementing RegistrationCallback interface
  • Logged registration success, ping results, and deregistration warnings in callback methods
capabilities-discovery/src/main/java/ai/wanaku/capabilities/sdk/discovery/RegistrationLogCallback.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • There’s an extra '}' in the non-debug branch of runCallBack’s LOG.warn format string, which will break the placeholder—please correct the formatting.
  • Method names runCallBack and addCallBack don’t follow consistent camelCase conventions; consider renaming them to runCallback and addCallback for clarity.
  • Automatically registering a default RegistrationLogCallback in the constructor may not be desired for all clients—consider making it injectable or optional to give users control over logging.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- There’s an extra '}' in the non-debug branch of runCallBack’s LOG.warn format string, which will break the placeholder—please correct the formatting.
- Method names runCallBack and addCallBack don’t follow consistent camelCase conventions; consider renaming them to runCallback and addCallback for clarity.
- Automatically registering a default RegistrationLogCallback in the constructor may not be desired for all clients—consider making it injectable or optional to give users control over logging.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Added support for running callbacks after registration, ping and deregistration

Ref: wanaku-ai/wanaku#637
@orpiske orpiske force-pushed the ci-issue-637-add-data-store branch from 2bd9990 to 77d87f5 Compare November 20, 2025 16:05
@orpiske orpiske merged commit 7d46cdb into wanaku-ai:main Nov 20, 2025
5 checks passed
@orpiske orpiske deleted the ci-issue-637-add-data-store branch November 20, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant