[CELEBORN-1516] DynamicConfigServiceFactory should support singleton

### What changes were proposed in this pull request?
DynamicConfigServiceFactory supports singleton.

### Why are the changes needed?
Improve code.

### Does this PR introduce _any_ user-facing change?
No.

### How was this patch tested?
Existing UTs.

Closes #2635 from leixm/singleton.

Authored-by: Xianming Lei <31424839+leixm@users.noreply.github.com>
Signed-off-by: Shuang <lvshuang.xjs@alibaba-inc.com>
This commit is contained in:
Xianming Lei 2024-07-19 16:15:04 +08:00 committed by Shuang
parent d692e49089
commit d5b124d8cd

View File

@ -22,18 +22,26 @@ import java.io.IOException;
import org.apache.celeborn.common.CelebornConf;
public class DynamicConfigServiceFactory {
private static volatile ConfigService _INSTANCE;
public static ConfigService getConfigService(CelebornConf celebornConf) throws IOException {
if (celebornConf.dynamicConfigStoreBackend().isEmpty()) {
return null;
} else {
String configStoreBackend = celebornConf.dynamicConfigStoreBackend().get();
// celeborn.dynamicConfig.store.backend checks value with FS, DB.
if ("FS".equals(configStoreBackend)) {
return new FsConfigServiceImpl(celebornConf);
} else {
return new DbConfigServiceImpl(celebornConf);
}
if (_INSTANCE == null) {
synchronized (DynamicConfigServiceFactory.class) {
if (_INSTANCE == null) {
String configStoreBackend = celebornConf.dynamicConfigStoreBackend().get();
if ("FS".equals(configStoreBackend)) {
_INSTANCE = new FsConfigServiceImpl(celebornConf);
} else {
_INSTANCE = new DbConfigServiceImpl(celebornConf);
}
}
}
}
return _INSTANCE;
}
}