Skip to main content

Java Agent

Starting with JDK 1.5, the javaagent feature has been around which provides for a hook to get access to the classes as they are loaded and consequently do instrumentation of the class to serve your purpose. This along with Javassist will allow you to achieve some useful tasks like enabling specific debugging etc. Below are some useful links for the same

http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/tutorial/tutorial.html
http://blog.javabenchmark.org/2013/05/java-instrumentation-tutorial.html
https://today.java.net/article/2008/04/22/add-logging-class-load-time-java-instrumentation

I used to face issues related to the agent class not been able to find javassist related classes. To tackle this you can add an index file to the agent jar like below.

jar -i agent.jar lib\javassist.jar

and ensure that during deployment the javassist.jar file is in the lib folder which itselfs exists in the same directory as the agent jar.

The insertBefore and insertAfter methods of javaassist can be very useful when instrumenting methods for tasks like profiling the timings, checking the input parameters and checking return values.

slf4j-ext has a good helper class (JavassistHelper) which provides for string to be used for logging the signature (input params) and the return value.

http://www.slf4j.org/extensions.html

In order to use the insertAt method of javassist, you can use the ExprEditor like below

method.instrument(new ExprEditor() {
 public void edit(MethodCall m) throws CannotCompileException {
 }
}

This will iterate through the method body. The required instrumentation can be done within this.

Comments

Popular posts from this blog

Exception in AppMerge flows' progression - Unable to resolve deadlock in factory claims [WebLogic 12.1.1]

While deploying my EAR which included a WAR, I was getting the following errors. While searching on the net for possible solutions to the issue, came across a post which indicated that the following setting for the domain was the cause for the same. The setting needs to be deselected. I tried the below url for steps to disable the setting for the domain that I had already created. http://stackoverflow.com/questions/12219782/how-do-you-turn-off-sip-support-in-weblogic-server-12c But that did not help. I then created a new domain and ensured that the setting was unchecked. This resolved the issue.

Cordova

As part of the installation process, for NetBeans, git is installed. git needs to have the proxy settings to be configured properly before it is functional. Use below command to setup the proxy git config --global http.proxy http://<ip>:<port> When integrating with ionic using the below command to download ionic npm install -g ionic To start an ionic app, use command ionic start <AppFolder> If you are behind a proxy you need to set the PROXY environment variable as below set PROXY=http://<ip>:<port> Below is a good tutorial for building a cordova-ionic app https://www.youtube.com/watch?v=sCnGSOaaZFo Tutorial for ionic apps using jax-rs http://ccoenraets.github.io/ionic-tutorial/create-angular-service.html Tutorial for Angular JS https://docs.angularjs.org/tutorial/step_11 http://www.toptal.com/angular-js/a-step-by-step-guide-to-your-first-angularjs-app