IDEMPIERE-5355 Improve default trx name (FHCA-3765) (#1407)

* IDEMPIERE-5355 Improve default trx name (FHCA-3765)

* IDEMPIERE-5355 Improve default trx name (FHCA-3765)

Implement suggestions from Heng Sin
Added SysConfig TRX_AUTOSET_DISPLAY_NAME (default false)

* Delete test/debugging code committed by mistake

* IDEMPIERE-5355 fix method wrongly named
This commit is contained in:
Carlos Ruiz 2022-07-26 08:08:32 +02:00 committed by GitHub
parent da245c061c
commit 486ae19cdc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 105 additions and 27 deletions

View File

@ -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";

View File

@ -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<Trx> 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)
*/

View File

@ -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();

View File

@ -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<TrxInfo> 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;
}
}

View File

@ -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('<title>" + escapeEcmaScript(trx.getDisplayName()) +"</title>"
+ "<pre>" + escapeEcmaScript(trx.getStackTrace()) + "</pre>')");
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('<title>" + escapeEcmaScript(trx.getDisplayName()) +"</title>"
+ "<p><b>Transaction = " + trx.getDisplayName() + "</b></p>"
+ "<p><b>TrxName = " + trx.getTrxName() + "</b></p>"
+ "<pre>" + escapeEcmaScript(trx.getStackTrace()) + "</pre>')");
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('<title>" + escapeEcmaScript(trx.getDisplayName()) +"</title>"
+ "<pre>" + escapeEcmaScript(trx.getStackTrace()) + "</pre>')");
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('<title>" + escapeEcmaScript(trx.getDisplayName()) +"</title>"
+ "<p><b>Transaction = " + trx.getDisplayName() + "</b></p>"
+ "<p><b>TrxName = " + trx.getTrxName() + "</b></p>"
+ "<pre>" + escapeEcmaScript(trx.getStackTrace()) + "</pre>')");
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);
}

View File

@ -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)
{}

View File

@ -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)
{}