-
Notifications
You must be signed in to change notification settings - Fork 107
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
Implement activity helpers #353
base: master
Are you sure you want to change the base?
Conversation
As a developer I would like to be able to define or even implements commons methods (default methods) that could be extended by an activity method interface. This methods, should not be consider as an activity method. This feature will gives an upper level of abstraction allowing commons behavior between activity methods. In order to support this feature, an annotation named 'ActivityHelper' was developed. You must add this annotation to all those interfaces that gives some kind of support or gives an upper level of abstraction to an activity method interface.
pjgg seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Sorry for the late reply, missed notification about the new PR. |
I have an alternative proposal. Treat all base interfaces as non activity interfaces. Only the interfaces that an activity implementation directly implements are used to define activities. Example:
The resulting activities registered with the worker: |
Thank you for your response @mfateev The main problem that we have is not the hierarchy between interfaces. The problem is that this class So, If you have a look at the unit test that we have implemented https://github.com/uber/cadence-java-client/pull/353/files#diff-95c5d7ffe18c3ca1e1816a77893fc38cR155 You will see that is pretty much the same as your example:
If you remove the annotation
In order to avoid this behavior and allow the developer to have interfaces with methods (not activity methods) that could be extended by an interface that implements an activity method we have created an annotation: https://github.com/uber/cadence-java-client/pull/353/files#diff-afc5b685d6cf32cbbdc56ae28d92888cR34 So all the interfaces that are annotated with this annotation will be ignored by https://github.com/uber/cadence-java-client/pull/353/files#diff-c0d35c261ac27624c0c8ea09a069a4f3R101 |
I see. How do you expect the activity stub to behave in this case?
In the workflow code:
Should |
This example works, but this one doesn't
You can test it running the following UnitTest:
Because in the same worker, you have two activities with the same default name "A::foo" |
I believe my initial proposal here (#353 (comment)) solves the issue in the last example. |
You need to have the same method name in all the interfaces in order to reproduce this issue. You could have a look the unit test that comes with this PR, or on the comments. |
Sorry, I'm still confused. Could you explain why exactly my proposal doesn't solve your problem? |
Because your proposal doesn't overwrite any method (is not the same scenario). Please try this scenario in order to understand the issue. You will notice that cadence complain about 'foo' activity because is already registered. interface A { interface B extends A { interface C extends A { class BImpl implements B { class CImpl implements C { worker.registerActivityImpl(new BImpl(), new CIml()); To avoid this weird behavior, we've created a new annotation '@ActivityHelper'. This PR talks about this scenario. |
Sorry, but my proposal solves your issue. It will register B::foo and C::foo, but is not going to register A::foo. What do I miss? |
Let me try to drive you, and see if together we can understand what is happening: Imagine that you have the following activity hierarchy
And the following workflow (doesn't really care)
When we try to run this workflow, by the following unit test:
We are getting the following exception:
Please copy this test, and run it by your self. Then you can debug cadence-java-client and pay attention to
Because B and C activity has the same parent, and cadence will register this parent twice (when it should not been registered). The solution that we thought was a new annotation called "activityHelper" in order to make cadence know, that this interface "A" should be not considered as an interface that holds activity methods. You can also test this approach running the unitTest that comes with this PR. |
Here is my proposal (not yet implemented) that I put at the beginning of this thread: Treat all base interfaces as non activity interfaces. Only the interfaces that an activity implementation directly implements are used to define activities. Example:
The resulting activities registered with the worker: Could you explain why exactly it is not solving your problem? The issue with your proposal is the following: How do you expect the activity stub to behave in this case?
In the workflow code:
Should |
Because you are not in the same Scenario that I told you. You only will be able to reproduce the issue if all the interfaces extend the same method name. ` interface B extends A { interface C extends A { class BImpl implements B { class CImpl implements C { worker.registerActivityImpl(new BImpl(), new CIml()); I have tested all the examples that I gave you. And you can reproduce the issue with the unit test that comes with this PR. You will get the following exception: java.lang.IllegalStateException: A::foo activity type is already registered with the worker Because as I told you:
You will find the problem in this class: POJOActivityTaskHandler.java -> addActivityImplementation Look I am not going to continue with this issue. If you want to investigate it's up to you. Thank you anyway!. |
As a developer I would like to be able to define or even implements
commons methods (default methods) that could be extended by an
activity method interface. This methods, should not be consider as an
activity method.
This feature will gives an upper level of abstraction allowing commons
behavior between activity methods.
In order to support this feature, an annotation named 'ActivityHelper'
was developed. You must add this annotation to all those interfaces that
gives some kind of support or gives an upper level of abstraction to an
activity method interface.