From 29f5186d41c27d725ff9a7c1822bba75a3a5f4fc Mon Sep 17 00:00:00 2001 From: hengsin Date: Fri, 19 Nov 2021 23:04:54 +0800 Subject: [PATCH] IDEMPIERE-5047 iDempiere Server Monitor Improvements (#988) --- .../src/org/compiere/model/GridTabVO.java | 2 +- .../src/org/compiere/model/MAttribute.java | 2 +- .../src/org/compiere/model/MLookup.java | 16 ++--- .../org/compiere/model/MLookupFactory.java | 4 +- .../src/org/compiere/util/CCache.java | 24 +++++++- .../org/compiere/web/AdempiereMonitor.java | 60 ++++++++++++++----- .../src/org/compiere/db/DB_PostgreSQL.java | 2 +- .../webservices/AbstractService.java | 2 +- 8 files changed, 83 insertions(+), 29 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/model/GridTabVO.java b/org.adempiere.base/src/org/compiere/model/GridTabVO.java index a84bc67ae4..f57c9318ef 100644 --- a/org.adempiere.base/src/org/compiere/model/GridTabVO.java +++ b/org.adempiere.base/src/org/compiere/model/GridTabVO.java @@ -311,7 +311,7 @@ public class GridTabVO implements Evaluatee, Serializable return true; } // loadTabDetails - private static final CCache> s_gridFieldCache = new CCache>(MField.Table_Name, "GridFieldVO Cache", 100, 60, false, 1000); + private static final CCache> s_gridFieldCache = new CCache>(MField.Table_Name, "GridFieldVO Cache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 1000); /************************************************************************** * Create Tab Fields diff --git a/org.adempiere.base/src/org/compiere/model/MAttribute.java b/org.adempiere.base/src/org/compiere/model/MAttribute.java index 70434c60ab..3b5ad26498 100644 --- a/org.adempiere.base/src/org/compiere/model/MAttribute.java +++ b/org.adempiere.base/src/org/compiere/model/MAttribute.java @@ -49,7 +49,7 @@ public class MAttribute extends X_M_Attribute implements ImmutablePOSupport /** Logger */ private static CLogger s_log = CLogger.getCLogger (MAttribute.class); - private static CCache s_cache = new CCache(Table_Name, 30, 60); + private static CCache s_cache = new CCache(Table_Name, 30, CCache.DEFAULT_EXPIRE_MINUTE); /** Values */ private MAttributeValue[] m_values = null; diff --git a/org.adempiere.base/src/org/compiere/model/MLookup.java b/org.adempiere.base/src/org/compiere/model/MLookup.java index 14dec432ee..e3c6d09cc3 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookup.java +++ b/org.adempiere.base/src/org/compiere/model/MLookup.java @@ -903,18 +903,18 @@ public final class MLookup extends Lookup implements Serializable - private final static CCache>> s_keyNamePairCache = new CCache>>(null, "MLookup.KeyNamePairCache", 100, 60, false, 500); - private final static CCache>> s_valueNamePairCache = new CCache>>(null, "MLookup.ValueNamePairCache", 100, 60, false, 500); + private final static CCache>> s_keyNamePairCache = new CCache>>(null, "MLookup.KeyNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); + private final static CCache>> s_valueNamePairCache = new CCache>>(null, "MLookup.ValueNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); - private final static CCache> s_directKeyNamePairCache = new CCache>(null, "MLookup.DirectKeyNamePairCache", 100, 60, false, 500); - private final static CCache> s_directValueNamePairCache = new CCache>(null, "MLookup.DirectValueNamePairCache", 100, 60, false, 500); + private final static CCache> s_directKeyNamePairCache = new CCache>(null, "MLookup.DirectKeyNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); + private final static CCache> s_directValueNamePairCache = new CCache>(null, "MLookup.DirectValueNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); private synchronized static List getKeyNamePairCache(MLookupInfo lookupInfo, String cacheKey) { CCache> knpCache = s_keyNamePairCache.get(lookupInfo.TableName); if (knpCache == null) { - knpCache = new CCache>(lookupInfo.TableName, lookupInfo.TableName + " KeyNamePair Cache", 100, 60, false, 500); + knpCache = new CCache>(lookupInfo.TableName, cacheKey + " KeyNamePair Cache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); s_keyNamePairCache.put(lookupInfo.TableName, knpCache); } List list = knpCache.get(cacheKey); @@ -931,7 +931,7 @@ public final class MLookup extends Lookup implements Serializable CCache> vnpCache = s_valueNamePairCache.get(lookupInfo.TableName); if (vnpCache == null) { - vnpCache = new CCache>(lookupInfo.TableName, lookupInfo.TableName + " ValueNamePair Cache", 100, 60, false, 500); + vnpCache = new CCache>(lookupInfo.TableName, cacheKey + " ValueNamePair Cache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, 500); s_valueNamePairCache.put(lookupInfo.TableName, vnpCache); } List list = vnpCache.get(cacheKey); @@ -948,7 +948,7 @@ public final class MLookup extends Lookup implements Serializable CCache knpCache = s_directKeyNamePairCache.get(cacheKey); if (knpCache == null) { - knpCache = new CCache(lookupInfo.TableName, lookupInfo.TableName + " DirectKeyNamePairCache", 100, 60, false, MAX_NAMEPAIR_CACHE_SIZE); + knpCache = new CCache(lookupInfo.TableName, cacheKey + " DirectKeyNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, MAX_NAMEPAIR_CACHE_SIZE); s_directKeyNamePairCache.put(cacheKey, knpCache); } return knpCache; @@ -959,7 +959,7 @@ public final class MLookup extends Lookup implements Serializable CCache vnpCache = s_directValueNamePairCache.get(cacheKey); if (vnpCache == null) { - vnpCache = new CCache(lookupInfo.TableName, lookupInfo.TableName + " DirectValueNamePairCache", 100, 60, false, MAX_NAMEPAIR_CACHE_SIZE); + vnpCache = new CCache(lookupInfo.TableName, cacheKey + " DirectValueNamePairCache", 100, CCache.DEFAULT_EXPIRE_MINUTE, false, MAX_NAMEPAIR_CACHE_SIZE); s_directValueNamePairCache.put(cacheKey, vnpCache); } return vnpCache; diff --git a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java index e147bcf748..797e7ce5b0 100644 --- a/org.adempiere.base/src/org/compiere/model/MLookupFactory.java +++ b/org.adempiere.base/src/org/compiere/model/MLookupFactory.java @@ -55,9 +55,9 @@ public class MLookupFactory /** Logging */ private static CLogger s_log = CLogger.getCLogger(MLookupFactory.class); /** Table Reference Cache */ - private static CCache s_cacheRefTable = new CCache(I_AD_Ref_Table.Table_Name, 30, 60); // 1h + private static CCache s_cacheRefTable = new CCache(I_AD_Ref_Table.Table_Name, 30, CCache.DEFAULT_EXPIRE_MINUTE); // 1h /** List Reference Cache */ - private static CCache s_cacheRefList = new CCache(I_AD_Ref_List.Table_Name, 30, 60); // 1h + private static CCache s_cacheRefList = new CCache(I_AD_Ref_List.Table_Name, 30, CCache.DEFAULT_EXPIRE_MINUTE); // 1h /** diff --git a/org.adempiere.base/src/org/compiere/util/CCache.java b/org.adempiere.base/src/org/compiere/util/CCache.java index be6832dd19..851d500ca6 100644 --- a/org.adempiere.base/src/org/compiere/util/CCache.java +++ b/org.adempiere.base/src/org/compiere/util/CCache.java @@ -55,6 +55,28 @@ public class CCache implements CacheInterface, Map, Serializable private int m_maxSize = 0; + /** Default cache expire time in minutes **/ + public static final int DEFAULT_EXPIRE_MINUTE = getDefaultExpireMinute(); + + private static int getDefaultExpireMinute() + { + try + { + String property = System.getProperty("Cache.ExpireMinute"); + if (property != null && property.trim().length() > 0) + { + int expireMinute = 0; + try + { + expireMinute = Integer.parseInt(property.trim()); + } catch (Throwable t) {} + if (expireMinute > 0) + return expireMinute; + } + } catch (Throwable t) {} + return 60; + } + public CCache (String name, int initialCapacity) { this(name, name, initialCapacity); @@ -87,7 +109,7 @@ public class CCache implements CacheInterface, Map, Serializable public CCache (String tableName, String name, int initialCapacity, boolean distributed) { - this (tableName, name, initialCapacity, 60, distributed); + this (tableName, name, initialCapacity, DEFAULT_EXPIRE_MINUTE, distributed); } public CCache (String tableName, String name, int initialCapacity, int expireMinutes, boolean distributed) diff --git a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java index 651be107e4..58dcfadf9d 100644 --- a/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java +++ b/org.adempiere.server/src/main/servlet/org/compiere/web/AdempiereMonitor.java @@ -779,9 +779,16 @@ public class AdempiereMonitor extends HttpServlet para.addElement(link); font status = null; if (server.isStarted()) - status = new font().setColor(HtmlColor.GREEN).addElement(" (Running)"); + { + if (server.isSleeping()) + status = new font().setColor(HtmlColor.GREEN).addElement(" (Started)"); + else + status = new font().setColor(HtmlColor.GREEN).addElement(" (Running)"); + } else + { status = new font().setColor(HtmlColor.RED).addElement(" (Stopped)"); + } para.addElement(status); } bb.addElement(para); @@ -910,7 +917,7 @@ public class AdempiereMonitor extends HttpServlet if (serverCount != null) { builder.append(serverCount.getStarted()+serverCount.getStopped()) - .append(" - Running=") + .append(" - Started=") .append(serverCount.getStarted()) .append(" - Stopped=") .append(serverCount.getStopped()); @@ -1525,20 +1532,45 @@ public class AdempiereMonitor extends HttpServlet { if (ccache.getName().endsWith("|CCacheListener")) continue; - line = new tr(); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getName()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getTableName()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getSize()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getExpireMinutes()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMaxSize()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getHit()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMiss()))); - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.isDistributed()))); - if (ccache.getNodeId() != null) + if (ccache.getSize() > 0) { - line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getNodeId()))); + line = new tr(); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getName()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getTableName()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getSize()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getExpireMinutes()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMaxSize()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getHit()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMiss()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.isDistributed()))); + if (ccache.getNodeId() != null) + { + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getNodeId()))); + } + table.addElement(line); + } + } + for (CacheInfo ccache : instances) + { + if (ccache.getName().endsWith("|CCacheListener")) + continue; + if (ccache.getSize() == 0) + { + line = new tr(); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getName()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getTableName()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getSize()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getExpireMinutes()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMaxSize()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getHit()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getMiss()))); + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.isDistributed()))); + if (ccache.getNodeId() != null) + { + line.addElement(new td().addElement(WebEnv.getCellContent(ccache.getNodeId()))); + } + table.addElement(line); } - table.addElement(line); } // b.addElement(table); diff --git a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java index 691fdaaa44..8a05c4232b 100755 --- a/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java +++ b/org.compiere.db.postgresql.provider/src/org/compiere/db/DB_PostgreSQL.java @@ -135,7 +135,7 @@ public class DB_PostgreSQL implements AdempiereDatabase private static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK"; - private CCache convertCache = new CCache(null, "DB_PostgreSQL_Convert_Cache", 1000, 60, false); + private CCache convertCache = new CCache(null, "DB_PostgreSQL_Convert_Cache", 1000, CCache.DEFAULT_EXPIRE_MINUTE, false); private Random rand = new Random(); diff --git a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/AbstractService.java b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/AbstractService.java index eaf398a411..3a15d72a39 100644 --- a/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/AbstractService.java +++ b/org.idempiere.webservices/WEB-INF/src/org/idempiere/webservices/AbstractService.java @@ -209,7 +209,7 @@ public class AbstractService { } private static ImmutablePOCache s_WebServiceTypeCache = new ImmutablePOCache(MWebServiceType.Table_Name, 10, 60); //60 minutes - private static CCache s_RoleAccessCache = new CCache<>(X_WS_WebServiceTypeAccess.Table_Name, 60, 60); + private static CCache s_RoleAccessCache = new CCache<>(X_WS_WebServiceTypeAccess.Table_Name, 60, CCache.DEFAULT_EXPIRE_MINUTE); /** * Authenticate user for requested service type