use of com.creditease.monitor.interceptframework.spi.InterceptContext.Event in project uavstack by uavorg.
the class AppProfilingListener method handleEvent.
@Override
public void handleEvent(InterceptContext context) {
// get the context path
String contextpath = (String) context.get(InterceptConstants.CONTEXTPATH);
String basepath = (String) context.get(InterceptConstants.BASEPATH);
// swtich event
Event event = context.getEvent();
// create the profile context object
ProfileContext profilecontext = new StandardProfileContext();
// put InterceptContext into profile context, then profile handler can get info from InterceptContext
profilecontext.put(InterceptContext.class, context);
// get the profile factory
ProfileFactory pf = ProfileFactory.instance();
switch(event) {
case AFTER_SERVET_INIT:
break;
case BEFORE_SERVLET_DESTROY:
break;
case WEBCONTAINER_STARTED:
startProfiling(contextpath, basepath, pf, profilecontext);
break;
case WEBCONTAINER_STOPPED:
stopProfiling(contextpath, basepath, pf);
break;
default:
break;
}
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext.Event in project uavstack by uavorg.
the class AbsDBPoolHookProxy method start.
@Override
public void start(HookContext context, ClassLoader webapploader) {
Event event = context.get(Event.class);
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
switch(event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_INIT:
initHook(ic);
break;
case AFTER_SERVET_INIT:
break;
case BEFORE_SERVLET_DESTROY:
break;
case GLOBAL_FILTER_REQUEST:
break;
case GLOBAL_FILTER_RESPONSE:
break;
case WEBCONTAINER_RESOURCE_CREATE:
break;
case WEBCONTAINER_RESOURCE_INIT:
break;
case WEBCONTAINER_STARTED:
break;
case WEBCONTAINER_STOPPED:
break;
default:
break;
}
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext.Event in project uavstack by uavorg.
the class JdbcHookProxy method start.
@Override
public void start(HookContext context, ClassLoader webapploader) {
Event event = context.get(Event.class);
InterceptContext ic = (InterceptContext) context.get(HookConstants.INTERCEPTCONTEXT);
switch(event) {
case SPRING_BEAN_REGIST:
case WEBCONTAINER_RESOURCE_INIT:
this.injectDriverManager(webapploader, ic);
this.injectDBCP2(webapploader, ic);
this.injectTomcatDBCP2(webapploader, ic);
this.injectHikari(webapploader, ic);
this.injectDruid(webapploader, ic);
break;
case WEBCONTAINER_RESOURCE_CREATE:
this.injectDataSource(ic);
break;
case WEBCONTAINER_INIT:
this.injectDriverManager(webapploader, ic);
this.injectDBCP2(webapploader, ic);
this.injectTomcatDBCP2(webapploader, ic);
this.injectHikari(webapploader, ic);
this.injectDruid(webapploader, ic);
break;
case AFTER_SERVET_INIT:
break;
case BEFORE_SERVLET_DESTROY:
break;
case WEBCONTAINER_STARTED:
break;
case WEBCONTAINER_STOPPED:
break;
default:
break;
}
}
use of com.creditease.monitor.interceptframework.spi.InterceptContext.Event in project uavstack by uavorg.
the class HookFactory method startHook.
/**
* start application framework hook
*
* @param webapploader
* AppServer WebAppClassLoader
* @param detectClass
* the class is used to defect if the application framework exists
* @param loaderName
* the loader tag helps to load the hook jars
* @param proxyClass
* the hook proxy class to run hook logic
*/
@SuppressWarnings("rawtypes")
public void startHook(ClassLoader webapploader, String detectClass, String loaderName, String proxyClass, Map hookConfig, HookContext cntx) {
if (webapploader == null || detectClass == null || loaderName == null || proxyClass == null) {
return;
}
// see if the app framework is there
try {
webapploader.loadClass(detectClass);
} catch (ClassNotFoundException e) {
// ignore
if (log.isDebugable()) {
log.debug("LOAD detectclass[" + detectClass + "] FAIL. ", e);
}
return;
}
InterceptContext context = (InterceptContext) cntx.get(HookConstants.INTERCEPTCONTEXT);
Event evt = cntx.get(Event.class);
if (log.isLogEnabled()) {
log.info("START hook for proxy=" + proxyClass + ",detect=" + detectClass + ",jar=" + loaderName + ",evt=" + evt.toString());
}
/**
* NOTE: there is only one HookProxy instance for each proxyClass and each webapploader
*/
String contextPath = (String) context.get(InterceptConstants.CONTEXTPATH);
String proxyKey = getHookProxyKey(contextPath, proxyClass);
HookProxy proxy = null;
boolean isNew = false;
if (hooks.containsKey(proxyKey)) {
proxy = hooks.get(proxyKey);
} else {
@SuppressWarnings("unchecked") List<String> supports = (List<String>) hookConfig.get("supports");
// install hook jars
this.installHookJars(webapploader, loaderName, supports);
// new hookproxy instance
try {
Class<?> hookproxyClass = webapploader.loadClass(proxyClass);
Constructor<?> con = hookproxyClass.getConstructor(new Class<?>[] { String.class, Map.class });
proxy = (HookProxy) con.newInstance(new Object[] { proxyKey, hookConfig });
isNew = true;
} catch (Exception e) {
log.error("CREATE hookproxy[" + proxyClass + "] instance FAIL. ", e);
return;
}
}
try {
if (log.isDebugable()) {
log.debug("START hookproxy[" + proxyClass + "] ", null);
}
// start hookproxy
proxy.start(cntx, webapploader);
// only start SUCCESS to store hookproxy
if (isNew == true) {
hooks.put(proxyKey, proxy);
}
if (log.isDebugable()) {
log.debug("START hookproxy[" + proxyClass + "] END", null);
}
} catch (Exception e) {
log.error("START hookproxy[" + proxyClass + "] FAIL. ", e);
} catch (Error e) {
log.error("START hookproxy[" + proxyClass + "] FAIL. ", e);
}
}
Aggregations