Move LeaderInitiators to later phase

There is a race condition when Zookeeper `LeaderInitiator` may start
earlier than `CuratorFramework` it depends on.
This is because both of them are configured for the same default `phase` (`0`)

* Make `LeaderInitiator` and `LockRegistryLeaderInitiator` to be started
in the `Integer.MAX_VALUE - 1000` phase by default - as late as possible
* Make `CuratorFrameworkFactoryBean` to start in the `Integer.MIN_VALUE + 1000`
phase - as early as possible
* Alight lifecycle properties from the `LeaderInitiatorFactoryBean` with
defaults in the `LeaderInitiator`
* Simplify a `LeaderListenerParser` to rely on the `LeaderInitiatorFactoryBean`

**Cherry-pick to 5.0.x**
This commit is contained in:
Artem Bilan
2018-08-15 16:04:05 -04:00
committed by Gary Russell
parent ed07777b4e
commit 15eae700a3
5 changed files with 30 additions and 36 deletions

View File

@@ -151,7 +151,7 @@ public class LockRegistryLeaderInitiator implements SmartLifecycle, DisposableBe
/**
* @see SmartLifecycle which is an extension of org.springframework.context.Phased
*/
private int phase;
private int phase = Integer.MAX_VALUE - 1000;
/**
* Flag that indicates whether the leadership election for this {@link #candidate} is