INT-4528: Docs for SmartLifecycleRoleController
JIRA: https://jira.spring.io/browse/INT-4528
This commit is contained in:
committed by
Gary Russell
parent
262e624ef4
commit
8a7adb8cc4
@@ -664,6 +664,17 @@ See the http://docs.spring.io/spring-framework/docs/current/spring-framework-ref
|
||||
Starting with version 4.2, endpoints can be assigned to roles.
|
||||
Roles let endpoints be started and stopped as a group.
|
||||
This is particularly useful when using leadership election, where a set of endpoints can be started or stopped when leadership is granted or revoked, respectively.
|
||||
For this purpose the framework registers a `SmartLifecycleRoleController` bean in the application context with the name `IntegrationContextUtils.INTEGRATION_LIFECYCLE_ROLE_CONTROLLER`.
|
||||
Whenever it is necessary to control lifecycles, this bean can be injected or `@Autowired`:
|
||||
|
||||
====
|
||||
[source, xml]
|
||||
----
|
||||
<bean class="com.some.project.SomeLifecycleControl">
|
||||
<property name="roleController" ref="integrationLifecycleRoleController"/>
|
||||
</bean>
|
||||
----
|
||||
====
|
||||
|
||||
You can assign endpoints to roles using XML, Java configuration, or programmatically.
|
||||
The following example shows how to configure endpoint roles with XML:
|
||||
@@ -734,11 +745,9 @@ Invoking `roleController.startLifecyclesInRole("cluster")` and the corresponding
|
||||
|
||||
NOTE: Any object that implements `SmartLifecycle` can be programmatically added -- not just endpoints.
|
||||
|
||||
The `SmartLifecycleRoleController` implements `ApplicationListener<AbstractLeaderEvent>` and it automatically
|
||||
starts and stops its configured `SmartLifecycle` objects when leadership is granted or revoked (when some bean publishes
|
||||
`OnGrantedEvent` or `OnRevokedEvent`, respectively).
|
||||
The `SmartLifecycleRoleController` implements `ApplicationListener<AbstractLeaderEvent>` and it automatically starts and stops its configured `SmartLifecycle` objects when leadership is granted or revoked (when some bean publishes `OnGrantedEvent` or `OnRevokedEvent`, respectively).
|
||||
|
||||
IMPORTANT: When using leadership election to start and stop components, it is important to set the `auto-startup` XML attribute (`autoStartup` bean property) to `false` so taht the application context does not start the components during context initialization.
|
||||
IMPORTANT: When using leadership election to start and stop components, it is important to set the `auto-startup` XML attribute (`autoStartup` bean property) to `false` so that the application context does not start the components during context initialization.
|
||||
|
||||
Starting with version 4.3.8, the `SmartLifecycleRoleController` provides several status methods:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user