INT-4357: LeaderInit: Add failed to lock event
JIRA: https://jira.spring.io/browse/INT-4357 Updated based on code review. Updated adocs *Polishing code style, typos * Add protection from NPE when `LockRegistryLeaderInitiator` isn't supplied with the `leaderEventPublisher` * Add `What's New` note
This commit is contained in:
committed by
Artem Bilan
parent
a7eebed252
commit
1979f91cf5
@@ -695,12 +695,14 @@ This is useful in clustered scenarios where shared resources must only be consum
|
||||
An example of this is a file inbound channel adapter that is polling a shared directory.
|
||||
(See <<file-reading>>).
|
||||
|
||||
To participate in a leader election and be notified when elected leader or when leadership is revoked, an application creates a component in the application context called a "leader initiator".
|
||||
To participate in a leader election and be notified when elected leader, when leadership is revoked or, failure to acquire the resources to become leader, an application creates a component in the application context called a "leader initiator".
|
||||
Normally a leader initiator is a `SmartLifecycle` so it starts up (optionally) automatically when the context starts, and then publishes notifications when leadership changes.
|
||||
Users can also receive failure notifications by setting the `publishFailedEvents` to `true` (starting with _version 5.0_), in cases when they want take a specific action if a failure occurs.
|
||||
By convention the user provides a `Candidate` that receives the callbacks and also can revoke the leadership through a `Context` object provided by the framework.
|
||||
User code can also listen for `AbstractLeaderEvents`, and respond accordingly, for instance using a `SmartLifecycleRoleController`.
|
||||
User code can also listen for `org.springframework.integration.leader.event.AbstractLeaderEvent` s, and respond accordingly, for instance using a `SmartLifecycleRoleController`.
|
||||
|
||||
There is a basic implementation of a leader initiator based on the `LockRegistry` abstraction. To use it you just need to create an instance as a bean, for example:
|
||||
There is a basic implementation of a leader initiator based on the `LockRegistry` abstraction.
|
||||
To use it you just need to create an instance as a bean, for example:
|
||||
|
||||
[source, java]
|
||||
----
|
||||
@@ -710,6 +712,8 @@ public LockRegistryLeaderInitiator leaderInitiator(LockRegistry locks) {
|
||||
}
|
||||
----
|
||||
|
||||
If the lock registry is implemented correctly, there will only ever be at most one leader. If the lock registry also provides locks which throw exceptions (ideally `InterruptedException`) when they expire or are broken, then the duration of the leaderless periods can be as short as is allowed by the inherent latency in the lock implementation. By default there is a `busyWaitMillis` property that adds some additional latency to prevent CPU starvation in the (more usual) case that the locks are imperfect and you only know they expired by trying to obtain one again.
|
||||
If the lock registry is implemented correctly, there will only ever be at most one leader.
|
||||
If the lock registry also provides locks which throw exceptions (ideally `InterruptedException`) when they expire or are broken, then the duration of the leaderless periods can be as short as is allowed by the inherent latency in the lock implementation.
|
||||
By default there is a `busyWaitMillis` property that adds some additional latency to prevent CPU starvation in the (more usual) case that the locks are imperfect and you only know they expired by trying to obtain one again.
|
||||
|
||||
See <<zk-leadership>> for more information about leadership election and events using Zookeeper.
|
||||
|
||||
@@ -99,6 +99,10 @@ The `@GlobalChannelInterceptor` annotation and `<int:channel-interceptor>` now s
|
||||
|
||||
See <<global-channel-configuration-interceptors>> for more information.
|
||||
|
||||
A new `OnFailedToAcquireMutexEvent` is emitted now via `DefaultLeaderEventPublisher` by the `LockRegistryLeaderInitiator`, when candidate is failed to acquire the lock.
|
||||
|
||||
See <<leadership-event-handling>> for more information.
|
||||
|
||||
==== Gateway Changes
|
||||
|
||||
The gateway now correctly sets the `errorChannel` header when the gateway method has a `void` return type and an error channel is provided.
|
||||
|
||||
Reference in New Issue
Block a user