MaintainJ Blog

September 27, 2009

How to trace socket servers or non-GUI apps?

Filed under: Uncategorized — maintainj @ 6:23 pm

All the MaintainJ video demos show analyzing GUI applications, but you can also analyze non-GUI applications (for that matter any non-J2ME Java code). One query I got was how to use MaintainJ on a socket server application. Socket server applications typically do not have a GUI and it is not easy to define the start and end points of a use case. This post addresses this issue. The same procedure can be applied to to trace a single method or GUI applications when you do not want to manually turn tracing on and off.

The key here is to identify the entry call to the application after which all the calls must be traced. Tracing will be turned on before this method is entered and turned off immediately after this method exits. The call trace is written to a file with name ‘traceFileXX_threadName.ser, where XX is the trace file count starting from 1.

For a Servlet based application, the entry call could be MyAbstractServlet.service(..) method, where all the Servlets in the application override or implement service(..) method. Typically this will be a ‘facade’ or ‘entry’ method in an abstract class or interface where all processing starts with a call to this method.

Once such a method is identified, you need to manually change the aspect (aop.xml) file as follows:

<concrete-aspect name=”com.maintainj.inst.MyAspect” extends=“com.maintainj.aspect.HeadlessExecutionAspect”>
<pointcut name=”anyExecution” expression=”execution(* *.*(..)) || execution(*.new(..))”/>
<pointcut name=”entryCall” expression=”execution( *”/>
<weaver options=”-proceedOnError -nowarn”>
<include within=”*”/>
<exclude within=”com.maintainj..*”/>

Pay attention to the changes in blue. The first change is the super aspect that is extended, which is HeadlessExecutionAspect. This is same for any type of application, Java/J2EE/Eclipse plug-in, as long as you want to generate the trace files in headless mode. If you are capturing the method call context, change HeadlessExecutionAspect to HeadlessExecutionDataAspect.

The second change is the pointcut. If in the auto generated aop.xml there is a second pointcut below ‘anyExecution’ pointcut, delete that and add the new ‘entryCall’ pointcut. This is where you are defining the entry call to your application. The class name here can either be an abstract class or interface or a concrete class. Ensure that the ‘facade’ class is included in the instrumentation scope.

You can start with the auto generated aop.xml and then change it. The location of the auto generated aop.xml for various wizards is discussed in this FAQ. If you are using one of the MaintainJ Run Configurations, in the ‘Aspect’ tab check the ‘Do not regenerate aop.xml’ so that your changes will not be overwritten.

The trace files are written to the current folder from where the application is started. Locate the trace files and copy them to a project in Eclipse workspace to view the beautiful MaintainJ diagrams!

Choudary Kothapalli.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a comment

You must be logged in to post a comment.

Powered by WordPress