Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] debugging without stopping server

Hi Neo,
yes, I think you are confused. AspectWerkz merged with AspectJ. What you
are searching is not dependent on Load Time Weaving directly, what you
are searching for is a tracing aspect.

Basically your need is :
 - Find out which parameters were passed to each a certain function when
it throws an exception
 - Log it somewhere, so that proper action can be taken
 - So, eliminate the need to stop the server, restart it in debug mode,
place the breakpoint, look at those params, restart the server in normal
mode again.

This is perfectly possible, and easy, using AspectJ. A simple aspect
like this will do the job, and can easily be expanded to further support
your needs.

Suppose you have the following class :

public class MyDAO {
  public void doStuffOnDb(String functionName, int parameter) throws
SQLException {
    // call the stored procedure, do stuff on the DB
  }
}

You can add an aspect like this :

public aspect TraceParamatersOnException {
  // A pointcut
  pointcut dbFunction() : execution(MyDao.doStuffOnDb(..));

  // An advice that takes arguments and log them
  after() throwing (SQLException e) : doStuffOnDb() {
    Object[] args = thisJoinPoint.getArgs();
    Logger.getLogger(...).log(.....); //Compose a string here using your
preferred loggin system
  }
}

And that is it. Obviously, you can extend the aspect changing the
pointcut to catch more methods, all the methods in a class, all the
methods throwing SQLException, all the methods in all classes in a
certain package and so on using the flexible pointcut syntax provided by
AspectJ.

Once your aspect is written, you have then to "incorporate" it in your
project. This step is called "weaving". Basically, AspectJ will take
your classes (either java sources, or already compiled .class) on one
side, your aspects on the other, and modify your classes so that proper
advice is executed when an SQLException is thrown.

Weaving can be done in a number of ways. If you are writing an aspect
that will intercept only classes pertaining to your project (classes on
which you have complete control), then maybe compile time weaving is a
good choice : you can use ANT or Maven or call the Ajc compiler by hand
to weave your classes, then package them as usual in a WAR or in a JAR
and use them as if nothing special is there.

I do prefer load time weaving, because it resolves a number of problems
common to compile time weaving, like an aspect having to intercept
classes from different jars and stuff like that. Also, I find it
incredibly simple to use. This decision however is not connected to
"programming an aspect", but it's more a "deploy" style decision, so
should be taken by who cares about that part of the process in your
organization. The decision could finally depend on other requirements,
like the target application server.

If load time weaving is in place (in it's simplest form, it consist of
running the JVM with the AspectJ javaagent), then you can simply write
your aspects in eclipse (installing AJDT, which will provide eclipse
plugins for aspects), pack them in a jar (AJDT has an option to do this
automatically from eclipse), put the jar in the WEB-INF/lib of your WAR
or web application and that's it, nothing more required.

The nice thing about AOP, is that you can write even complex and "heavy"
aspects, but once all the possible causes of exceptions are eliminated
and the code is stable, simply removing the JAR containing aspects from
the web application will effectively remove the additional logging
without touching the application code itself.

Hope this clarified it a bit, I know that the first part of the learning
curve is a bit hard to escalate.

Simone

Neo Anderson wrote:
> Yes, basically the feature I want is to capture the message/ error whilst system is still running. For instance, we have a legacy system based on rmi, which uses store procedure to perform insert, update, delete actions against database. The bitter problem I encountered is each time when there is an error, usually it only throws error like 'ORA-xxxx something goes wrong' with stack trace.  Even I have source and can see exactly what lines the code are at when error occurred, nothing I can do to solve the problem because I do not know what parameters passed in whilst execution (logs sometime just do not help too much and we can not modify the source code; or sometimes it is urgent, but we still can not shutdown the server.)  So if I am able to monitor the exactly value used whilst the system goes wrong, that definitively would help me a lot. 
>
> But due to I am new to AOP, the more document I read, the more confused I am. Originally I thought aspectj's load-time weaving is what I want. However, after reading some document, it seems like the load-time weaving is different from run-time/ online weaving (aspectwerkz) and dynamic AOP (JBoss AOP), which is the feature that aspectj does not support.  So I switch to learn aspectwerkz. Interestingly, in the mailing list, I saw someone says that since the aspectj and aspectwerkz are merged. Users should use aspectj 5 instead of using aspectwerkz for such feature.  I believe I might misunderstand something, but I can't distinguish based on my limited knowledge on AOP.   Would you or anyone please to give me a bit more explain about this?  
>
> I appreciate any help.
>
> Thank you very much.
>
> --- On Wed, 10/9/08, Andrew Eisenberg <andrew@xxxxxxxxxxxx> wrote:
>
>   
>> From: Andrew Eisenberg <andrew@xxxxxxxxxxxx>
>> Subject: Re: [aspectj-users] debugging without stopping server
>> To: javadeveloper999@xxxxxxxxxxx, aspectj-users@xxxxxxxxxxx
>> Date: Wednesday, 10 September, 2008, 3:32 PM
>> Are you saying that you want to use AspectJ to monitor an
>> application
>> and notify you when there is a failure?  You cannot use
>> AspectJ to
>> debug your application.  You can, however, use AspectJ to
>> help gather
>> state about your application at the time of the failure.
>>
>> There is a first failure data capture (FFDC) pattern that
>> you can use.
>> http://blog.springsource.com/main/2008/01/07/capturing-failures-and-system-state-part-i/
>>
>> As for adding aspects to an already running system on a
>> server
>> (without stopping it), that might be difficult depending on
>> the kind
>> of server that you are running.  OSGi based servers are
>> built to allow
>> this kind of thing to happen.
>>
>> On Wed, Sep 10, 2008 at 2:01 AM, Neo Anderson
>> <javadeveloper999@xxxxxxxxxxx> wrote:
>>     
>>> Is it possible for aspectj to debug application or
>>>       
>> project running on the server without stopping the service?
>>     
>>> For instance, suppose I have an application providing
>>>       
>> service and the application also talks to the backend
>> database. Sometime it might throw error (not server crash),
>> but we can not stop it. I check the doc and it looks like
>> load-time weaving can be used for this purpose, but I have
>> no idea how to do that. Would anyone please provide senario
>> or any good tutorial/ example about this?
>>     
>>> Thanks in advice,
>>>
>>>
>>>
>>> _______________________________________________
>>> aspectj-users mailing list
>>> aspectj-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>>
>>>       
>
>
>       
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>   


-- 
Simone Gianni            CEO Semeru s.r.l.           Apache Committer
MALE human being programming a computer   http://www.simonegianni.it/



Back to the top