[
https://issues.apache.org/jira/browse/CAMEL-6840?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16517811#comment-16517811
]
ASF GitHub Bot commented on CAMEL-6840:
---------------------------------------
onderson commented on a change in pull request #2376: CAMEL-6840 - add grouped
throttling feature, both XML and Java DSL should be fine now.
URL: https://github.com/apache/camel/pull/2376#discussion_r196652156
##########
File path: camel-core/src/main/java/org/apache/camel/processor/Throttler.java
##########
@@ -235,63 +283,122 @@ protected void enqueuePermit(final ThrottlePermit
permit, final Exchange exchang
/**
* Evaluates the maxRequestsPerPeriodExpression and adjusts the throttle
rate up or down.
*/
- protected void calculateAndSetMaxRequestsPerPeriod(final Exchange
exchange) throws Exception {
+ protected void
calculateAndSetMaxRequestsPerPeriod(DelayQueue<ThrottlePermit> delayQueue,
final Exchange exchange, final Integer key) throws Exception {
Integer newThrottle =
maxRequestsPerPeriodExpression.evaluate(exchange, Integer.class);
if (newThrottle != null && newThrottle < 0) {
throw new IllegalStateException("The maximumRequestsPerPeriod must
be a positive number, was: " + newThrottle);
}
- synchronized (this) {
- if (newThrottle == null && throttleRate == 0) {
+ Object lockOnSync = null;
+ Integer currentThrottleRate = throttleRate;
+ if (correlationExpression != null) {
+ currentThrottleRate = throttleRatesMap.get(key);
+ lockOnSync = new Integer(currentThrottleRate.intValue());
Review comment:
I got that but that was the point of @aldettinger's first suggestion to make
a defensive copy due to not being sure of the reference returned by evaluate
could be used as a lock by another thread for another purpose or not. I think
that led me to think like that. I think the correct way of managing
synchronised block will be like this
1- If no grouping applied, throttler itself should be used as lock
because all threads will be accessing volatile throttleRate and modify it.
2- If grouping applied, not the value from throttleRates map should be
used as lock but the key would be a better choice.
that was what i already mentioned but reflected in an unintended way to
implementation.
https://github.com/apache/camel/pull/2376#discussion_r195896140
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
> Allow Throttler EIP to specify SLA per client/correlated-group
> --------------------------------------------------------------
>
> Key: CAMEL-6840
> URL: https://issues.apache.org/jira/browse/CAMEL-6840
> Project: Camel
> Issue Type: New Feature
> Components: camel-core, eip
> Reporter: Christian Posta
> Assignee: Önder Sezgin
> Priority: Major
> Fix For: 2.22.0
>
>
> Basic idea is to allow throttler to have a predicate to determine whether or
> not to apply throttling to that exchange.
> From this Mailing List discussion:
> http://camel.465427.n5.nabble.com/Throttling-by-client-ID-td5741032.html
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)