mxsm commented on code in PR #3119:
URL:
https://github.com/apache/incubator-eventmesh/pull/3119#discussion_r1107192607
##########
eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/acl/Acl.java:
##########
@@ -25,33 +25,44 @@
import org.apache.commons.lang3.StringUtils;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class Acl {
- private static final Logger logger = LoggerFactory.getLogger(Acl.class);
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+public class Acl {
- private static final Acl INSTANCE = new Acl();
+ private static final Map<String, Acl> ACL_CACHE = new HashMap<>(16);
private AclService aclService;
private Acl() {
}
- public static Acl getInstance() {
- return INSTANCE;
+ public static Acl getInstance(String aclPluginType) {
+ return ACL_CACHE.computeIfAbsent(aclPluginType, key ->
aclBuilder(key));
}
- public void init(String aclPluginType) throws AclException {
- aclService = EventMeshExtensionFactory.getExtension(AclService.class,
aclPluginType);
- if (aclService == null) {
- logger.error("can't load the aclService plugin, please check.");
+ private static Acl aclBuilder(String aclPluginType) {
+ AclService aclServiceExt =
EventMeshExtensionFactory.getExtension(AclService.class, aclPluginType);
+ if (aclServiceExt == null) {
+ log.error("can't load the aclService plugin, please check.");
throw new RuntimeException("doesn't load the aclService plugin,
please check.");
}
+ Acl acl = new Acl();
+ acl.aclService = aclServiceExt;
+
+ return acl;
+ }
+
+ public void init() throws AclException {
aclService.init();
Review Comment:
@jonyangx done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]