/*
 * Copyright 2012-2020 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.boot.availability;

import org.springframework.context.ApplicationContext;

Provides availability state information for the application.

Components can inject this class to get the current state information. To update the state of the application an AvailabilityChangeEvent should be published to the application context with directly or via AvailabilityChangeEvent.publish.

Author:Brian Clozel, Phillip Webb
Since:2.3.0
/** * Provides {@link AvailabilityState availability state} information for the application. * <p> * Components can inject this class to get the current state information. To update the * state of the application an {@link AvailabilityChangeEvent} should be * {@link ApplicationContext#publishEvent published} to the application context with * directly or via {@link AvailabilityChangeEvent#publish}. * * @author Brian Clozel * @author Phillip Webb * @since 2.3.0 */
public interface ApplicationAvailability {
Return the LivenessState of the application.
Returns:the liveness state
/** * Return the {@link LivenessState} of the application. * @return the liveness state */
default LivenessState getLivenessState() { return getState(LivenessState.class, LivenessState.BROKEN); }
Return the ReadinessState of the application.
Returns:the readiness state
/** * Return the {@link ReadinessState} of the application. * @return the readiness state */
default ReadinessState getReadinessState() { return getState(ReadinessState.class, ReadinessState.REFUSING_TRAFFIC); }
Return AvailabilityState information for the application.
Params:
  • stateType – the state type
  • defaultState – the default state to return if no event of the given type has been published yet (must not be null.
Type parameters:
  • <S> – the state type
See Also:
Returns:the readiness state
/** * Return {@link AvailabilityState} information for the application. * @param <S> the state type * @param stateType the state type * @param defaultState the default state to return if no event of the given type has * been published yet (must not be {@code null}. * @return the readiness state * @see #getState(Class) */
<S extends AvailabilityState> S getState(Class<S> stateType, S defaultState);
Return AvailabilityState information for the application.
Params:
  • stateType – the state type
Type parameters:
  • <S> – the state type
See Also:
Returns:the readiness state or null if no event of the given type has been published yet
/** * Return {@link AvailabilityState} information for the application. * @param <S> the state type * @param stateType the state type * @return the readiness state or {@code null} if no event of the given type has been * published yet * @see #getState(Class, AvailabilityState) */
<S extends AvailabilityState> S getState(Class<S> stateType);
Return the last AvailabilityChangeEvent received for a given state type.
Params:
  • stateType – the state type
Type parameters:
  • <S> – the state type
Returns:the readiness state or null if no event of the given type has been published yet
/** * Return the last {@link AvailabilityChangeEvent} received for a given state type. * @param <S> the state type * @param stateType the state type * @return the readiness state or {@code null} if no event of the given type has been * published yet */
<S extends AvailabilityState> AvailabilityChangeEvent<S> getLastChangeEvent(Class<S> stateType); }