Caching with AspectJ

In my last post I presented a very simple cache that stores objects. Now I want to use this cache with AspectJ in a small sample application.

You can download the Eclipse project as a tar or zip file or browse the code online here.

Continue reading →

Singletons with AspectJ

I stumbled upon this post (german) that shows how to implement the singleton pattern with AspectJ. Although you may want to use dependency injection with Spring or Guice, there might be (hopefully rare) occasions on which you opt for this solution. In this post we’ll check out how to do this with AspectJ 5.

The Eclipse project with the sample code for this post can be downloaded as tar.gz or zip; make sure to install the AspectJ Development Tools. You can browse the code online here.

Continue reading →

Profiling with AspectJ

Lately, I read a paper about profiling with AspectJ: it investigates how to profile heap usage, object lifetime, wasted time and time spent. I was wondering how difficult it would be to write my own simple profiler; and as we’ll see it’s easy and fun.

If you’d like to check out the sample code that accompanies this post, you can download the Eclipse project as tar.gz or zip; make sure to install the AspectJ Development Tools. You can browse the code online here.

Continue reading →

Logging with AspectJ

Again, I would like to endorse the usage of aspect oriented programming because it may ease development significantly. That’s almost always the case with crosscutting concerns like logging and in this post we’ll develop a solution with AspectJ. So, adding logging to your application is as easy as this:

  • implement this AbstractLoggingAspect and define the methods you’d like to monitor
  • declare advice before, after or around the logging pointcut and println your logging to stdout.

Once you’re finished with this you’ve got logging in your application without touching the original code. We’ll have a look at the details in the next sections.

If you’d like to check out the code that accompanies this post you can download the Eclipse project as tar.gz or zip; make sure to install the AspectJ Development Tools. You can browse the code online here.

Continue reading →