JavaPulse

a finger on the pulse of the freelance Java™ market in the Netherlands

What continuous integration software do you use?

Posted on | 2 December 2008 | 2 Comments
Tags:

Continuous integration is an important component of agile development. It allows teams to work together and catch integration bugs early by continuously integrating into the central code base.

For more info on continuous integration, read it from Martin Fowler:
Continuous Integration by Martin Fowler

What continuous integration software do you use?

View Results

Loading ... Loading …

Introduction to SCRUM

Posted on | 8 October 2008 | No Comments
Tags: |

At my work now, there is a wave of agile revolution going on. Some people (including myself) are really excited about this. I’ve worked with XP and really enjoy the productivity that comes with teamwork, continuous integration, etc.

I gave the following presentation at work and would like to share it here:

RESOURCES:

WEBSITES:

Core AOP (Part I): Introduction to AOP

Posted on | 5 October 2008 | No Comments
Tags: | |

Finally, after my holidays and a week of work, I get around to writing down my impressions from the AOP course from SpringSource. In this course, we gained experience using Spring AOP and AspectJ, and learned the reason behind the choices to be made when adopting AOP. Furthermore, we learned how to use AOP for code analysis and architectural enforcement, infrastructure concerns and finally, domain-specific concerns. I will write several posts on AOP based on my notes from the course. This first one is an introduction to AOP and I plan to fill in more details in further posts.

Introduction and History

Goals of AOP

Aspect Oriented Programming (AOP) is a programming paradigm that aims to promote desirable software characteristics that have been difficult to implement in the current OOP (Object Oriented Programming) technologies. Desirable software characteristics include the DRY principle (Don’t Repeat Yourself), 1:1 modularity, information hiding, and separation of cross-cutting concerns. Examples of cross-cutting concerns are logging, security, transactions, remoting, caching, lazy instantiation, and even business logic.

Design (anti-)patterns

In the absence of multiple inheritance in the current programming languages such as Java and C# (1), design patterns have been developed to help with modularity. However, design patterns (i.e. such as decorator, proxy, command, inheritance, and callbacks)tend to be work-arounds that are usually weakly-typed, invasive, and cumbersome - requiring programmers to follow a template, thus leading to code copying and making it more difficult to refactor. True separation of concerns enables each concern to be developed and tested individually, leading to easier refactoring, and thus improving agility (adaptation to change).

Paradigm Shifts

While programming languages come along more often (2), programming paradigms shift roughly once a decade: assembly/C in the 1970’s, SmallTalk in the early 1980’s, C++ in the mid-80’s, Java in the 1990’s. AOP adoption is increasing due to improvements in tools which provide clarity in where aspects are applied.

AOP Basics

join point - a point in the runtime execution of a program.
pointcut - a set of join points matched together by a pointcut expression.
advice - a method to execute for each matched join point in the pointcut. Types of advice are: before, after (normal exit, exception thrown, both), and around.
aspect - a unit of modularity (like a class) that specifies pointcuts and advices to implement a cross-cutting concern.

Spring AOP vs. AspectJ

Both Spring AOP and AspectJ are now backed by SpringSource and are increasingly tightly integrated: using the same pointcut language and annotations from AspectJ, while Spring provides dependency injection to complement aspects. The differences between them provide the choices that can be made when programming AOP in Java. These differences are language, join point model, weaving possiblities.

Language

While Spring AOP specify aspects as normal Java classes and configured using XML or annotation, AspectJ requires the use of the AspectJ language. There are advantages and disadvantages for both. Because aspects as Java classes can be easily understood by Java developers, Spring AOP is easier to adopt, but it has its limitations (see below). Furthermore, pointcut expressions, as well as annotations, are the same as AspectJ. On the other hand, while AspectJ requires knowledge of a new language, the language is most natural for coding aspects, allowing better static analysis with the provided tools and optimal runtime performance.

Join Point Model

A join point model is a set of join point types which specify when an advice can run. AspectJ has a rich join point model: including:
- call
- execution
- get
- set
- exception handlers
- initialization
- static initialization
- advice execution
On the other hand, Spring AOP supports only method execution from the above join point types. (Note that initially Spring AOP is sufficient and easier to adopt especially if already using Spring).

Weaving

An aspect has to be “weaved” into the classes in order for the aspects to be executed during runtime. Spring AOP uses proxy-based (runtime) weaving, while AspectJ provides the choice for compile time, post-compile time, and load time weaving.

Proxy-based weaving (runtime)

Proxy-based weaving means that a proxy is dynamically created for each object that need to be advised. This type of weaving is used by Spring AOP. With proxy-based weaving, there is the runtime flexibility to add, remove, and reorder advices, as well as allowing individual objects of the same type to be advised differently. However, with this flexibility comes the inherent problems of proxies such as identity management (which object is ‘this’?). In addition, as mentioned above, Spring AOP is restricted to method execution pointcuts.

Compile-time weaving (iajc)

Compile-time weaving means that all sources including aspects are compiled with iajc - incremental AspectJ compiler. This links the classes and aspects together to produce fully-weaved .class files. However, there might be reasons why another compiler cannot be used.

Binary weaving (post-compile, byte code instrumentation)

Binary weaving means that aspects are linked with pre-built .class files instead of building the whole application from source. The .class files are “instrumented” like they are for coverage measurement with tools like Cobertura and EMMA. There is full Ant (http://dev.eclipse.org/viewcvs/indextech.cgi/aspectj-home/doc/ant-tasks.html) and Maven (http://mojo.codehaus.org/aspectj-maven-plugin/) support for both compile-time and binary weaving.

Load-time weaving

Load-time weaving means that weaving is deferred until the last possible moment: when a class is loaded by the VM. From what I understand, this is the least straight-forward approach, since it is application server specific. With Java5+, a Java agent, referencing a weaver, is used to run the application. For application servers, enabling load-time weaver depended on the configuration of the classloader as provided by each application server.

Summary

In this post, I wrote an introduction to AOP, presenting goals of AOP, a bit of history, and AOP basic concepts, and finally, exploring the difference between Spring AOP and AspectJ in terms of language, join point model, and weaving. The next post will be about basic pointcut expressions.

Resources:
http://en.wikipedia.org/wiki/Aspect-oriented_programming
http://static.springframework.org/spring/docs/2.5.x/reference/aop.html
http://www.eclipse.org/aspectj/

Footnotes:
1 Why no multiple inheritance in Java?
http://www.javaworld.com/javaqa/2002-07/02-qa-0719-multinheritance.html
http://en.wikipedia.org/wiki/Diamond_problem

2 History of Programming Languages
http://merd.sourceforge.net/pixel/language-study/diagram.html
Main programming languages: http://people.mandriva.com/~prigaux/language-study/diagram-light.png
Full 150+ languages: http://people.mandriva.com/~prigaux/language-study/diagram.png

« go backkeep looking »