From cd60956778a4e6338a41c0795dd5fe7a64907e06 Mon Sep 17 00:00:00 2001 From: o2null Date: Fri, 24 Sep 2021 12:50:57 +0000 Subject: [PATCH] =?UTF-8?q?jndi=E4=BD=BF=E7=94=A8CurrentHashMap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit fd628fb64b37dcd416cfbb0fcac27def402e4799) --- .../x/base/core/project/config/Config.java | 120 ++++++++++++------ .../com/x/server/console/ResourceFactory.java | 14 +- 2 files changed, 89 insertions(+), 45 deletions(-) diff --git a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java index e1e7899a6a..86f113d02f 100644 --- a/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java +++ b/o2server/x_base_core_project/src/main/java/com/x/base/core/project/config/Config.java @@ -12,6 +12,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.LinkedBlockingQueue; @@ -1288,64 +1289,103 @@ public class Config { return (LinkedBlockingQueue) initialContext().lookup(RESOURCE_NODE_EVENTQUEUE); } - public static synchronized JsonElement resource_node_applications() throws Exception { - Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONS); - if (null != o) { - return (JsonElement) o; - } - return null; + @SuppressWarnings("unchecked") + public static JsonElement resource_node_applications() throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + return (JsonElement) map.get(RESOURCE_NODE_APPLICATIONS); +// Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONS); +// if (null != o) { +// return (JsonElement) o; +// } +// return null; } - public static synchronized void resource_node_applications(JsonElement jsonElement) throws Exception { - initialContext().rebind(RESOURCE_NODE_APPLICATIONS, jsonElement); + @SuppressWarnings("unchecked") + public static void resource_node_applications(JsonElement jsonElement) throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + map.put(RESOURCE_NODE_APPLICATIONS, jsonElement); + // initialContext().rebind(RESOURCE_NODE_APPLICATIONS, jsonElement); } - public static synchronized Date resource_node_applicationsTimestamp() throws Exception { - Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONSTIMESTAMP); - if (null != o) { - return (Date) o; - } - return null; + @SuppressWarnings("unchecked") + public static Date resource_node_applicationsTimestamp() throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + return (Date) map.get(RESOURCE_NODE_APPLICATIONSTIMESTAMP); + // Object o = initialContext().lookup(RESOURCE_NODE_APPLICATIONSTIMESTAMP); +// if (null != o) { +// return (Date) o; +// } +// return null; } - public static synchronized void resource_node_applicationsTimestamp(Date date) throws Exception { - initialContext().rebind(RESOURCE_NODE_APPLICATIONSTIMESTAMP, date); + @SuppressWarnings("unchecked") + public static void resource_node_applicationsTimestamp(Date date) throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + map.put(RESOURCE_NODE_APPLICATIONSTIMESTAMP, date); + // initialContext().rebind(RESOURCE_NODE_APPLICATIONSTIMESTAMP, date); } - public static synchronized String resource_node_centersPirmaryNode() throws Exception { - Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYNODE); - if (null != o) { - return (String) o; - } - return null; + @SuppressWarnings("unchecked") + public static String resource_node_centersPirmaryNode() throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + return (String) map.get(RESOURCE_NODE_CENTERSPRIMARYNODE); +// Object o = initialContext().lookup()RESOURCE_NODE_CENTERSPRIMARYNODE; +// if (null != o) { +// return (String) o; +// } +// return null; } - public static synchronized void resource_node_centersPirmaryNode(String node) throws Exception { - initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYNODE, node); + @SuppressWarnings("unchecked") + public static void resource_node_centersPirmaryNode(String node) throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + map.put(RESOURCE_NODE_CENTERSPRIMARYNODE, node); } - public static synchronized Integer resource_node_centersPirmaryPort() throws Exception { - Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYPORT); - if (null != o) { - return (Integer) o; - } - return null; + @SuppressWarnings("unchecked") + public static Integer resource_node_centersPirmaryPort() throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + return (Integer) map.get(RESOURCE_NODE_CENTERSPRIMARYPORT); + // Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYPORT); +// if (null != o) { +// return (Integer) o; +// } +// return null; } - public static synchronized void resource_node_centersPirmaryPort(Integer port) throws Exception { - initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYPORT, port); + @SuppressWarnings("unchecked") + public static void resource_node_centersPirmaryPort(Integer port) throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + map.put(RESOURCE_NODE_CENTERSPRIMARYPORT, port); + // initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYPORT, port); } - public static synchronized Boolean resource_node_centersPirmarySslEnable() throws Exception { - Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE); - if (null != o) { - return (Boolean) o; - } - return null; + @SuppressWarnings("unchecked") + public static Boolean resource_node_centersPirmarySslEnable() throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + return (Boolean) map.get(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE); + // Object o = initialContext().lookup(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE); +// if (null != o) { +// return (Boolean) o; +// } +// return null; } - public static synchronized void resource_node_centersPirmarySslEnable(Boolean sslEnable) throws Exception { - initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, sslEnable); + @SuppressWarnings("unchecked") + public static void resource_node_centersPirmarySslEnable(Boolean sslEnable) throws Exception { + ConcurrentHashMap map = (ConcurrentHashMap) initialContext() + .lookup(RESOURCE_NODE_APPLICATIONS); + map.put(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, sslEnable); + // initialContext().rebind(RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, sslEnable); } public static synchronized ExecutorService[] resource_node_processPlatformExecutors() throws Exception { diff --git a/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java b/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java index 31a3b5c384..0e1dba9b62 100644 --- a/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java +++ b/o2server/x_console/src/main/java/com/x/server/console/ResourceFactory.java @@ -9,6 +9,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Properties; import java.util.TreeMap; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.LinkedBlockingQueue; @@ -96,12 +97,15 @@ public class ResourceFactory { eventQueueExecutor.start(); new Resource(Config.RESOURCE_NODE_EVENTQUEUE, eventQueue); new Resource(Config.RESOURCE_NODE_EVENTQUEUEEXECUTOR, eventQueueExecutor); - new Resource(Config.RESOURCE_NODE_APPLICATIONS, null); - new Resource(Config.RESOURCE_NODE_APPLICATIONSTIMESTAMP, null); + new Resource(Config.RESOURCE_NODE_APPLICATIONS, new ConcurrentHashMap()); + // new Resource(Config.RESOURCE_NODE_APPLICATIONSTIMESTAMP, null); Entry entry = Config.nodes().centerServers().first(); - new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYNODE, entry.getKey()); - new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYPORT, entry.getValue().getPort()); - new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, entry.getValue().getSslEnable()); + Config.resource_node_centersPirmaryNode(entry.getKey()); + Config.resource_node_centersPirmaryPort(entry.getValue().getPort()); + Config.resource_node_centersPirmarySslEnable(entry.getValue().getSslEnable()); +// new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYNODE, entry.getKey()); +// new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYPORT, entry.getValue().getPort()); +// new Resource(Config.RESOURCE_NODE_CENTERSPRIMARYSSLENABLE, entry.getValue().getSslEnable()); } private static void containerEntityNames(ClassLoader classLoader, ScanResult sr) throws Exception { -- GitLab