All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.crac.CracConfigurationProperties Maven / Gradle / Ivy

Go to download

Adds support for CRaC (Coordinated Restore at Checkpoint) to the Micronaut Framework.

The newest version!
/*
 * Copyright 2017-2022 original 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 io.micronaut.crac;

import io.micronaut.context.annotation.ConfigurationProperties;
import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.annotation.NonNull;

import java.time.Duration;

/**
 * Configuration for CRaC support. Enabled by default.
 *
 * @author Tim Yates
 * @since 1.0.0
 */
@Experimental
@ConfigurationProperties(CracConfigurationProperties.PREFIX)
public class CracConfigurationProperties implements CracConfiguration {

    /**
     * The prefix to use for CRaC configuration.
     */
    public static final String PREFIX = "crac";

    /**
     * The default enable value.
     */
    @SuppressWarnings("WeakerAccess")
    public static final boolean DEFAULT_ENABLED = true;
    public static final boolean DEFAULT_REFRESH = true;
    public static final String DEFAULT_DATASOURCE_PAUSE_TIMEOUT = "PT30S";

    private boolean enabled = DEFAULT_ENABLED;
    private boolean refreshBeans = DEFAULT_REFRESH;
    private Duration datasourcePauseTimeout = Duration.parse(DEFAULT_DATASOURCE_PAUSE_TIMEOUT);

    /**
     * @return Whether CRaC is enabled.
     */
    @Override
    public boolean isEnabled() {
        return enabled;
    }

    /**
     * Whether CRaC (Coordinated Restore at Checkpoint) support, even if we're on a supporting JDK, is enabled. Default value ({@value #DEFAULT_ENABLED}).
     *
     * @param enabled override CRaC if required
     */
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    /**
     * @return Whether to refresh beans prior to taking a checkpoint.
     */
    public boolean isRefreshBeans() {
        return refreshBeans;
    }

    /**
     * Whether to trigger a refresh event to refresh all {@code Refreshable} beans prior to taking a checkpoint. Default value ({@value #DEFAULT_REFRESH}).
     *
     * @param refreshBeans Whether to trigger a refresh event prior to taking a checkpoint.
     * @see Documentation for Refreshable scope
     */
    public void setRefreshBeans(boolean refreshBeans) {
        this.refreshBeans = refreshBeans;
    }

    @Override
    @NonNull
    public Duration getDatasourcePauseTimeout() {
        return datasourcePauseTimeout;
    }

    /**
     * The timeout to wait for a datasource to pause before taking a checkpoint. Default value ({@value #DEFAULT_DATASOURCE_PAUSE_TIMEOUT}).
     *
     * @param datasourcePauseTimeout The timeout to wait for a datasource to pause before taking a checkpoint.
     */
    public void setDatasourcePauseTimeout(Duration datasourcePauseTimeout) {
        this.datasourcePauseTimeout = datasourcePauseTimeout;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy