Skip to content
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

[WIP] Add interfaces for refactoring work #1276

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Conversation

aaron-congo
Copy link
Contributor

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Copy link

github-actions bot commented Feb 5, 2025

Qodana Community for JVM

1 new problem were found

Inspection name Severity Problems
Unused assignment 🔶 Warning 1

💡 Qodana analysis was run in the pull request mode: only the changed files were checked

View the detailed Qodana report

To be able to view the detailed Qodana report, you can either:

  1. Register at Qodana Cloud and configure the action
  2. Use GitHub Code Scanning with Qodana
  3. Host Qodana report at GitHub Pages
  4. Inspect and use qodana.sarif.json (see the Qodana SARIF format for details)

To get *.log files or any other Qodana artifacts, run the action with upload-result option set to true,
so that the action will upload the files as the job artifacts:

      - name: 'Qodana Scan'
        uses: JetBrains/[email protected]
        with:
          upload-result: true
Contact Qodana team

Contact us at [email protected]


package software.amazon.jdbc.util.monitoring;

public enum MonitorState {
Copy link
Contributor

Choose a reason for hiding this comment

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

CREATED?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does that indicate a monitor that has been instantiated but never run? With the current design the monitor service doesn't provide a method to submit a monitor without running it, we just have the "runIfAbsent" method which would automatically create and run the monitor. So I'm not sure if we'd ever have a monitor in this state.

Copy link
Contributor

Choose a reason for hiding this comment

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

Theoretically it's possible to create an instance, add it to the list of monitors and let other threads to observe it. In this case the monitor is created but isn't yet started. Otherwise your code has to guarantee that such monitors won't be available for other observers.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently the API doesn't have a method that creates a monitor but does not run it. The only way to submit a monitor is to call the runIfAbsent method which will automatically start the monitor when it is created. If we discover we need a method that submits a monitor but does not start then yes we should add this state.


void stop();

MonitorStatus getStatus();
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an exception as part of MonitorStatus. Is it an unhandled exception that stops/breaks a monitor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my intention yes, it would be a reference to an exception that caused a monitor to unexpectedly stop.

Copy link
Contributor

Choose a reason for hiding this comment

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

That means it's a handled exception (since it's been caught and stored). That contradicts the original goal. It's possible that monitor isn't able to catch it so monitor service needs to handle them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I was thinking the monitor would use a try-catch for its entire run loop that would catch the generic Exception type (eg it would catch any unhandled exceptions) and then it would set its exception status. So the monitor itself would be responsible for indicating it has hit an unexpected error, and the monitor service's watcher thread would check the monitor's status to see if it has hit an error. Do we want to pursue a different approach?

* @param subscriber the subscriber to be notified when the given event classes occur.
* @param eventClasses the classes of event that the subscriber should be notified of.
*/
void subscribe(EventSubscriber subscriber, Class<?>... eventClasses);
Copy link
Contributor

Choose a reason for hiding this comment

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

Class<? extends Event>

Copy link
Contributor Author

@aaron-congo aaron-congo Feb 7, 2025

Choose a reason for hiding this comment

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

When I make this change I get the warning "Possible heap pollution from parameterized vararg type", so maybe I'll make this a Set<Class<? extends Event>> instead of a vararg

@sergiyvamz sergiyvamz added the wip Pull request that is a work in progress label Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wip Pull request that is a work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants