Archive for the ‘Spring’ tag
Øredev Presentations
My presentations from Oredev are finally available. After working through almost all the export options on Keynote, I have settled on QuickTime as the distro format. The “flying code” in the aspects presentation worked out best with QuickTime. Note that it’s not a continuous playback and you have to click-through each frame.
- Solving Domain Problems with Aspects has a couple of slides with repeated transitions (courtesy of the export
). This one has the flying code, as Claudio Perrone calls it! And it is the presentation that lead to the chat with Ayende Rahien. He has done something similar in C# here. - 29.1MB @ http://aslamkhan.net/wp-content/uploads/2008/11/SolvingDomainProblemsWithAspects.mov
- Managing Diversity in Agile Teams was inspired by Claudio’s presentation style. Highly visual with minimal text. It’s about story telling, movie script style and not about bullet point presentations. Thanks, Claudio! - 16.6MB @ http://aslamkhan.net/wp-content/uploads/2008/11/ManagingDiversityInAgileTeams.mov
- Bootstrapping your SOA Project has the slides for the workshop that I ran. It’s a mixture of traditional and visual. The traditional is used purely for reference / take-home material. - 13.5MB @ http://aslamkhan.net/wp-content/uploads/2008/11/BootstrappingYourSOAProject.mov
OSGi Cookbook: #1. A Simple Bean
This is something that I have been meaning to do for some time now, i.e. an OSGi cookbook. So this is the first in a series of recipes, with each one building on the next in usefulness and complexity. This recipe is really for newbies, just to take some of the mystery out of OSGi and to introduce some of the emerging tools for OSGi development. If you have never done anything with OSGi before, then I recommend that you work through Neil Bartlett’s excellent series on getting started with OSGi.
Getting ready
Ensure that you have maven andthe pax-construct scripts installed.The installation is straight forward, just follow the instructions on their respective web sites.
#1. A Simple Bean
This recipe creates a service out of a simple POJO. The service doesn’t do anything useful, but the recipe is a simple way to getyour development environment up and running.
- Create a project using pax-construct.The pax-construct scripts uses maven and the maven-pax-plugin.Using the familiar maven terminology of groupId and artifactId, create the project with a groupId of
net.aslamkhanand artifactId ofosgi-simplebean./> pax-create-project -g net.aslamkhan -a osgi-simplebean...
[INFO] Archetype created in dir: /Users/aslam/projects/osgi/osgi-simplebean
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
- Have a look at what’s in the project and make sure that it does build cleanly (well, there’s actually nothing worthwhile to build here, but let’s make sure that everything is still ok).
/> cd osgi-simplebean/> ls -l-rw-r--r-- 1 aslam aslam 2354 Jan 9 10:26 pom.xml
drwxr-xr-x 5 aslam aslam 170 Jan 9 10:26 poms
drwxr-xr-x 3 aslam aslam 102 Jan 9 10:26 provision
/> mvn package...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO] ------------------------------------------------------------------------
[INFO] net.aslamkhan.osgi-simplebean (OSGi project) .......... SUCCESS [1.689s]
[INFO] osgi-simplebean - plugin configuration ................ SUCCESS [0.004s]
[INFO] osgi-simplebean - wrapper instructions................. SUCCESS [32.144s]
[INFO] osgi-simplebean - bundle instructions ................. SUCCESS [0.003s]
[INFO] osgi-simplebean - imported bundles .................... SUCCESS [0.002s]
...
- We now need to add in the dependencies for Spring Dynamic Modules for OSGi. Instead of hand crafting our maven
pom.xmlfile(s), we again use a pax-construct script to add the repositoriesfor the Spring distributions. From this point onwards, I will not show the output of commands unless it helps to illustrate a point./> pax-add-repository -i spring-milestones \-u http://s3.amazonaws.com/maven.springframework.org/milestone/> pax-add-repository -i spring-snapshots \-u http://static.springframework.org/maven2-snapshots \-- -Dsnapshots "-Dreleases=false" - Import the spring-osgi-extender bundle, and the slf4j logging service bundle.
/> pax-import-bundle -g org.springframework.osgi \-a spring-osgi-extender -v 1.0-rc1 \-- -DwidenScope -DimportTransitiveIf you look at the contents of the
provision/pom.xmlfile, you will see a bunch of dependencies that have been pulled inthe moment we imported the spring-osgi-extender bundle.<dependency>
<groupId>org.springframework.osgi</groupId><artifactId>spring-osgi-extender</artifactId><version>1.0-rc1</version><scope>provided</scope></dependency>
...
- Now that we have all the infrastructure things sorted out, we can start cooking. The quickest way to get cooking is to usethe pax-construct
pax-create-bundlescript. In this instance, we will create a sample bean with the necessaryboilerplate files needed for Spring Dynamic Modules./> pax-create-bundle -p org.example.bean \-- -Dspring -DjunitNotice that another directory
org.example.beanhas been created. Furthermore, this maven module has been added to the root (i.e. parent)./pom.xmlfile. Also conveniently created, is asample bean and associated unit tests inorg.example.bean/srcdirectory.Edit theorg.example.bean/src/main/resources/META-INF/spring/bundle-context-osgi.xmlfile to contain the following.<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
...
xmlns:osgi="http://www.springframework.org/schema/osgi"
...>
<osgi:service ref="myExampleBean"><osgi:interfaces><value>org.example.bean.ExampleBean</value></osgi:interfaces></osgi:service></beans>
- We should be able to build this and fire it up in the Apache Felix OSGi implementation. But wait! We have not downloaded, nor installed Felix. Not to worry, maven-pax-plugin will download Felix and fire it up for you, allpart of the
pax:provisiongoal./> mvn clean install pax:provision... properties (org.springframework.context.service.name=org.example.bean)->
Let’s check if our org.example.bean bundle is installed and active. From the Felix console, enter the following.Also notice that the spring-osgi-extender bundle and spring 2.5 jars are now available as bundles as well.
-> psSTART LEVEL 6 ID State Level Name
[ 0] [Active ] [ 0] System Bundle (1.0.1)
[ 1] [Active ] [ 1] org.osgi.r4.compendium (1.0.0)
[ 2] [Active ] [ 1] Apache Felix Shell Service (1.0.0)
[ 3] [Active ] [ 1] Apache Felix Shell TUI (1.0.0)
[ 4] [Active ] [ 5] spring-osgi-extender (1.0.0.rc1)
[ 5] [Active ] [ 5] jcl104-over-slf4j (1.4.3)
[ 6] [Active ] [ 5] slf4j-api (1.4.3)
[ 7] [Active ] [ 5] spring-osgi-core (1.0.0.rc1)
[ 8] [Active ] [ 5] spring-osgi-io (1.0.0.rc1)
[ 9] [Active ] [ 5] spring-aop (2.5.0)
[ 10] [Active ] [ 5] spring-beans (2.5.0)
[ 11] [Active ] [ 5] spring-context (2.5.0)
[ 12] [Active ] [ 5] spring-core (2.5.0)
[ 13] [Active ] [ 5] spring-web (2.5.0)
[ 14] [Active ] [ 5] spring-test (2.5.0)
[ 15] [Active ] [ 5] aopalliance.osgi (1.0.0.SNAPSHOT)
[ 16] [Active ] [ 5] backport-util-concurrent.osgi (3.0.0.SNAPSHOT)
[ 17] [Active ] [ 5] slf4j-simple (1.4.3)
[ 18] [Active ] [ 5] org.example.bean (1.0.0.SNAPSHOT)->
Now, check that the service is available.
-> services...
org.example.bean (18) provides:
-------------------------------
org.example.bean.ExampleBeanorg.springframework.osgi.context.support.OsgiBundleXmlApplicationContext,
...
That’s it for this recipe. Overall, pax makes it really painless to get your OSGi implementation up and running in your developmentenvironment. Combined with the convenience of spring-dm, we have the start of something really productive.
Looking after your domain model
Mats Helander has written an excellent article on how to manage your domain model with some intelligent design trade-offs. It’s a lengthy article that even manages to introduce AOP as well. If you start reading it and wonder where it’s going, just carry on reading…it is written in an evolutionary style. Nice article, Mats! UPDATE: I have written the Java equivalent of the listing in Mats’ article and attached it. The AOP part uses SpringFramework 2.5 and AspectJ.
Speaking at TSS-JS 2008
I will be speaking at the next TheServerSide Java Symposium in Las Vegas in March 2008. The presentation will be part of the FrontLine Java track and will cover OSGi and its use in Enterprise Application Development. This is a more detailed presentation of what I was intending to cover at the *Camp in Cape Town.
