-
Notifications
You must be signed in to change notification settings - Fork 921
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
Provides a way for DecoratorFactory to be applied only once #5918
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before going into code review, I think it's better if some points are clarified cc. @ikhoon (the original issue creator)
- Can repeatable be set for decorators also? It seems odd that only DecoratorFunctions only are considered. I think we can probably use the same trick that was used for
order
to determine additivity of decorators added by factories.
e.g.
@RequiresPermission(Permission.WRITE)
static class SensitiveService {
@RequiresPermission(Permission.READ)
@Decorator(PermissionDecorator.class)
@Get("/")
public String get() { ... }
}
- Additivity originally turns off the cumulative behavior. Do we following this rule? or do we just apply the highest order decorator if any one of the decorators have
additivity=true
?
e.g. Assume that decorator1(order=0), decorator2(order=50, additivity = false), decorator3(order=100). Then only decorator1, decorator2 will be applied following the original cumulativity rule.
SGTM
Did you mean
A class decorator has a lower priority (order) than a method decorator. IIUC, if we follow the rule, isn't Initially, I intended to provide a way to apply the innermost decorator when the same decorators are applied repeatedly. |
I thought the order was determined by the order attribute value eventually Line 59 in 906617b
Perhaps I didn't understand the original intention of the repeatable field you proposed. So if |
I was talking about cases where the order is determined by the declared position of the decorator without explicitly declaring the Lines 54 to 56 in 906617b
I thought about collecting decorators starting from the highest priority (innermost decorator) to the lowest priority until finding |
To be clear, by priority do you mean order? I feel like it's more natural that the decorator application order also applies to additivity (or repeatable). Reversing this order feels counter-intuitive to me. I think I'm out of ideas at the moment. |
We have already introduced a simpler approach in armeria/core/src/main/java/com/linecorp/armeria/server/metric/MetricCollectingService.java Lines 123 to 124 in 906617b
So I didn't think it was odd. Anyway, I also need to think more about the direction and API design. |
I think there is a misunderstanding 😅 I'm not against ignoring the order of decorators as long as the change makes sense. It seems like @ikhoon already has a good idea on how to proceed with this PR, so let me review this later after the PR is more developed 🙏 |
I'm sorry, I misundertood the requirement of this issue🙏 But the requirement may be more complicated than I thought.
Thank you. Please let me know if they are fixed! |
Motivation:
Please refer to issue #5759
Modifications:
addtivity
flag toDecoratorFactory
which makes us possible to control that the annotation that has the highest priority to be only applied within annotations annotaed by thisDecoratorFactory
.Result:
DecoratorFactory
to be applied only once #5759additivity=false
, the decorator with a higher priority will only be selected and others are not applied. In the following example, focusing onget()
method,Permission READ
is only applied andPermission WRITE
is ignored.