What steps will reproduce the problem?
currentEvent = (MessageEvent) queue.waitFor(Arrays.asList(MessageEvent.class),
10000, TimeUnit.MILLISECONDS);
What is the expected output? What do you see instead?
The above code will not honor the timeout setting of 10 seconds, instead it
keeps waiting.
What version of the product are you using? On what operating system?
Version 2.0.1 on OS X.
Please provide any additional information below.
The LinkedBlockingQueue returns null if the specified waiting time elapses
before an element is available. As a result, the foreach loop is empty and
therefore the function does not return and simply polls again with the same
timeout setting.
It can be fixed as following:
public Event waitFor(@NonNull List<Class<? extends Event>> eventClasses, long timeout, @NonNull TimeUnit unit) throws InterruptedException {
while (true) {
Event curEvent = eventQueue.poll(timeout, unit);
if (curEvent == null)
return curEvent;
for (Class<? extends Event> curEventClass : eventClasses)
if (curEventClass.isInstance(curEvent))
return curEvent;
}
}
Original issue reported on code.google.com by Arnold.O...@gmail.com on 29 Sep 2014 at 6:38
Original issue reported on code.google.com by
Arnold.O...@gmail.com
on 29 Sep 2014 at 6:38