#include <JavaTraceTarget.h>
Inheritance diagram for JavaTraceTarget:

| Public Member Functions | |
| JavaTraceTarget () | |
| JavaTraceTarget (jobject javaTraceInit, jmethodID methTraceInit, jmethodID methGetSourceTraceLevelInit) | |
| virtual | ~JavaTraceTarget () | 
| virtual void | notifyTrace (std::string source, TraceLevel level, std::string message) | 
| Receives notification when a trace event occurs. | |
| virtual TraceLevel | getSourceTraceLevel (std::string source) | 
| Gets the level at which a particular source should be traced. | |
| virtual void | beginSnapshot () | 
| Begins recording a snapshot. | |
| virtual void | endSnapshot () | 
| Finishes recording a snapshot. | |
| virtual void | writeCounter (std::string name, int64_t value) | 
| Writes one int counter. | |
| virtual void | onThreadStart () | 
| Receives notification that stats polling is starting via a TimerThread. | |
| virtual void | onThreadEnd () | 
| Receives notification that stats polling via a TimerThread is ending. | |
| Private Attributes | |
| jobject | javaTrace | 
| net.sf.farrago.util.NativeTrace object to which trace messages should be written. | |
| jmethodID | methTrace | 
| Method NativeTrace.trace. | |
| jmethodID | methGetSourceTraceLevel | 
| Method NativeTrace.getSourceTraceLevel. | |
It also implements StatsTarget by converting performance counter updates into trace events which are published inside of Java.
Definition at line 39 of file JavaTraceTarget.h.
| JavaTraceTarget::JavaTraceTarget | ( | ) |  [explicit] | 
Definition at line 33 of file JavaTraceTarget.cpp.
References JniUtil::incrementHandleCount(), javaTrace, methGetSourceTraceLevel, and methTrace.
00034 { 00035 JniEnvAutoRef pEnv; 00036 jclass classNativeTrace = pEnv->FindClass( 00037 "net/sf/farrago/util/NativeTrace"); 00038 00039 jmethodID methInstance = 00040 pEnv->GetStaticMethodID( 00041 classNativeTrace, "instance", 00042 "()Lnet/sf/farrago/util/NativeTrace;"); 00043 00044 jobject javaTraceInit = 00045 pEnv->CallStaticObjectMethod(classNativeTrace, methInstance); 00046 00047 JniUtil::incrementHandleCount(JAVATRACETARGET_TYPE_STR, this); 00048 javaTrace = pEnv->NewGlobalRef(javaTraceInit); 00049 00050 // TODO: convert to Java excn instead 00051 assert(javaTrace); 00052 00053 methTrace = pEnv->GetMethodID( 00054 classNativeTrace,"trace", 00055 "(Ljava/lang/String;ILjava/lang/String;)V"); 00056 methGetSourceTraceLevel = pEnv->GetMethodID( 00057 classNativeTrace,"getSourceTraceLevel", 00058 "(Ljava/lang/String;)I"); 00059 }
| JavaTraceTarget::JavaTraceTarget | ( | jobject | javaTraceInit, | |
| jmethodID | methTraceInit, | |||
| jmethodID | methGetSourceTraceLevelInit | |||
| ) |  [explicit] | 
Definition at line 61 of file JavaTraceTarget.cpp.
References JniUtil::incrementHandleCount(), javaTrace, methGetSourceTraceLevel, and methTrace.
00064 { 00065 JniEnvAutoRef pEnv; 00066 00067 JniUtil::incrementHandleCount(JAVATRACETARGET_TYPE_STR, this); 00068 javaTrace = pEnv->NewGlobalRef(javaTraceInit); 00069 00070 // TODO: convert to Java excn instead 00071 assert(javaTrace); 00072 00073 methTrace = methTraceInit; 00074 methGetSourceTraceLevel = methGetSourceTraceLevelInit; 00075 }
| JavaTraceTarget::~JavaTraceTarget | ( | ) |  [virtual] | 
Definition at line 77 of file JavaTraceTarget.cpp.
References JniUtil::decrementHandleCount(), and javaTrace.
00078 { 00079 JniEnvAutoRef pEnv; 00080 00081 pEnv->DeleteGlobalRef(javaTrace); 00082 JniUtil::decrementHandleCount(JAVATRACETARGET_TYPE_STR, this); 00083 00084 javaTrace = NULL; 00085 }
| void JavaTraceTarget::notifyTrace | ( | std::string | source, | |
| TraceLevel | level, | |||
| std::string | message | |||
| ) |  [virtual] | 
Receives notification when a trace event occurs.
| source | the facility from which the message originated | |
| level | the trace event severity level | |
| message | the text of the message | 
Implements TraceTarget.
Definition at line 87 of file JavaTraceTarget.cpp.
References javaTrace, and methTrace.
Referenced by beginSnapshot(), endSnapshot(), and writeCounter().
00089 { 00090 JniEnvAutoRef pEnv; 00091 00092 // NOTE jvs 21-Aug-2007: use ref reapers here since this 00093 // may be called over and over before control returns to Java 00094 00095 jstring javaSource = pEnv->NewStringUTF(source.c_str()); 00096 JniLocalRefReaper javaSourceReaper(pEnv, javaSource); 00097 jstring javaMessage = pEnv->NewStringUTF(message.c_str()); 00098 JniLocalRefReaper javaMessageReaper(pEnv, javaMessage); 00099 pEnv->CallVoidMethod(javaTrace,methTrace,javaSource,level,javaMessage); 00100 }
| TraceLevel JavaTraceTarget::getSourceTraceLevel | ( | std::string | source | ) |  [virtual] | 
Gets the level at which a particular source should be traced.
| source | name of source to be traced | 
Implements TraceTarget.
Definition at line 102 of file JavaTraceTarget.cpp.
References javaTrace, and methGetSourceTraceLevel.
00103 { 00104 JniEnvAutoRef pEnv; 00105 jstring javaSource = pEnv->NewStringUTF(source.c_str()); 00106 int level = pEnv->CallIntMethod( 00107 javaTrace,methGetSourceTraceLevel,javaSource); 00108 return static_cast<TraceLevel>(level); 00109 }
| void JavaTraceTarget::beginSnapshot | ( | ) |  [virtual] | 
Begins recording a snapshot.
Called before all writeCounter invocations for the snapshot.
Implements StatsTarget.
Definition at line 111 of file JavaTraceTarget.cpp.
References notifyTrace(), and TRACE_PERFCOUNTER_BEGIN_SNAPSHOT.
00112 { 00113 notifyTrace( 00114 "", TRACE_PERFCOUNTER_BEGIN_SNAPSHOT, ""); 00115 }
| void JavaTraceTarget::endSnapshot | ( | ) |  [virtual] | 
Finishes recording a snapshot.
Called after all writeCounter invocations for the snapshot.
Implements StatsTarget.
Definition at line 117 of file JavaTraceTarget.cpp.
References notifyTrace(), and TRACE_PERFCOUNTER_END_SNAPSHOT.
00118 { 00119 notifyTrace( 00120 "", TRACE_PERFCOUNTER_END_SNAPSHOT, ""); 00121 }
| void JavaTraceTarget::writeCounter | ( | std::string | name, | |
| int64_t | value | |||
| ) |  [virtual] | 
Writes one int counter.
This is called from a StatsSource implementation in response to writeStats().
| name | name of counter | |
| value | snapshot value | 
Implements StatsTarget.
Definition at line 123 of file JavaTraceTarget.cpp.
References notifyTrace(), and TRACE_PERFCOUNTER_UPDATE.
00124 { 00125 std::string s = boost::lexical_cast<std::string>(value); 00126 notifyTrace( 00127 name, TRACE_PERFCOUNTER_UPDATE, s); 00128 }
| void JavaTraceTarget::onThreadStart | ( | ) |  [virtual] | 
Receives notification that stats polling is starting via a TimerThread.
Reimplemented from StatsTarget.
Definition at line 130 of file JavaTraceTarget.cpp.
References JniEnvAutoRef::suppressDetach().
00131 { 00132 JniEnvAutoRef pEnv; 00133 // We want to stay attached for the duration of the timer thread, 00134 // so suppress detach here and do it explicitly in onThreadEnd 00135 // instead. See comments on suppressDetach about the need for a 00136 // cleaner approach to attaching native-spawned threads. 00137 pEnv.suppressDetach(); 00138 }
| void JavaTraceTarget::onThreadEnd | ( | ) |  [virtual] | 
Receives notification that stats polling via a TimerThread is ending.
Reimplemented from StatsTarget.
Definition at line 140 of file JavaTraceTarget.cpp.
References JniUtil::detachJavaEnv().
00141 { 00142 JniUtil::detachJavaEnv(); 00143 }
| jobject JavaTraceTarget::javaTrace  [private] | 
net.sf.farrago.util.NativeTrace object to which trace messages should be written.
Definition at line 46 of file JavaTraceTarget.h.
Referenced by getSourceTraceLevel(), JavaTraceTarget(), notifyTrace(), and ~JavaTraceTarget().
| jmethodID JavaTraceTarget::methTrace  [private] | 
Method NativeTrace.trace.
Definition at line 51 of file JavaTraceTarget.h.
Referenced by JavaTraceTarget(), and notifyTrace().
| jmethodID JavaTraceTarget::methGetSourceTraceLevel  [private] | 
Method NativeTrace.getSourceTraceLevel.
Definition at line 56 of file JavaTraceTarget.h.
Referenced by getSourceTraceLevel(), and JavaTraceTarget().
 1.5.1
 1.5.1