org.zodiac.sentinel.base.support.AbstratcInitFunc Maven / Gradle / Ivy
package org.zodiac.sentinel.base.support;
import java.util.concurrent.atomic.AtomicBoolean;
import com.alibaba.csp.sentinel.init.InitFunc;
public abstract class AbstratcInitFunc implements InitFunc {
private final AtomicBoolean initialized = new AtomicBoolean(false);
protected AbstratcInitFunc() {
}
@Override
public final void init() throws Exception {
if (initialized.compareAndSet(false, true)) {
try {
this.initialize();
} catch (Exception e) {
initialized.compareAndSet(true, false);
throw new Exception(e);
}
}
}
protected abstract void initialize() throws Exception;
}