Skip to content

Instantly share code, notes, and snippets.

@dkuebric
Created March 4, 2013 03:15
Show Gist options
  • Save dkuebric/5079655 to your computer and use it in GitHub Desktop.
Save dkuebric/5079655 to your computer and use it in GitHub Desktop.
RUM wrapper
/**
* 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