use of com.workoss.boot.storage.model.StorageType in project boot by workoss.
the class BaseStorageTemplate method loadStorageClient.
Map<StorageType, StorageClient> loadStorageClient() {
ServiceLoader<StorageClient> serviceLoader = ServiceLoader.load(StorageClient.class, this.getClass().getClassLoader());
Iterator<StorageClient> storageClientIterator = serviceLoader.iterator();
Map<StorageType, StorageClient> storageClientMap = new HashMap<>(16);
while (storageClientIterator.hasNext()) {
StorageClient storageClient = storageClientIterator.next();
storageClientMap.put(storageClient.type(), storageClient);
}
return storageClientMap;
}
use of com.workoss.boot.storage.model.StorageType in project boot by workoss.
the class BaseStorageTemplate method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
Map<StorageType, StorageClient> storageClientMap = loadStorageClient();
Map<StorageType, Integer> initNumMap = new HashMap<StorageType, Integer>(4);
if (multiStorageClientConfig != null && multiStorageClientConfig.isEnabled()) {
log.info("ćstoragećmultiStorageClientConfig init start");
Optional.ofNullable(multiStorageClientConfig.getClientConfigs()).orElse(new HashMap<>(16)).entrySet().stream().filter(storageClientConfigEntry -> storageClientMap.containsKey(storageClientConfigEntry.getValue().getStorageType())).forEach(storageClientConfigEntry -> {
Integer num = initNumMap.get(storageClientConfigEntry.getValue().getStorageType());
if (num == null) {
addStorageClient(storageClientMap.get(storageClientConfigEntry.getValue().getStorageType()), storageClientConfigEntry.getKey(), storageClientConfigEntry.getValue());
} else {
addStorageClient(loadStorageClient().get(storageClientConfigEntry.getValue().getStorageType()), storageClientConfigEntry.getKey(), storageClientConfigEntry.getValue());
}
initNumMap.put(storageClientConfigEntry.getValue().getStorageType(), num == null ? 1 : num + 1);
});
}
StorageClientConfig storageClientConfig = multiStorageClientConfig.getDefaultClient();
if (storageClientConfig != null) {
Map<StorageType, StorageClient> defaultClientMap = storageClientMap;
if (initNumMap.containsKey(storageClientConfig.getStorageType())) {
defaultClientMap = loadStorageClient();
}
addStorageClient(defaultClientMap.get(storageClientConfig.getStorageType()), "default", storageClientConfig);
}
initNumMap.clear();
}
Aggregations