[Jrisk-cvs] SF.net SVN: jrisk-code:[1061] Grasshopper
Brought to you by:
yuranet
|
From: <yu...@us...> - 2024-12-27 21:20:26
|
Revision: 1061
http://sourceforge.net/p/jrisk/code/1061
Author: yuranet
Date: 2024-12-27 21:20:23 +0000 (Fri, 27 Dec 2024)
Log Message:
-----------
track action count
Modified Paths:
--------------
Grasshopper/src/net/yura/grasshopper/BugManager.java
Grasshopper/src/net/yura/grasshopper/SimpleBug.java
Grasshopper/src/net/yura/grasshopper/util/TextHandler.java
Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java
Modified: Grasshopper/src/net/yura/grasshopper/BugManager.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/BugManager.java 2024-12-27 20:34:58 UTC (rev 1060)
+++ Grasshopper/src/net/yura/grasshopper/BugManager.java 2024-12-27 21:20:23 UTC (rev 1061)
@@ -18,10 +18,19 @@
public final static String VER = "2.15";
- protected abstract void action(String cause);
+ private Thread thread;
+ private int errorCount;
+ /**
+ * triggered 1 second after an error happens
+ */
+ protected abstract void action(String cause, int actionCount);
+
+ /**
+ * @return has an error happened, this will return true even if {@link #action(java.lang.String)} action has not been triggered yet
+ */
public boolean hasHappened() {
- return happened;
+ return errorCount != 0;
}
public static void interceptAndAlert(final Writer a,final BugManager b) {
@@ -63,6 +72,29 @@
} );
}
+ public void fireAction(final String errorSignature) {
+
+ final int actionCount = errorCount;
+ errorCount++;
+
+ if (thread == null) {
+ thread = new Thread() {
+ public void run() {
+ try {
+ Thread.sleep(1000); // sleep in case we get several printout for this error
+ }
+ catch (Throwable ex) { }
+ thread = null;
+ try {
+ action(errorSignature, actionCount);
+ }
+ catch (Throwable ex) { }
+ }
+ };
+ thread.start();
+ }
+ }
+
/**
* @deprecated
*/
@@ -112,7 +144,7 @@
String string = outputStream.toString();
sw.write( string );
outputStream.reset();
- if (ac!=null) action(ac,string);
+ if (ac!=null) ac.fireAction(string);
}
public void close() throws IOException {
try {
@@ -123,29 +155,4 @@
}
}, true );
}
-
- private Thread thread;
- private boolean happened;
-
- public static void action(final BugManager ac, final String errorSignature) {
-
- ac.happened = true;
-
- if (ac.thread == null) {
- ac.thread = new Thread() {
- public void run() {
- try {
- Thread.sleep(1000); // sleep in case we get several printout for this error
- }
- catch (Throwable ex) { }
- ac.thread = null;
- try {
- ac.action(errorSignature);
- }
- catch (Throwable ex) { }
- }
- };
- ac.thread.start();
- }
- }
}
Modified: Grasshopper/src/net/yura/grasshopper/SimpleBug.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2024-12-27 20:34:58 UTC (rev 1060)
+++ Grasshopper/src/net/yura/grasshopper/SimpleBug.java 2024-12-27 21:20:23 UTC (rev 1061)
@@ -20,8 +20,11 @@
if (instance!=null) return;
BugManager.interceptAndAlert(this, new BugManager() {
- protected void action(String errorSignature) {
- doSubmit(errorSignature);
+ protected void action(String errorSignature, int actionCount) {
+ // only sends first error, maybe there is a better way of doing this
+ if (actionCount == 0) {
+ doSubmit(errorSignature);
+ }
}
});
@@ -68,11 +71,9 @@
final File logfile = file;
//logfile.deleteOnExit();
BugManager.interceptAndAlert(fileWriter, new BugManager() {
- boolean sent;
- protected void action(String errorSignature) {
- // TODO only sends first error, maybe there is a better way of doing this
- if (!sent) {
- sent=true;
+ protected void action(String errorSignature, int actionCount) {
+ // only sends first error, maybe there is a better way of doing this
+ if (actionCount == 0) {
BugSubmitter.submitBug(new LogFile(logfile), errorSignature);
}
}
Modified: Grasshopper/src/net/yura/grasshopper/util/TextHandler.java
===================================================================
--- Grasshopper/src/net/yura/grasshopper/util/TextHandler.java 2024-12-27 20:34:58 UTC (rev 1060)
+++ Grasshopper/src/net/yura/grasshopper/util/TextHandler.java 2024-12-27 21:20:23 UTC (rev 1061)
@@ -86,7 +86,7 @@
// we really want to avoid any possibility of throwing from this method
// as we have no idea what we may be messing up, as anything can call the logger
try {
- BugManager.action(sps, errorSignature);
+ sps.fireAction(errorSignature);
}
catch (Exception ex) {
reportError(null, ex, ErrorManager.GENERIC_FAILURE);
Modified: Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java
===================================================================
--- Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java 2024-12-27 20:34:58 UTC (rev 1060)
+++ Grasshopper/src_swing/net/yura/grasshopper/PopupBug.java 2024-12-27 21:20:23 UTC (rev 1061)
@@ -37,7 +37,6 @@
private JTextArea debugText;
private BugManager simplePrintStream;
- private int count;
private String email;
private String cause;
@@ -53,14 +52,13 @@
debugText.setEditable(false);
simplePrintStream = new BugManager() {
- protected void action(String thecause) {
+ protected void action(String thecause, int actionCount) {
cause = thecause;
- count++;
- if (count == 1) {
+ if (actionCount == 0) {
openPopup();
}
- else if (count <= MAX_SUBMIT) {
+ else if (actionCount < MAX_SUBMIT) {
doSubmit(email, false);
}
}
|