spring-projects/spring-integration — pull request #1323 by artembilan (2014-11-14 15:51:58+00:00)
Title: INT-3560: Fix DelayHandler for double emitting

JIRA: https://jira.spring.io/browse/INT-3560

`AbstractApplicationContext` has the code:

````java
getLifecycleProcessor().onRefresh();

// Publish the final event.
publishEvent(new ContextRefreshedEvent(this));
````

So, some `Lifecycle`s (e.g. `InboundChannelAdapter`) can emit `Message` and send to the `DelayHandler` before the `ContextRefreshedEvent`.
In this case `DelayHandler` `delays` the `Message` and store it to the `MessageStore`.
When `ContextRefreshedEvent` is happened the `DelayHandler` reschedules all stored `Message` and our 'early' `Message` may be scheduled twice.

Fix an issue with an internal `Map> delayTasks` for each delayed `Message`.
Remove the `ScheduledFuture` for the `Message` on release.
`cancel(true)` and `clear` all `delayTasks` on the `reschedulePersistedMessages()`.

**Cherry-pick to 4.0.x & 3.0.x**