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

io.ceresdb.rpc.signal.RpcLimitSignalHandler Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
/*
 * Copyright 2023 CeresDB Project Authors. Licensed under Apache-2.0.
 */
package io.ceresdb.rpc.signal;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.ceresdb.common.SPI;
import io.ceresdb.common.signal.FileSignal;
import io.ceresdb.common.signal.FileSignals;
import io.ceresdb.common.signal.SignalHandler;
import io.ceresdb.rpc.interceptors.ClientRequestLimitInterceptor;

/**
 * A signal handler that can reset LIMIT_SWITCH by {@link ClientRequestLimitInterceptor#resetLimitSwitch()}.
 *
 */
@SPI(priority = 89)
public class RpcLimitSignalHandler implements SignalHandler {

    private static final Logger LOG = LoggerFactory.getLogger(RpcLimitSignalHandler.class);

    @Override
    public void handle(final String signalName) {
        if (FileSignals.ignoreSignal(FileSignal.RpcLimit)) {
            LOG.info("`LIMIT_SWITCH`={}.", ClientRequestLimitInterceptor.isLimitSwitchOpen());
            return;
        }

        final boolean oldValue = ClientRequestLimitInterceptor.resetLimitSwitch();
        LOG.warn("Reset `LIMIT_SWITCH` to {} triggered by signal: {}.", !oldValue, signalName);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy