Resiliency
The Platform and API provide Resiliency services which can be optionally used.
For the platform-level view, see Resilience.
Application Groups
To use platform-managed leadership, create an Application Group in Key Access and assign one or more applications to it. The Application Management guide covers creating groups and assigning resources to a group.
Applications in the same group receive a leadership state. The first online application in the group is PRIMARY, the next is SECONDARY, and any additional online applications are TERTIARY.
When the current primary stops or times out, Key Access promotes the remaining online applications and the API reports the new leadership state. An application that is not part of a group is treated as PRIMARY while it is online.
| Leadership State | Typical Use |
|---|---|
PRIMARY | Active instance. e.g. owns publishing or other single-owner work. |
SECONDARY | A specifically named standby instance, useful when you want a single non-primary instance to perform work that not all non-primary instances should perform. |
TERTIARY | Standby instance. Allocated to all instances after PRIMARY and SECONDARY have been allocated. |
UNKNOWN | Leadership is not known, usually because the application is not online. |
Leadership is driven by liveness. The API publishes heartbeats automatically, Key Access uses heartbeats to decide when an application is no longer live and should be marked offline.
Reading Leadership
The current leadership state is available from KeySession as follows:
LeadershipState leadershipState = session.getLeadershipState();
// convenience method to check if primary
if (session.isPrimary()) {
// .. do some primary work
}
// convenience method to check if secondary
if (session.isSecondary()) {
// .. do some secondary work
}
Use this when an application needs to gate work based on its current role. For TERTIARY, use getLeadershipState().
See JavaDoc for more details on KeySession.
Leadership Changes
KeySessionListener receives a callback whenever the session leadership state changes.
KeySessionListener listener = new KeySessionListener() {
@Override
public void leadershipChanged(LeadershipState leadershipState) {
// check leadershipState
}
};
See JavaDoc for more details on KeySessionListener.