Thursday, 27 May 2010

ServiceMix 4 is a beast, but hell I like it!

Share
I'm flabbergasted by the breadth with which Apache architects are building enterprise grade platforms. It's simple: you take Eclipse Equinox as OSGi framework and use it to build Karaf project (originating from ServiceMix Kernel subproject) which is a wrapper (shell, remote access, hot deploy, and more) for ServiceMix 4. Farther, ServiceMix itself uses internally such projects like Apache Camel for integration, Apache Active MQ for messaging, Apache CXF for Web Services. Simple isn't it?

I wrote some post about SM 3 before. There were some things I liked and some I didn't like.

But it's past now. I have been playing around with SM 4 for 2 weeks only, but I know one thing, I will never switch back to SM 3.

Today I will show you how to create first SE OSGi JBI service assembly using FUSE Maven2 archetype, and run it on pure ServiceMix 4. As usually I will also write about all problems I encountered (and solved of course).

Thursday, 20 May 2010

Apache ODE: WS-BPEL faults and failures support

Share
WS-BPEL comes with constructs which allow you to handle SOAP faults just like you do it in Java or .NET - you simply catch them :)

For this you can use <bpws:faultHandlers /> with <bpws:catch /> and/or <bpws:catchAll /> constructs.

But what if there is a failure? For example results returned from one partners were not valid and caused error, or worst one of the partners was not available?

It's a failure, so how can it be handled by WS-BPEL itself?

If you're using Apache ODE it's quite simple...

Wednesday, 19 May 2010

Objective-C categories == Groovy expando mechanism

Share
Long live dynamic languages! It's a short post glorifying dynamic languages :)

(BTW: do you remember my previous post about Groovy: 21 things I like and don't like about Groovy? - there is an example of Groovy expando mechanism)

I know and use Objective-C categories. I use them to, for example, re-implement methods that are already provided.

But only yesterday, while writing some iPhone piece of code using SBJSON library I realised that in fact Objective-C category mechanism is the same as Groovy expando mechanism.

A motto for writing estimates

Share
Last week I was asked to prepare estimates for an iPhone project. There was one song which was played over and over in radio and the Internet (well not the original song but a remix by Jay-Z). The lyrics perfectly describe how you should write the estimates :)

Monday, 17 May 2010

WS-BPEL resources

Share
I decided to put some links to useful WS-BPEL resources here so that I never forget or lose it :)

This week I was writing a WS-BPEL process after quite a long break (few months) and I forgot/misspelled/misplaced some of WS-BPEL constructs.

So here they are, the most useful WS-BPEL resources:

  1. WS-BPEL primer: http://www.oasis-open.org/committees/download.php/23964/wsbpel-v2.0-primer.htm
  2. WS-BPEL 2.0 language specification: http://docs.oasis-open.org/wsbpel/2.0/CS01/wsbpel-v2.0-CS01.html
  3. BPEL: Specifying Dates, Times, and duration: http://blogs.sun.com/gopalan/entry/bpel_specifying_date_and_time (I keep forgetting how to express date and time)
  4. DZone WS-BPEL Ref Card: http://www.scribd.com/doc/22295322/DZone-Refcard-77-Core-WS-BPEL-Business-Process-Execution-Language
  5. My Blog and bpel label: http://jee-bpel-soa.blogspot.com/search/label/bpel (I post non-standard examples and solutions to problems I encounter (and solve of course :) ))
Cheers,
Łukasz

Thursday, 13 May 2010

Java Observable/Observer vs Objective-C Notifications

Share
It's worth to learn new languages. You can always learn something new, get more experienced, and see things from different angle.

Today I will show and compare how notifications are implemented in Java and Objective-C.

Java Observable/Observer

Let's say we have a Downloader which downloads files from the Internet. Files usually take some time to download, so we download them in a separate thread. Upon completion we would like to notify everyone who was interested that download has finished and file is ready:

public class Downloader extends Observable implements Runnable {
 private URL url;
 public Downloader(String url) throws MalformedURLException {
  this.url = new URL(url);
  new Thread(this).start();
 }
 public void run() {
  // let's say I'm downloading the contents of url here
  // sleep for 1 second :)
  try {
   Thread.sleep(1000);
  } catch (InterruptedException e) {
  }
  // I downloaded it
  byte[] downloadedFileOrSomethingElse = {1,2,3};
  // important!
  // mark Observable instance as changed!
  // otherwise notification won't be propagated - see impl for more details
  setChanged();
  notifyObservers(downloadedFileOrSomethingElse);
 }
}

Let's say we have a view class which is interested in receiving notifications from the Downloader, the implementation might look like this:

public class MyView implements Observer {
 @Override
 public void update(Observable o, Object arg) {
  System.out.printf("Got observable ==> %s argument ==> %s", o, arg);
  // do something to update view of what ever
 }
}

To register MyView for notifications I wrote:

MyView view = new MyView();
Downloader downloader = new Downloader("http://www.kernel.org/download-linux-kernel.for.example");
// upon completion of download view will be notified so that it can update its contents properly
downloader.addObserver(view);
// give test some time
Thread.sleep(3000);

Advantages, drawbacks?

This is purely OO way of using notifications. Observable must hold references to all observers, which must adhere to some kind of interface.

Objective-C Notifications

Using iPhone Objective-C notifications mechanism observable and observers don't have to know anything about themselves. Observable posts notification to internal queue. Observer subscribes to it and provides information on what method to call when notification arrives.

Assume in ViewController you have the following code:

// 1. create downloader instance
Downloader *downloader = [Downloader new];
// 2. register current view controller for notifications called "DocumentDownloaded" posted by downloader object (last two parameters are optional)
//    upon recieving notification invoke showDocumentView method
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(showDocumentView:) name: @"DocumentDownloaded" object: downloader];
// 3. create NSURLConnection instance (on the iPhone it automatically starts in the background)
//    as a delegate pass downloader object
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest: request delegate: downloader];

Then in downloader delegate, at the end of connectionDidFinishLoading callback method, post notification:

-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
 [connection release];
 self.contents = [[NSString alloc] initWithBytes:[webData mutableBytes] length:[webData length] encoding:NSUTF8StringEncoding];
 [webData release];
 NSNotification *notification = [NSNotification notificationWithName: @"DocumentDownloaded" object: self];
 [[NSNotificationCenter defaultCenter] postNotification: notification]; 
}

Finally the showDocumentView method of our ViewCOntroller might look something like this:

-(void) showDocumentView: (NSNotification *)notification {
 Downloader *downloader = (Downloader*) [notification object];
 NSString* data = downloader.contents;
 // do something with data 
}

Summary

I like Objective-C approach more. It's something very different from Java and I like it :) I like it because it's 100% loosely coupled. Observable and observers don't have to know anything about themselves.

Of course you can implement this approach in Java as well. You can create static queues, and replace dynamic Objective-C selectors with Java Reflections (or Groovy callbacks)... But that's a different story.

Cheers,
Łukasz

Monday, 10 May 2010

OpenJPA and Geronimo Transaction Managers Madness

Share
I have been developing new version of my PhD system for a while. Nuntius 0.6 is coming in one week (2 weeks at max!) For those of you that are not familiar with it, Nuntius 0.5 is available here: http://nuntius.eti.pg.gda.pl. End of advertisements :)

During the development I decided to upgrade Geronimo from 2.1.3 to 2.1.4. Geronimo 2.1.3 uses OpenJPA 1.0.3, Geronimo 2.1.4 uses OpenJPA 1.2.1. Apart of OpenJPA, Geronimo has its own transaction manager.

I'm a huge fan of tests and integration tests and I highly despise testing enterprise grade system by clicking through the web front-end. I have loads of tests to make sure everything works without the need of deploying it on the server and clicking through it.

Apart of pure business logic and integration tests I have some database tests to test my model. In my tests I always try to use the same libraries my application server uses.

Here are some very interesting results.