mirror of
https://github.com/tiennm99/zfoo.git
synced 2026-06-02 14:15:20 +00:00
feat[storage]: 未被使用的Storage是否回收,recycle属性默认开启节省资源
This commit is contained in:
@@ -162,10 +162,12 @@ public class StorageManager implements IStorageManager {
|
||||
|
||||
@Override
|
||||
public void initAfter() {
|
||||
allStorageUsableMap.entrySet().stream()
|
||||
.filter(it -> !it.getValue())
|
||||
.map(it -> it.getKey())
|
||||
.forEach(it -> storageMap.remove(it));
|
||||
if (storageConfig.isRecycle()) {
|
||||
allStorageUsableMap.entrySet().stream()
|
||||
.filter(it -> !it.getValue())
|
||||
.map(it -> it.getKey())
|
||||
.forEach(it -> storageMap.remove(it));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,7 +177,7 @@ public class StorageManager implements IStorageManager {
|
||||
throw new RunException("没有定义[{}]的Storage,无法获取", clazz.getCanonicalName());
|
||||
}
|
||||
if (!usable) {
|
||||
throw new RunException("Storage没有使用[{}],为了节省内存提前释放了它;只有使用ResInjection注解的Storage才能被动态获取", clazz.getCanonicalName());
|
||||
throw new RunException("Storage没有使用[{}],为了节省内存提前释放了它;只有使用ResInjection注解的Storage才能被动态获取或者关闭配置recycle属性", clazz.getCanonicalName());
|
||||
}
|
||||
return storageMap.get(clazz);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,9 @@ public class StorageConfig {
|
||||
// 类的属性是否可写,如果为false则类的属性必须为private并且不能有set方法
|
||||
private boolean writeable;
|
||||
|
||||
// 未被使用的Storage是否回收,默认开启节省资源
|
||||
private boolean recycle;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -59,4 +62,12 @@ public class StorageConfig {
|
||||
public void setWriteable(boolean writeable) {
|
||||
this.writeable = writeable;
|
||||
}
|
||||
|
||||
public boolean isRecycle() {
|
||||
return recycle;
|
||||
}
|
||||
|
||||
public void setRecycle(boolean recycle) {
|
||||
this.recycle = recycle;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ public class StorageDefinitionParser implements BeanDefinitionParser {
|
||||
resolvePlaceholder("id", "id", builder, element, parserContext);
|
||||
resolvePlaceholder("package", "scanPackage", builder, scanElement, parserContext);
|
||||
resolvePlaceholder("writeable", "writeable", builder, scanElement, parserContext);
|
||||
resolvePlaceholder("recycle", "recycle", builder, scanElement, parserContext);
|
||||
resolvePlaceholder("location", "resourceLocation", builder, resourceElement, parserContext);
|
||||
|
||||
parserContext.getRegistry().registerBeanDefinition(clazz.getCanonicalName(), builder.getBeanDefinition());
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
<xsd:complexType name="scan">
|
||||
<xsd:attribute name="package" type="xsd:string" use="required"/>
|
||||
<xsd:attribute name="writeable" type="xsd:boolean" default="false"/>
|
||||
<xsd:attribute name="recycle" type="xsd:boolean" default="true"/>
|
||||
</xsd:complexType>
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user