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

fix: remove thread local based wiring #1817

Merged
merged 4 commits into from
Oct 26, 2023

Conversation

octonato
Copy link
Member

@octonato octonato commented Oct 21, 2023

Fix #1812

@github-actions github-actions bot added java-sdk kalix-runtime Runtime and SDKs sub-team labels Oct 21, 2023
@octonato octonato force-pushed the octonato/fix-component-client-wiring branch from da2d9f5 to 57513f1 Compare October 25, 2023 12:36
@octonato octonato marked this pull request as ready for review October 25, 2023 13:18
Comment on lines +22 to +23
@Component
public class IllDefinedWorkflow extends Workflow<String> {
Copy link
Member Author

Choose a reason for hiding this comment

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

This class and the one below are not related to the fix, but we were missing this test for Worklows

// NOTE: if they are allowed, 'partial' should already have a matching case for them
case p if p == classOf[KalixClient] =>
new BeanCreationException(
s"KalixClient cannot be inject into a [${constructor.getDeclaringClass.getSimpleName}]")
Copy link
Contributor

Choose a reason for hiding this comment

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

It should just create and return the exception, not throw it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh god! I don't know how to code anymore.

// block wiring of clients into anything that is not an Action or Workflow
// NOTE: if they are allowed, 'partial' should already have a matching case for them
case p if p == classOf[KalixClient] =>
throw new BeanCreationException(
Copy link
Member Author

Choose a reason for hiding this comment

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

Look @johanandren, now throwing for real.

// NOTE: if they are allowed, 'partial' should already have a matching case for them
case p if p == classOf[KalixClient] =>
throw new BeanCreationException(
s"[${constructor.getDeclaringClass.getSimpleName}] are not allowed to have a dependency on KalixClient")
Copy link
Member Author

Choose a reason for hiding this comment

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

I re-phrased the text here because I was using the article 'a' in previous commit. It would be wrong for EventSourcedEntity.

Comment on lines +349 to +351
if (bean == null)
throw new BeanCreationException(
s"Cannot wire [${anyOther.getSimpleName}]. Bean not found in the Application Context");
Copy link
Member Author

Choose a reason for hiding this comment

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

I also remove the check on wiring wrong context.

This more generic check will cover all wrong contexts, but also cases in which the user didn't properly define their own bean.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can go one extra mile and provide specific error messages when a user tries to inject a ActionContext into an EventSourcedEntity, for example.

But maybe that's something we should do using our Validation frameworky.

@octonato octonato merged commit 102f95c into main Oct 26, 2023
65 checks passed
@octonato octonato deleted the octonato/fix-component-client-wiring branch October 26, 2023 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
java-sdk kalix-runtime Runtime and SDKs sub-team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to wire ComponentClient
2 participants