Monday, July 28, 2008

ObjektForumNord about OSGi with Peter Kriens

I am pretty exited that Peter Kriens will join us for the ObjektForumNord (website in German, sorry), a series of talks in Germany. This time the session is in Hamburg (my hometown) and Peter is going to give a tutorial and a talk about OSGi. During the afternoon of September 9th, he will give an introductory tutorial about OSGi together with my colleague Matthias Lübken. The evening is filled with Peters talk on "Why Modularity is Important". I am really looking forward to it. Don't miss it.

Sunday, July 27, 2008

News from Equinox Aspects

Some people might have noticed already that some changes are going on inside the Equinox Aspects incubator. Heiko posted the details to the mailing list:

I am pretty exited that we are moving towards being a better citizen of the Eclipse world. We have re-arranged our development process and aligned it with the process of the other projects at Eclipse. Take a look at our milestone planning and details on what keeps us busy at the Equinox Aspects Plan wiki page.

The first milestone is targeted at the 8th of August, less than two weeks from now. And on the way from milestone to milestone you can watch and test the progress by using the development builds from our download page.

Friday, July 25, 2008

Episode on Plugin Architectures at SE-Radio

Last weekend SE-Radio published an episode about plugin-based architectures. Within this episode I talk with Klaus Marquardt about different kinds of plugins and different kinds of systems build with or out of plugins.

This episode was actually my first episode as host and we recorded it a long long time ago. But listening to it today disappoints me somehow. The episode contains a larger number of repetitions from my side and I didn't achieve to make it a condensed episode. Just to be clear: This was not the fault of Klaus, whom I interviewed in this episode - not at all. Again it reveals that recording podcast episodes is a learning process - just like software engineering is.

"Silver Medal" for Equinox Aspects Talk

The attendees session ranking from Java-Forum-Stuttgart 2008 is now online and I am more than happy to see that my talk about Equinox Aspects (slides, code examples) won the silver medal. How cool is that? And its great to see that more and more people are interested in Equinox Aspects. Wonderful...

Saturday, July 12, 2008

Dependency Injection for Extensions, Third Edition

As you might have read from my previous posting I created an example that demonstrates the usage of Equinox Aspects as the load-time weaving engine for Spring Dynamic Modules. Now its time to describe this in more detail. :-)

My first idea behind this combination was to use the @Configurable annotation to use Spring's dependency injection mechanism for arbitrary objects which you typically don't create via the application context of spring. The default examples for this are plain domain objects, extensions are another example (they are typically created by the extension registry of Eclipse). Spring realizes the dependency injection for those objects by weaving an aspect into their classes. This aspect takes care of injecting the dependencies after each object creation. And this is the point where Equinox Aspects comes into play.

Fortunately Spring ships as a set of OSGi bundles. This is also true for "spring-aspects.jar", the JAR archive that contains the aspect that is responsible for making the @Configurable annotation work. And you can use Equinox Aspects to weave this aspect into your bundles wherever you would like to use the @Configurable extension. Sounds good, eh?

Ok, what do you need to do? Let’s go through the example step by step. First you need a target platform that contains the following:
Now you have a class that would like to use @Configurable. In my example it is a view for an RCP application that looks somewhat like this:

public class View extends ViewPart {

private Service service;

public void setService(Service service) {
this.service = service;

public void createPartControl(Composite parent) {

Then you define in the spring context of the same bundle the view as a spring bean, including the "service" property (the dependency that should be injected):

<bean class="org.eclipse.example.springdm.rcpview.View" scope="prototype">
<property name="service" ref="myservice"/>

<bean id="myservice" class="org.eclipse.example.springdm.rcpview.Service"/>

Take care to define the bean for the view as of scope "prototype". This is necessary to tell spring that this bean definition should be used as prototype for various instances.
Now we need to tell your bundle to be woven with the spring aspect. Therefore you just define the aspect bundle as required bundle:

Require-Bundle: org.eclipse.ui,

Now Equinox Aspects (if started correctly) weaves the aspect into your bundle wherever the @Configurable annotation is used. The next step is to tell the spring context that it should use load-time weaving and annotation configuration (plain old spring configuration for load-time weaving, nothing special here):

<context:load-time-weaver class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver">

This also requires some more import package statements within your manifest:

Import-Package: org.aspectj.lang,

The first two import statements are necessary because they are needed if an aspect gets woven into one of your classes. A more elegant solution for this would be to reexport those packages from the spring-aspects bundle, but they didn’t define the reexport in their manifest. Therefore you need to import them manually.
The last step is to take care of the startup sequence of your bundle. If the extension is created, your bundle should be activated to get the spring context created. This creation of the spring context should happen synchronously to ensure that the context is created when your extension object is created – otherwise the dependency injection would not work. Therefore I declare in the manifest:

Eclipse-LazyStart: true
Spring-Context: *;create-asynchronously:=false

If you would like to take a look at the complete example that I used, you can download it here:

Feedback and questions are always welcome!

Code Examples from "Aspect Weaving for OSGi" Talk

As promised, here are the projects of my live demos from "Aspect Weaving for OSGi" at last weeks Java-Forum-Stuttgart 2008.

Eclipse Monitor Demo

This demo features the relatively old Eclipse Monitor application that Chris Laffra wrote a while ago. It visualizes plugin activities within your Eclipse application and you can analyze what is going on. This monitor uses Equinox Aspects to weave an aspect into all your bundles at load-time to gather the information of what is going on at runtime. It uses AspectJ advises for all methods and object creations. While this is a pretty heavy use of load-time weaving (you will notice a huge performance impact at first startup) it demos nicely the caching feature of Equinox Aspects. The second startup of your monitored app will perform very similar to a startup without any aspect weaving.

To run the example: Within your development environment you should have AJDT installed to work with AspectJ. In your target environment you should have included your favorite IDE (as example RCP app to monitor), the matching AJDT version, and the latest Equinox Aspects development build from here: Notive: You need to install the latest dev build, not one of the archived builds. Once you have this you should be ready to run the example. Just import the projects in your workspace and use the included launch configuration.

Dependency Injection with Spring Dynamic Modules and Equinox Aspects

Spring provides this nice mechanism to inject dependencies in domain objects via the @Configurable annotation (see more here:
The main difference to general spring beans is that the creation of those domain objects is not done by the application context of Spring. Therefore Spring uses an aspect to call the application context after object creation to inject all necessary dependencies. In plain old Spring applications this aspect is woven into the system using load-time weaving.
Wouldn't that be a nice mechanism to inject dependencies into Eclipse extensions (like views or editors)? Just annotate your extension with @Configurable and define the dependencies to be injected inside the application context of your bundle (using the Spring Dynamic Modules stuff)?

One way of doing this is to use Equinox Aspects together with Spring Dynamic Modules. Just use the spring-aspects.jar from your spring distro (its already an OSGi bundle) and enable Equinox Aspects weaving - and you are done. It just works! :-)

To run the example: You don't need any special support within your development environment. Instead your target platform should be configured carefully. For the example projects I used Eclipse 3.3.2 as target platform, added AJDT, added the latest dev build of Equinox Aspects, Spring 2.5.4 bundles and Spring Dynamic Modules 1.1.0 bundles. Import the example projects from the zip file into your workspace and use the included launch config to run the demo. The example injects a spring bean into the view extension.

I will give more detailed information on how this Equinox Aspects weaving can be used together with Spring Dynamic Modules in an upcoming post.

If you observe any problems or if I forgot something in this description, please let me know.

Have fun with the examples!

Thursday, July 03, 2008

Slides from "Aspect Weaving for OSGi" Talk

This morning I gave a presentation at the Java-Forum-Stuttgart conference on Aspect Weaving for OSGi. The slides of this talk are now available for download:
The code for all live demos from the presentation will follow shortly.