diff --git a/org.adempiere.base/src/org/compiere/model/MSysConfig.java b/org.adempiere.base/src/org/compiere/model/MSysConfig.java index 7548089a91..1a78b3de4c 100644 --- a/org.adempiere.base/src/org/compiere/model/MSysConfig.java +++ b/org.adempiere.base/src/org/compiere/model/MSysConfig.java @@ -44,7 +44,7 @@ public class MSysConfig extends X_AD_SysConfig /** * */ - private static final long serialVersionUID = 4959612634759674069L; + private static final long serialVersionUID = 4367630918820342645L; public static final String ADDRESS_VALIDATION = "ADDRESS_VALIDATION"; public static final String ALERT_SEND_ATTACHMENT_AS_XLS = "ALERT_SEND_ATTACHMENT_AS_XLS"; @@ -164,6 +164,7 @@ public class MSysConfig extends X_AD_SysConfig public static final String TAX_LOOKUP_SERVICE="TAX_LOOKUP_SERVICE"; public static final String TOP_MARGIN_PIXELS_FOR_HEADER = "TOP_MARGIN_PIXELS_FOR_HEADER"; public static final String TRACE_ALL_TRX_CONNECTION_GET = "TRACE_ALL_TRX_CONNECTION_GET"; + public static final String TRX_AUTOSET_DISPLAY_NAME = "TRX_AUTOSET_DISPLAY_NAME"; public static final String TWOPACK_COMMIT_DDL = "2PACK_COMMIT_DDL"; public static final String TWOPACK_HANDLE_TRANSLATIONS = "2PACK_HANDLE_TRANSLATIONS"; public static final String USE_EMAIL_FOR_LOGIN = "USE_EMAIL_FOR_LOGIN"; diff --git a/org.adempiere.base/src/org/compiere/util/Trx.java b/org.adempiere.base/src/org/compiere/util/Trx.java index dc5a37dc81..29f9a2851d 100644 --- a/org.adempiere.base/src/org/compiere/util/Trx.java +++ b/org.adempiere.base/src/org/compiere/util/Trx.java @@ -127,11 +127,24 @@ public class Trx */ public static String createTrxName (String prefix) { - if (prefix == null || prefix.length() == 0) + String displayName = null; + if (prefix == null || prefix.length() == 0) { prefix = "Trx"; + if (MSysConfig.getBooleanValue(MSysConfig.TRX_AUTOSET_DISPLAY_NAME, false)) { + StackTraceElement[] st = new Throwable().fillInStackTrace().getStackTrace(); + for (StackTraceElement ste : st) { + if (! Trx.class.getName().equals(ste.getClassName())) { + displayName = ste.getClassName().concat("_").concat(ste.getMethodName()); + break; + } + } + } + } prefix += "_" + UUID.randomUUID(); //System.currentTimeMillis(); //create transaction entry - Trx.get(prefix, true); + Trx trx = Trx.get(prefix, true); + if (displayName != null) + trx.setDisplayName(displayName); return prefix; } // createTrxName @@ -609,7 +622,7 @@ public class Trx /** * @return Trx[] */ - public static Trx[] getActiveTransactions() + public static Trx[] getOpenTransactions() { Collection collections = s_cache.values(); Trx[] trxs = new Trx[collections.size()]; @@ -617,7 +630,16 @@ public class Trx return trxs; } - + + /** + * @return Trx[] + * @deprecated - wrong method name fixed with IDEMPIERE-5355 - please use getOpenTransactions + */ + public static Trx[] getActiveTransactions() + { + return getOpenTransactions(); + } + /** * @see #run(String, TrxRunnable) */ diff --git a/org.adempiere.server/src/main/server/org/compiere/server/SystemInfo.java b/org.adempiere.server/src/main/server/org/compiere/server/SystemInfo.java index 7517bd0bf1..e8a779ee23 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/SystemInfo.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/SystemInfo.java @@ -270,7 +270,7 @@ public class SystemInfo implements Serializable { si.peakThreadCount = th.getPeakThreadCount(); si.daemonThreadCount = th.getDaemonThreadCount(); si.totalStartedThreadCount = th.getTotalStartedThreadCount(); - si.trxInfos = TrxInfo.getActiveTransactions(); + si.trxInfos = TrxInfo.getOpenTransactions(); si.logLevel = CLogMgt.getLevel(); si.currentLogFile = LogFileInfo.getCurrentLogFile(); si.logFileInfos = LogFileInfo.getLogFileInfos(); diff --git a/org.adempiere.server/src/main/server/org/compiere/server/TrxInfo.java b/org.adempiere.server/src/main/server/org/compiere/server/TrxInfo.java index 820a41c647..ab9853c6a6 100644 --- a/org.adempiere.server/src/main/server/org/compiere/server/TrxInfo.java +++ b/org.adempiere.server/src/main/server/org/compiere/server/TrxInfo.java @@ -37,15 +37,16 @@ import org.compiere.util.Trx; * */ public class TrxInfo implements Serializable { - /** - * generated serial id + * */ - private static final long serialVersionUID = -4002703843474813148L; - + private static final long serialVersionUID = 5884131137700945750L; + private String displayName; + private String trxName; private Date startTime; private String stackTrace; + private boolean isActive; /** * @@ -53,21 +54,44 @@ public class TrxInfo implements Serializable { private TrxInfo() { } - public static TrxInfo[] getActiveTransactions() { + /** + * Get the open transactions + * @param onlyActive return just active transactions + * @return + */ + public static TrxInfo[] getOpenTransactions(boolean onlyActive) { List list = new ArrayList<>(); - Trx[] trxs = Trx.getActiveTransactions(); + Trx[] trxs = Trx.getOpenTransactions(); for (Trx trx : trxs) { - if (trx != null && trx.isActive()) { + if (trx != null && (!onlyActive || trx.isActive())) { TrxInfo ti = new TrxInfo(); ti.displayName = trx.getDisplayName(); + ti.trxName = trx.getTrxName(); ti.startTime = trx.getStartTime(); ti.stackTrace = trx.getStrackTrace(); + ti.isActive = trx.isActive(); list.add(ti); } } return list.toArray(new TrxInfo[0]); } + /** + * Get all the open transactions + * @return + */ + public static TrxInfo[] getOpenTransactions() { + return getOpenTransactions(false); + } + + /** + * Get the active transactions + * @return + */ + public static TrxInfo[] getActiveTransactions() { + return getOpenTransactions(true); + } + /** * @return the displayName */ @@ -75,6 +99,13 @@ public class TrxInfo implements Serializable { return displayName; } + /** + * @return the trxName + */ + public String getTrxName() { + return trxName; + } + /** * @return the startTime */ @@ -88,4 +119,12 @@ public class TrxInfo implements Serializable { public String getStackTrace() { return stackTrace; } + + /** + * @return Active status + */ + public boolean isActive() { + return isActive; + } + } 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 0e304a1e21..dfd16b1f0f 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 @@ -1138,13 +1138,21 @@ public class AdempiereMonitor extends HttpServlet for (TrxInfo trx : trxs) { line = new tr(); - line.addElement(new th().addElement("Active Transaction ")); + line.addElement(new th().addElement((trx.isActive() ? "Active" : "Inactive") + " Transaction ")); td td = new td(); - td.setOnClick("var newwindow=window.open('','Popup', 'width=800,height=600');newwindow.document.write('" + escapeEcmaScript(trx.getDisplayName()) +"" - + "
" + escapeEcmaScript(trx.getStackTrace()) + "
')"); - td.addElement("Name="+trx.getDisplayName() + ", StartTime=" + formatTimestampWithTimeZone(0,trx.getStartTime())); - td.setTitle("Click to see stack trace"); - td.setStyle("text-decoration: underline; color: blue"); + if (Util.isEmpty(trx.getStackTrace())) { + td.addElement("Name=" + trx.getDisplayName() + ", StartTime=" + formatTimestampWithTimeZone(0,trx.getStartTime())); + td.setTitle(trx.getTrxName()); + } else { + td.setOnClick("var newwindow=window.open('','Popup', 'width=800,height=600');newwindow.document.write('" + escapeEcmaScript(trx.getDisplayName()) +"" + + "

Transaction = " + trx.getDisplayName() + "

" + + "

TrxName = " + trx.getTrxName() + "

" + + "
" + escapeEcmaScript(trx.getStackTrace()) + "
')"); + label lbl = new label().addElement(trx.getDisplayName()); + lbl.setStyle("text-decoration: underline; color: blue"); + td.addElement("Name=").addElement(lbl).addElement(", StartTime=" + formatTimestampWithTimeZone(0,trx.getStartTime())); + td.setTitle("Click to see stack trace for " + trx.getTrxName()); + } line.addElement(td); table.addElement(line); } @@ -1715,13 +1723,21 @@ public class AdempiereMonitor extends HttpServlet for (TrxInfo trx : trxs) { line = new tr(); - line.addElement(new th().addElement("Active Transaction ")); + line.addElement(new th().addElement((trx.isActive() ? "Active" : "Inactive") + " Transaction ")); td td = new td(); - td.setOnClick("var newwindow=window.open('','Popup', 'width=800,height=600');newwindow.document.write('" + escapeEcmaScript(trx.getDisplayName()) +"" - + "
" + escapeEcmaScript(trx.getStackTrace()) + "
')"); - td.addElement("Name="+trx.getDisplayName() + ", StartTime=" + formatTimestampWithTimeZone(0, trx.getStartTime())); - td.setTitle("Click to see stack trace"); - td.setStyle("text-decoration: underline; color: blue"); + if (Util.isEmpty(trx.getStackTrace())) { + td.addElement("Name=" + trx.getDisplayName() + ", StartTime=" + formatTimestampWithTimeZone(0,trx.getStartTime())); + td.setTitle(trx.getTrxName()); + } else { + td.setOnClick("var newwindow=window.open('','Popup', 'width=800,height=600');newwindow.document.write('" + escapeEcmaScript(trx.getDisplayName()) +"" + + "

Transaction = " + trx.getDisplayName() + "

" + + "

TrxName = " + trx.getTrxName() + "

" + + "
" + escapeEcmaScript(trx.getStackTrace()) + "
')"); + label lbl = new label().addElement(trx.getDisplayName()); + lbl.setStyle("text-decoration: underline; color: blue"); + td.addElement("Name=").addElement(lbl).addElement(", StartTime=" + formatTimestampWithTimeZone(0,trx.getStartTime())); + td.setTitle("Click to see stack trace for " + trx.getTrxName()); + } line.addElement(td); table.addElement(line); } diff --git a/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java b/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java index ce72a3f12b..d683f7aa04 100644 --- a/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java +++ b/org.compiere.db.oracle.provider/src/org/compiere/db/DB_Oracle.java @@ -355,7 +355,7 @@ public class DB_Oracle implements AdempiereDatabase sb.append(" , # Min Pool Size: ").append(m_ds.getMinPoolSize()); sb.append(" , # Max Pool Size: ").append(m_ds.getMaxPoolSize()); sb.append(" , # Max Statements Cache Per Session: ").append(m_ds.getMaxStatementsPerConnection()); - sb.append(" , # Active Transactions: ").append(Trx.getActiveTransactions().length); + sb.append(" , # Open Transactions: ").append(Trx.getOpenTransactions().length); } catch (Exception e) {} 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 6099d18a0b..6220481374 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 @@ -334,7 +334,7 @@ public class DB_PostgreSQL implements AdempiereDatabase sb.append(" , # Min Pool Size: ").append(m_ds.getMinPoolSize()); sb.append(" , # Max Pool Size: ").append(m_ds.getMaxPoolSize()); sb.append(" , # Max Statements Cache Per Session: ").append(m_ds.getMaxStatementsPerConnection()); - sb.append(" , # Active Transactions: ").append(Trx.getActiveTransactions().length); + sb.append(" , # Open Transactions: ").append(Trx.getOpenTransactions().length); } catch (Exception e) {}