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

Use CodeGen for AOP Fallback #470

Merged
merged 12 commits into from
Jan 9, 2024
Merged

Use CodeGen for AOP Fallback #470

merged 12 commits into from
Jan 9, 2024

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Dec 9, 2023

The current way of using fallback methods is pretty obtuse, so this adds

  • Adds a new annotation to mark a method as a fallback for AOP.
  • will generate code to register a fallback method to an invocation
  • Adds new method to Invocation to invoke a registered fallback method
  • also will use method references in generated proxies if possible

Given stuff like this:

  @MyRetry
  public String retry2(String param0, int param1) {
    retryWithFallbackCounter++;
    throw new IllegalArgumentException("Retry2Fail[" + param0 + "," + param1 + "]");
  }

  @AOPFallback("retry2")
  public String fallbackRetry2(String param0, int param1, Throwable e) {
    return "fallbackRetry2-" + param0 + ":" + param1 + ":" + e.getMessage();
  }

this will get generated

  @Override
  public java.lang.String retry2(String param0, int param1) {
    var call = new Invocation.Call<>(() -> super.retry2(param0, param1))
      .with(this, retry20, param0, param1)
      .fallback(ex -> fallbackRetry2(param0, param1, ex));
    try {
      retry20MyRetry.invoke(call);
      return call.finalResult();
    } catch (RuntimeException ex) {
      ex.addSuppressed(new InvocationException("retry2 proxy threw exception"));
      throw ex;
    } catch (Throwable t) {
      throw new InvocationException("retry2 proxy threw exception", t);
    }
  }

@SentryMan
Copy link
Collaborator Author

SentryMan commented Dec 11, 2023

@rbygrave waiting for your thoughts before I start on the method signature validation

@rbygrave
Copy link
Contributor

rbygrave commented Dec 16, 2023

waiting for your thoughts before I start on the method signature validation

So yes I'm happy so far.

start on the method signature validation

I'm not sure specifically what you mean there. Maybe the new methods on Invocation?
edit: Oh, method signature validation ... ok, got it.

@SentryMan SentryMan marked this pull request as draft December 16, 2023 23:42
@SentryMan SentryMan marked this pull request as ready for review December 17, 2023 00:43
@SentryMan
Copy link
Collaborator Author

yeah, I'm good with this

@SentryMan SentryMan self-assigned this Dec 17, 2023
@SentryMan
Copy link
Collaborator Author

Feel free to change the names of method/class names

@SentryMan SentryMan added this to the 9.11 milestone Jan 8, 2024
@rbygrave
Copy link
Contributor

rbygrave commented Jan 9, 2024

change the names of method/class names

For myself, I feel the ideal name for @AOPFallback would be @Fallback but we can't do that at the moment as that is the name of the deprecated interface that will be removed at some stage.

This is a really nice improvement for doing fallback methods - way better than the existing approach.

@rbygrave rbygrave merged commit 79f6b15 into avaje:master Jan 9, 2024
4 checks passed
@SentryMan SentryMan deleted the fallback branch January 9, 2024 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants