Created
March 4, 2013 03:15
-
-
Save dkuebric/5079655 to your computer and use it in GitHub Desktop.
RUM wrapper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Wraps RUM methods using reflection. | |
* (works even if RUM classes are unavailable.) | |
*/ | |
import java.lang.reflect.Method; | |
public class RUMWrapper { | |
private static Method headerMethod = null, footerMethod = null; | |
static { | |
try { | |
/* Attempt to load RUM class and find header/footer methods: */ | |
ClassLoader classLoader = RUMWrapper.class.getClassLoader(); | |
Class rumClass = classLoader.loadClass("com.tracelytics.api.RUM"); | |
headerMethod = rumClass.getDeclaredMethod("getHeader"); | |
footerMethod = rumClass.getDeclaredMethod("getFooter"); | |
} catch (Exception e) { | |
/* This is expected in cases where the Tracelytics jar is not available */ | |
System.err.println("RUM not available"); | |
} | |
} | |
public static String getHeader() { | |
if (headerMethod == null) { | |
return ""; | |
} | |
try { | |
return (String)headerMethod.invoke(null); | |
} catch(Throwable ex) { | |
// Should never happen | |
return ""; | |
} | |
} | |
public static String getFooter() { | |
if (footerMethod == null) { | |
return ""; | |
} | |
try { | |
return (String)footerMethod.invoke(null); | |
} catch(Throwable ex) { | |
// Should never happen | |
return ""; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment