[ 
https://issues.apache.org/activemq/browse/SM-1937?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=57977#action_57977
 ] 

Freeman Fang commented on SM-1937:
----------------------------------

Hi Alexander,

Good catch, just slightly modify your patch like
{code}
protected void throttle() {
        if (component.isExchangeThrottling()) {
            if (component.getThrottlingInterval() <= intervalCount) {
                intervalCount = -1;
                try {
                    long timeout = component.getThrottlingTimeout();
                    LOG.debug("throttling, sleep for: " + timeout);
                    Thread.sleep(timeout);
                } catch (InterruptedException e) {
                    LOG.warn("throttling failed", e);
                }
            }
            intervalCount++;
        }

    }
{code}

so that  keep interval same between the first time throttle and the successor 
throttle.
Also I add check for the Role and Status for MessageExchange, ensure the 
throttle only happen when send inital messageexchange(me) from 
consumer to provider, so avoid throttling counter++ for response me and Done me.

Also I add testcase to verify it works.

http://svn.apache.org/viewvc?rev=918354&view=rev

Thanks
Freeman

> Incorrect logic in throttle method of DeliveryChannelImpl.java 
> ---------------------------------------------------------------
>
>                 Key: SM-1937
>                 URL: https://issues.apache.org/activemq/browse/SM-1937
>             Project: ServiceMix
>          Issue Type: Improvement
>          Components: servicemix-core
>    Affects Versions: 3.3.1
>            Reporter: Alexander Zobkov
>            Assignee: Freeman Fang
>            Priority: Minor
>             Fix For: 3.3.2
>
>
> It seems something wrong with logic of the following method in 
> DeliveryChannelImpl.java  file:
> {code}
>     protected void throttle() {
>         if (component.isExchangeThrottling()) {
>             if (component.getThrottlingInterval() > intervalCount) {
>                 intervalCount = 0;
>                 try {
>                     Thread.sleep(component.getThrottlingTimeout());
>                 } catch (InterruptedException e) {
>                     LOG.warn("throttling failed", e);
>                 }
>             }
>             intervalCount++;
>         }
>     }
> {code}
> if user specifies positive values (default value is 1) of throttlingInterval 
> then "if" statement is always true.  So user need to specify negative values 
> of throttlingInterval in order to not force thread sleep on each doSend 
> method. Also it would be good to add a little bit logging here. So I propose 
> the following modification:
> {code}
>     protected void throttle() {
>         if (component.isExchangeThrottling()) {
>             if (component.getThrottlingInterval() < intervalCount) {
>                 intervalCount = 0;
>                 try {
>                     long timeout = component.getThrottlingTimeout()
>                     LOG.debug("throttling, sleep for: "+timeout);
>                     Thread.sleep(timeout);
>                 } catch (InterruptedException e) {
>                     LOG.warn("throttling failed", e);
>                 }
>             }
>             intervalCount++;
>         }
>     }
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to