Qian LIN created S4-134:
---------------------------
Summary: Wrong way of using TimeUnit conversion in setTrigger()
Key: S4-134
URL: https://issues.apache.org/jira/browse/S4-134
Project: Apache S4
Issue Type: Bug
Affects Versions: 0.5.0, 0.6, generic
Environment: CentOS 5.8 x86_64
Reporter: Qian LIN
[File]
ProcessingElement.java
[Function]
public ProcessingElement setTrigger(Class<? extends Event> eventType, int
numEvents, long interval, TimeUnit timeUnit)
[Description]
Before instantiating the trigger, the function checks the TimeUnit and does
conversion, if necessary, since S4 uniformly uses millisecond to configure
timers internally. See the code below:
if (timeUnit != null && timeUnit != TimeUnit.MILLISECONDS) {
interval = timeUnit.convert(interval, TimeUnit.MILLISECONDS);
}
The purpose of this code is to do conversion if the TimeUnit is not
MILLISECONDS. However, using the method of convert() is incorrect here. See the
Java API doc for reference.
[Impact]
Using TimeUnit other than MILLISECONDS (e.g., SECONDS) to call setTrigger()
will get unexpected timeout interval.
[Fix]
The right code should be as follows:
if (timeUnit != null && timeUnit != TimeUnit.MILLISECONDS) {
interval = TimeUnit.MILLISECONDS.convert(interval, timeUnit);
}
Or, more concisely,
if (timeUnit != null && timeUnit != TimeUnit.MILLISECONDS) {
interval = timeUnit.toMillis(interval);
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira