Class PsDebug
- java.lang.Object
-
- jv.object.PsDebug
-
- All Implemented Interfaces:
- java.lang.Runnable
public final class PsDebug extends java.lang.Object implements java.lang.RunnableAllows to issue messages and debug information on the console of JavaView, which is different from Java console. These calls are intended to replace System.out calls. Textual debug information may be issued with either of the following callsif (PsDebug.NOTIFY) PsDebug.notify(String) // Default: disabled in release version if (PsDebug.WARNING) PsDebug.warning(String) // Default: enabled PsDebug.error(String, PsObject) // Default: enabledand textual messages may be directly issued withPsDebug.message(String) // Default: enabledAll information is collected in a text area and shown in the dialogPsConsole. The checkboxes located in the header of the console allow to enable different warning levels. Remark: All messages are cached and flushed to console after some short intervals.Debug methods parse the current stack trace and print additional information about the calling method and class.
- See Also:
PsConsole- Author:
- Konrad Polthier
- Version:
- 23.11.14, 3.80 revised (kp) Special checks to assure a clean jvLite setup.
11.03.10, 3.70 revised (fk) AddmessageWithoutNewline(String).
19.11.06, 3.60 revised (kp) New methods to popStatus and pushStatus.
24.04.05, 3.50 revised (kp) New method to issue outOfMemory warning.
20.11.04, 3.41 revised (kp) New global variable DEBUG for development purposes.
22.09.02, 3.40 revised (kp) Console not created until it is really shown.
21.09.02, 3.30 revised (kp) New static variables added MESSAGE and STATUS.
16.12.00, 3.20 revised (kp) New methods to get/set maximal number of beeps.
04.11.00, 3.10 revised (kp) New private variables to identify debug messages.
03.11.00, 3.00 revised (kp) Message use method stack to print information about calling method.
30.09.99, 2.20 revised (kp) Thread in PsConsole deactivated because of mysterious dead lock.
11.07.99, 2.10 revised (kp) NOTIFY flag added.
09.06.99, 2.00 revised (kp) Caching of messages added to method append().
02.06.99, 1.60 revised (kp) Invoke a reset of static PsDebug when console is disposed.
20.05.99, 1.50 revised (kp) Handling of console moved here from PvViewer.
23.01.99, 1.20 revised (kp) methodmessage(String)added.
16.11.98, 1.10 revised (kp) cleaned.
00.00.97, 1.00 created (kp)
-
-
Field Summary
Fields Modifier and Type Field and Description static booleanDEBUGDetermines if JavaView runs in debug mode.static booleanERRORGlobal flag used during compile time to include or exclude all PsDebug.error() calls.static intMAX_MESSAGE_LENGTHDetermines the message type 'message'.static booleanMEMORYDetermines if JavaView performs memory measurements.static booleanMESSAGEGlobal flag used during compile time to include or exclude all PsDebug.message() calls.static booleanNOTIFYGlobal flag used during compile time to include or exclude all PsDebug.notify() calls.static booleanPROFILEDetermines if JavaView performs profiling measurements.static booleanSTATUSGlobal flag used during compile time to include or exclude all PsDebug.showStatus() calls.static booleanWARNINGGlobal flag used during compile time to include or exclude all PsDebug.warning() calls.
-
Constructor Summary
Constructors Constructor and Description PsDebug()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static voidbeep(java.lang.String message)Issue a beep and print message to System.out.static voiddisposeConsole()Dispose console window, e.g. when applet stops, remove textArea and reset variables.static voiderror(java.lang.String aString)Error messages indicate fatal errors which cannot be handled.static voiderror(java.lang.String aString, java.lang.Object what)Error messages indicate fatal errors which cannot be handled.static voidflushMessages()Flush cached messages into console window.static PsConsolegetConsole()Get console window.static java.awt.RectanglegetConsoleSize()Get rectangle with size of JavaView console window.static longgetFlushInterval()Get length of least time interval between two successive flushes.static intgetMaxNumBeeps()Get maximal number of warning beeps.static longgetMemoryIncr()Get amount of newly allocated memory since last call of initMemory() or getMemoryIncr().static longgetMemoryTotal()Get total amount of memory which is total memory minus free memory of current runtime.static java.awt.PanelgetStatusPanel()Get panel which shows status information.static longgetTimeIncr()Get number of milliseconds since last call of getIncrTime() or initTime().static longgetTimeUsed()Get number of milliseconds since last call of initTime().static booleanhasConsole()Get state of console.static booleanhasMessages()Check whether message buffer contains non-flushed messages.static voidinitMemory()Compute initial amount of memory for use with getMemoryIncr().static voidinitTime()Initialize timer for use with getTimeUsed() and getTimeIncr().static booleanisDebug()Check switch if debugging is enabled.static booleanisError()Check switch to record heavy errors in JavaView console.static booleanisMessage()Check switch to record info message in JavaView console.static booleanisNotify()Check switch to record notify message, i.e. debug messages, in JavaView console.static booleanisWarning()Check switch to record warning messages in JavaView console.static voidmessage(java.lang.String aString)Print messages immediately to console, make rare use since no button to turn it off.static voidmessage(java.lang.String aString, boolean bShowConsole)Print messages immediately to console, make rare use since no button to turn it off.static voidmessageWithoutNewline(java.lang.String aString)Print messages immediately to console, make rare use since no button to turn it off.static voidmessageWithoutNewline(java.lang.String aString, boolean bShowConsole)Print messages immediately to console, make rare use since no button to turn it off.static voidnotify(java.lang.String aString)Heavily used during development process for all different messages.static voidoutOfMemory(java.lang.OutOfMemoryError oom)Issue an OutOfMemory warning and perform garbage collection.static voidpopStatus()Recall and show the previous status message.static voidpushStatus(java.lang.String aString)Store previous status on stack and show this new status message.static voidpushStatus(java.lang.String aString, int seconds)Display message in status bar of applet, and in console window.voidrun()Flush messages collected with PsDebug to console.static voidsetConsole(PsConsole console)Set console.static voidsetDebug(boolean aFlag)Enable debugging.static voidsetError(boolean aFlag)Enable recording of heavy errors in JavaView console.static voidsetMaxNumBeeps(int num)Set maximal number of warning beeps.static voidsetMessage(boolean aFlag)Enable recording of info message in JavaView console.static voidsetNotify(boolean aFlag)Enable recording of notify message, i.e. debug messages, in JavaView console.static voidsetWarning(boolean aFlag)Enable recording of warning messages in JavaView console.static voidshowStatus(java.lang.String aString)Display message in status bar of applet, and in console window.static voidwarning(java.lang.Exception ex, java.lang.String aString)Warning messages indicate real errors which are handled.static voidwarning(java.lang.String aString)Warning messages indicate real errors which are handled.static voidwarning(java.lang.String aString, java.lang.Object what)Warning messages indicate real errors which are handled.
-
-
-
Field Detail
-
STATUS
public static final boolean STATUS
Global flag used during compile time to include or exclude all PsDebug.showStatus() calls. IfSTATUS==falsethen all notification methods are removed by a Java compiler during optimization since the methods would never be executed.The Microsoft conditional directive is used to simplify the conditional switch, and the conditional statements can be removed without any influence if the developer sets the variable STATUS by hand.
- See Also:
- Constant Field Values
- Version:
- 21.09.02, 1.00 created (kp)
-
MESSAGE
public static final boolean MESSAGE
Global flag used during compile time to include or exclude all PsDebug.message() calls. IfMESSAGE==falsethen all notification methods are removed by a Java compiler during optimization since the methods would never be executed.The Microsoft conditional directive is used to simplify the conditional switch, and the conditional statements can be removed without any influence if the developer sets the variable MESSAGE by hand.
- See Also:
- Constant Field Values
- Version:
- 21.09.02, 1.00 created (kp)
-
NOTIFY
public static final boolean NOTIFY
Global flag used during compile time to include or exclude all PsDebug.notify() calls. IfNOTIFY==falsethen all notification methods are removed by a Java compiler during optimization since the methods would never be executed.The Microsoft conditional directive is used to simplify the conditional switch, and the conditional statements can be removed without any influence if the developer sets the variable NOTIFY by hand.
- See Also:
- Constant Field Values
- Version:
- 06.05.17, 1.02 revised (kp) Activate notify framework, though might be switch off initially.
31.08.99, 1.01 revised (kp) Microsoft conditional directive added.
-
WARNING
public static final boolean WARNING
Global flag used during compile time to include or exclude all PsDebug.warning() calls. IfWARNING==falsethen all warning methods are removed by a Java compiler during optimization since the methods would never be executed.The Microsoft conditional directive is used to simplify the conditional switch, and the conditional statements can be removed without any influence if the developer sets the variable WARNING by hand.
- See Also:
- Constant Field Values
- Version:
- 31.08.99 1.01 revised (kp) Microsoft conditional directive added.
-
ERROR
public static final boolean ERROR
Global flag used during compile time to include or exclude all PsDebug.error() calls. IfERROR==falsethen all error methods are removed by a Java compiler during optimization since the methods would never be executed.The Microsoft conditional directive is used to simplify the conditional switch, and the conditional statements can be removed without any influence if the developer sets the variable ERROR by hand.
- Since:
- JavaView 2.37
- See Also:
- Constant Field Values
- Version:
- 13.09.02 1.00 created (kp)
-
DEBUG
public static final boolean DEBUG
Determines if JavaView runs in debug mode.- Since:
- JavaView 3.54.000
- See Also:
- Constant Field Values
- Version:
- 29.08.04 1.00 created (kp)
-
MEMORY
public static final boolean MEMORY
Determines if JavaView performs memory measurements.- Since:
- JavaView 3.84.012
- See Also:
- Constant Field Values
- Version:
- 04.02.05 1.00 created (kp)
-
PROFILE
public static boolean PROFILE
Determines if JavaView performs profiling measurements.- Since:
- JavaView 4.10.003
- Version:
- 12.03.14 1.00 created (kp)
-
MAX_MESSAGE_LENGTH
public static final int MAX_MESSAGE_LENGTH
Determines the message type 'message'.- See Also:
- Constant Field Values
-
-
Method Detail
-
getConsole
public static PsConsole getConsole()
Get console window. It is no error if console window is not available, e.g. when during startup frame has not been registered in PsConfig. The text area is available from the very beginning and records all information. If console is opened this information is displayed in the console.- Version:
- 12.06.99, 1.70 revised (kp) Flush message when creating a new console.
-
getStatusPanel
public static java.awt.Panel getStatusPanel()
Get panel which shows status information.- Version:
- 05.05.07, 1.10 revised (kp) Background color of status panel.
18.11.06, 1.00 created (kp)
-
disposeConsole
public static void disposeConsole()
Dispose console window, e.g. when applet stops, remove textArea and reset variables. Since PsDebug is a static class it is essential to remove the console and textArea when an applet stops, since otherwise the next applet will get the same console window and textArea.- Version:
- 02.06.99, 1.60 revised (kp) Invoke a reset of static PsDebug when console is disposed.
20.05.99, 1.50 created (kp) Handling of console moved here from PvViewer.
-
setConsole
public static void setConsole(PsConsole console)
Set console.
-
hasConsole
public static boolean hasConsole()
Get state of console.
-
getConsoleSize
public static java.awt.Rectangle getConsoleSize()
Get rectangle with size of JavaView console window.
-
isMessage
public static boolean isMessage()
Check switch to record info message in JavaView console.
-
setMessage
public static void setMessage(boolean aFlag)
Enable recording of info message in JavaView console.
-
isNotify
public static boolean isNotify()
Check switch to record notify message, i.e. debug messages, in JavaView console.
-
setNotify
public static void setNotify(boolean aFlag)
Enable recording of notify message, i.e. debug messages, in JavaView console.
-
isWarning
public static boolean isWarning()
Check switch to record warning messages in JavaView console.
-
setWarning
public static void setWarning(boolean aFlag)
Enable recording of warning messages in JavaView console.
-
isError
public static boolean isError()
Check switch to record heavy errors in JavaView console.
-
setError
public static void setError(boolean aFlag)
Enable recording of heavy errors in JavaView console.
-
isDebug
public static boolean isDebug()
Check switch if debugging is enabled.
-
setDebug
public static void setDebug(boolean aFlag)
Enable debugging.
-
getFlushInterval
public static long getFlushInterval()
Get length of least time interval between two successive flushes.
-
hasMessages
public static boolean hasMessages()
Check whether message buffer contains non-flushed messages.
-
flushMessages
public static final void flushMessages()
Flush cached messages into console window. Console window is the Runnable and calls this method from time to time.
-
popStatus
public static final void popStatus()
Recall and show the previous status message.- Version:
- 19.11.06, 1.00 created (kp)
-
pushStatus
public static final void pushStatus(java.lang.String aString)
Store previous status on stack and show this new status message.- Version:
- 19.11.06, 1.00 created (kp)
-
pushStatus
public static final void pushStatus(java.lang.String aString, int seconds)Display message in status bar of applet, and in console window.- Parameters:
aString- status message- Version:
- 04.11.00, 1.10 revised (kp) No longer print a notify message of status.
-
run
public void run()
Flush messages collected with PsDebug to console. All handling is done inside PsDebug, but PsDebug cannot implement functionality of a Runnable since it is static. Therefore, the instance of PsConsole is used.- Specified by:
runin interfacejava.lang.Runnable
-
showStatus
public static final void showStatus(java.lang.String aString)
Display message in status bar of applet, and in console window.- Parameters:
aString- status message- Version:
- 04.11.00, 1.10 revised (kp) No longer print a notify message of status.
-
message
public static final void message(java.lang.String aString)
Print messages immediately to console, make rare use since no button to turn it off.- Version:
- 12.06.01, 1.00 created (kp)
-
messageWithoutNewline
public static final void messageWithoutNewline(java.lang.String aString)
Print messages immediately to console, make rare use since no button to turn it off.- Version:
- 11.03.10, 1.00 created (fk)
-
message
public static final void message(java.lang.String aString, boolean bShowConsole)Print messages immediately to console, make rare use since no button to turn it off. Additional message method which allows to avoid automatic display of the JavaView console.- Version:
- 11.03.10, 1.10 revised (fk) Delegate to messageWithoutNewline.
12.06.01, 1.00 created (kp)
-
messageWithoutNewline
public static final void messageWithoutNewline(java.lang.String aString, boolean bShowConsole)Print messages immediately to console, make rare use since no button to turn it off. Additional message method which allows to avoid automatic display of the JavaView console.- Version:
- 11.03.10, 1.00 created (fk) created from
message(String, boolean)
-
notify
public static final void notify(java.lang.String aString)
Heavily used during development process for all different messages. Many calls should remain even after in the release version but with disabled notification.
-
warning
public static final void warning(java.lang.String aString)
Warning messages indicate real errors which are handled. A warning message indicates that something is wrong with the system, and further running may lead to unexpected behaviour.- Parameters:
aString- warning message
-
warning
public static final void warning(java.lang.Exception ex, java.lang.String aString)Warning messages indicate real errors which are handled. A warning message indicates that something is wrong with the system, and further running may lead to unexpected behaviour.Print stack trace either of the method which invoked this warning method, or, if ex!=null print the stack trace of the exception.
- Parameters:
ex- Stack trace of exception is printed rather than of invocation of warning.aString- warning message
-
warning
public static final void warning(java.lang.String aString, java.lang.Object what)Warning messages indicate real errors which are handled. A warning message indicates that something is wrong with the system, and further running may lead to unexpected behaviour.- Parameters:
aString- warning messagewhat- object containing more information, what.toString() is appended to message
-
error
public static final void error(java.lang.String aString)
Error messages indicate fatal errors which cannot be handled. The system is completely out of order. Method callsPsDebug.error(String, Object)withobject==null. Console window pops up automatically if method is called.- Parameters:
aString- error message
-
error
public static final void error(java.lang.String aString, java.lang.Object what)Error messages indicate fatal errors which cannot be handled. The system is completely out of order. Console window pops up automatically if method is called.- Parameters:
aString- error message.what- object containing more information, what.toString() is appended to message.
-
getMaxNumBeeps
public static int getMaxNumBeeps()
Get maximal number of warning beeps.- Returns:
- the maximal number of warning beeps.
-
setMaxNumBeeps
public static void setMaxNumBeeps(int num)
Set maximal number of warning beeps.- Parameters:
num- maximal number of warning beeps.
-
beep
public static void beep(java.lang.String message)
Issue a beep and print message to System.out. Only the first invocations of this method lead to an actually beep.The beep() method attempts to play an audio beep. You have no control over pitch, duration, or volume; it is like putting echo ^G in a UNIX shell script.
If run as application this method calls the beep method of the default toolkit. If run as applet then a beep from an audio file is played (pending).
Method is called if an error occurs, or, when in debug mode, also if a warning occurs. Information about the beep is given in the console window of JavaView.
- Version:
- 10.08.00, 1.00 created (kp)
-
initTime
public static void initTime()
Initialize timer for use with getTimeUsed() and getTimeIncr().- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
getTimeUsed
public static long getTimeUsed()
Get number of milliseconds since last call of initTime().- Returns:
- number of milliseconds since last call of initTime().
- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
getTimeIncr
public static long getTimeIncr()
Get number of milliseconds since last call of getIncrTime() or initTime().- Returns:
- number of milliseconds since last call of getTimeIncr() or initTime().
- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
initMemory
public static void initMemory()
Compute initial amount of memory for use with getMemoryIncr(). It is a good idea to garbage collect before, e.g. using PsConfig.runCG().- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
getMemoryTotal
public static long getMemoryTotal()
Get total amount of memory which is total memory minus free memory of current runtime.- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
getMemoryIncr
public static long getMemoryIncr()
Get amount of newly allocated memory since last call of initMemory() or getMemoryIncr().- Since:
- JavaView v3.84.012
- Version:
- 05.02.05, 1.00 created (kp)
-
outOfMemory
public static void outOfMemory(java.lang.OutOfMemoryError oom)
Issue an OutOfMemory warning and perform garbage collection.- Since:
- JavaView v3.85.002
- Version:
- 23.04.05, 1.00 created (kp)
-
-
"