From: Bernd Hufmann Date: Tue, 26 Jul 2011 17:45:17 +0000 (-0400) Subject: Fix backwards compatibility problem for JNI 2.6. X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=eb25c724ef488a7c119d552cc73278ffda180bc8;p=deliverable%2Ftracecompass.git Fix backwards compatibility problem for JNI 2.6. --- diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java index 14d8e9b468..6911255b52 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni/JniTrace.java @@ -77,6 +77,9 @@ public abstract class JniTrace extends Jni_C_Common { // Should we print debug in the C library or not? private boolean printLttDebug = DEFAULT_LTT_DEBUG; + // flag determine if live trace is supported or not + private boolean isLiveTraceSupported = false; + // This need to be called prior to any operation protected native int ltt_initializeHandle(String libname); @@ -268,8 +271,16 @@ public abstract class JniTrace extends Jni_C_Common { // Call the LTT to open the trace // Note that the libraryId is not yet and the pointer long newPtr; + if (isLiveTraceSupported()) { - newPtr = ltt_openTraceLive(newLibraryId, tracepath, printLttDebug); + try { + newPtr = ltt_openTraceLive(newLibraryId, tracepath, printLttDebug); + } catch (UnsatisfiedLinkError e) { + // JNI library doesn't support live trace read. Set flag for live trace support to false and + // open trace in offline mode. + setLiveTraceSupported(false); + newPtr = ltt_openTrace(newLibraryId, tracepath, printLttDebug); + } } else { newPtr = ltt_openTrace(newLibraryId, tracepath, printLttDebug); } @@ -785,12 +796,20 @@ public abstract class JniTrace extends Jni_C_Common { /** * Indicate whether a trace can be opened in live mode. - * Override if live mode is supported * * @return true if the trace version supports live */ public boolean isLiveTraceSupported() { - return false; + return isLiveTraceSupported; + } + + /** + * Sets whether a trace can be opened in live mode. + * + * @param isSupported + */ + protected void setLiveTraceSupported(boolean isSupported) { + isLiveTraceSupported = isSupported; } /** diff --git a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java index 12a2c84a3b..99bfa28636 100644 --- a/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java +++ b/org.eclipse.linuxtools.lttng.jni/src/org/eclipse/linuxtools/lttng/jni_v2_6/JniTrace_v2_6.java @@ -37,8 +37,10 @@ public class JniTrace_v2_6 extends JniTrace { */ protected JniTrace_v2_6() { super(); + // Set live trace supported for 2.6 to true by default. + // Will be set to false if open live trace fails. + setLiveTraceSupported(true); } - public JniTrace_v2_6(String newpath) throws JniException { super(newpath); @@ -83,18 +85,4 @@ public class JniTrace_v2_6 extends JniTrace { public JniTracefile allocateNewJniTracefile(Jni_C_Pointer_And_Library_Id newPtr, JniTrace newParentTrace) throws JniException { return new JniTracefile_v2_6(newPtr, newParentTrace); } - - - /** - * Indicate whether a trace can be opened in live mode. - * Override if live mode is supported - * - * @return true if the trace version supports live - */ - @Override - public boolean isLiveTraceSupported() { - return true; - } - - }