PageHandlerAdapterFactory, handlerAdapters,handlerAdapterMap should unmodifiable (#11801)
* Update LocalSimpleCountRateCounter.java fixbug * Update LocalSimpleCountRateCounter.java bugfix * fix:默认的nacos反脆弱插件的问题 * fix:默认的nacos反脆弱插件的问题 * fix:默认的nacos反脆弱插件的问题 * fix:默认的nacos反脆弱插件的问题 * fix:默认的nacos反脆弱插件的问题,调整为tryAdd * fix:默认的nacos反脆弱插件的问题,调整为tryAdd * 调整测试方式,保障流水线成功 * 重构PageHandlerAdapterFactory,这里将handlerAdapters,handlerAdapterMap设置为unmodifiable * 重构PageHandlerAdapterFactory,这里将handlerAdapters,handlerAdapterMap设置为unmodifiable
This commit is contained in:
parent
b7c3905976
commit
c2aa515f1e
@ -24,6 +24,8 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Collections;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/**
|
||||
* pagination factory.
|
||||
@ -31,54 +33,43 @@ import java.util.Map;
|
||||
* @author huangKeMing
|
||||
*/
|
||||
public class PageHandlerAdapterFactory {
|
||||
|
||||
private static PageHandlerAdapterFactory instance;
|
||||
|
||||
private List<PageHandlerAdapter> handlerAdapters;
|
||||
|
||||
private Map<String, PageHandlerAdapter> handlerAdapterMap;
|
||||
|
||||
|
||||
private final List<PageHandlerAdapter> handlerAdapters;
|
||||
|
||||
private final Map<String, PageHandlerAdapter> handlerAdapterMap;
|
||||
|
||||
public List<PageHandlerAdapter> getHandlerAdapters() {
|
||||
return handlerAdapters;
|
||||
}
|
||||
|
||||
|
||||
public Map<String, PageHandlerAdapter> getHandlerAdapterMap() {
|
||||
return handlerAdapterMap;
|
||||
}
|
||||
|
||||
|
||||
private PageHandlerAdapterFactory() {
|
||||
handlerAdapters = new ArrayList<>(3);
|
||||
handlerAdapterMap = new HashMap<>(3);
|
||||
initHandlerAdapters();
|
||||
}
|
||||
|
||||
public static PageHandlerAdapterFactory getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (PageHandlerAdapterFactory.class) {
|
||||
if (instance == null) {
|
||||
instance = new PageHandlerAdapterFactory();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* init handler adapters.
|
||||
*/
|
||||
private void initHandlerAdapters() {
|
||||
List<PageHandlerAdapter> handlerAdapters = new ArrayList<>(3);
|
||||
Map<String, PageHandlerAdapter> handlerAdapterMap = new HashMap<>(3);
|
||||
Consumer<PageHandlerAdapter> addHandlerAdapter = handlerAdapter -> {
|
||||
handlerAdapters.add(handlerAdapter);
|
||||
handlerAdapterMap.put(handlerAdapter.getClass().getName(), handlerAdapter);
|
||||
};
|
||||
// MysqlPageHandlerAdapter
|
||||
addHandlerAdapter(new MysqlPageHandlerAdapter());
|
||||
addHandlerAdapter.accept(new MysqlPageHandlerAdapter());
|
||||
// DerbyPageHandlerAdapter
|
||||
addHandlerAdapter(new DerbyPageHandlerAdapter());
|
||||
addHandlerAdapter.accept(new DerbyPageHandlerAdapter());
|
||||
// DefaultPageHandlerAdapter
|
||||
addHandlerAdapter(new DefaultPageHandlerAdapter());
|
||||
addHandlerAdapter.accept(new DefaultPageHandlerAdapter());
|
||||
this.handlerAdapters = Collections.unmodifiableList(handlerAdapters);
|
||||
this.handlerAdapterMap = Collections.unmodifiableMap(handlerAdapterMap);
|
||||
}
|
||||
|
||||
private void addHandlerAdapter(PageHandlerAdapter handlerAdapter) {
|
||||
handlerAdapters.add(handlerAdapter);
|
||||
handlerAdapterMap.put(handlerAdapter.getClass().getName(), handlerAdapter);
|
||||
|
||||
private static final class InstanceHolder {
|
||||
static final PageHandlerAdapterFactory INSTANCE = new PageHandlerAdapterFactory();
|
||||
}
|
||||
|
||||
|
||||
public static PageHandlerAdapterFactory getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user