Caching the remote interface of a Stateless Session Bean

We have asked this question several times in our organisation and I have seen it being asked many times in various web forums.
I suspect that the reason why there is no correct answer is that it all depends on your environment.
Some people report very good results with one approach but the same approach may not be efficient or not even functional somewhere else; such as in a clustered environment.
The options:
1. A common basic approach is to store the reference to the remote interface in the http session. Once it has been stored, all clients can quickly access business methods of the stateful session bean. You should use business delegates to communicate with your EJBs.
According to the specification (EJB spec 2.1FR, section 7.8):

There is no fixed mapping between clients and stateless instances. The container simply delegates a client’s work to any available instance that is method-ready.

This means that even with a single remote interface, the container will delegate what bean instance should serve a client call.
With stateful beans the case is the contrary. A remote interface will always guarantee calls are delegated to the same stateful session bean. This of course is crucial to enable a dialog between a client and a stateful bean.
2. The JNDI lookup of a home interface is the costly part of locating an EJB. As such, storing a reference to the home interface is a second approach.
Because application servers may use the create() method as load balancing trigger this approach may behave better in a clustered environment. Consider using the service locator pattern to collect all your service lookups to a single point.
3. A handle to an EJB has the advantage of being serialisable and valid between multiple JVMs. It seems to be the superior way of storing a reference to an EJB.
It is only possible to acquire a handle to EJBs that implement remote interfaces. With EJB 2.0, you will see that many EJBs implement local interfaces only to improve performance. Only the session facades will be exposing both local and remote interfaces.
Conclusion:
To be future proof, it is safest to assume as little as possible about the behaviour of your J2EE server and avoiding short cuts.
This will ensure that your application can move from a testing environment to a full clustered, load balanced production environment or a different j2ee application server.
JNDI lookups of the home interface is the expensive operation so implement a service locator that caches home interfaces. Make sure all of your code is using this single point of looking up EJBs. It will then be possible to change the lookup strategy in the future if needed.
References:
The server side
Service Locator pattern
EJB 2.1 Specification

Young entrepreneurs in London

Yesterday while at the excellent Camden Market, I met some fellow country men (Czechs). They had set up a stand from which a lovely caramelised sugar and cinnamon scent was coming.
They were selling “Trdlo” that they proclaimed was a traditional Czech pastry. I had never seen “Trdlo” before so I asked about it, in English.
They started explaining how traditional it is but when I mentioned that I am Czech as well and that I had never seen it before, they had few and lame explanations.
Anyway, I was amused by the claim and it smelled lovely so I decided to try it. It was really yum and at £2 (100 Czech krounes) a pop it seems to be a gold mine. I don’t really care whether the claim is true, I am just happy to see some young Czech entrepreneurs trying their wings due to the new EU membership 😉
Update 06/09/04
Looks as if trdlo has been introduced in Prague as well; with not so good response. A Czech blogger writes how people are being ripped of with burned dough (In Czech).
Update 18/04/06
Trdlo recipe (is in Slovak… will be translated to English at some point)

Netbeans 4.0 Beta 1 – first impressions

The potential is great but I have mixed first feelings.
Netbeans 4.1 splashThe new Netbeans is (Ant) project oriented a la Eclipse, IntelliJ and others. Point at an Ant build script, and Netbeans will try to pick out source, target and library directories. No more mounting ad hoc mounting of directories, things have to be more organised.
Refactoring has a dedicated menu option. You will be able to rename and move classes around; Netbeans will search all of the code base and reflect the changes.
Multiple build targets is something that has always been lacking. Finally Netbeans 4.0 allows you to define a build target for each source path. Build your Servlets, EJB implementations, interfaces, utilities and etc to different targets.
I know this is just a first beta (the final release is scheduled for December 2004) but there were exceptions all over the place. Possibly because I tried to open two medium to large sized existing projects. Had I started creating a small project from scratch, it would have given NB 4.0b1 a more fair chance.
The J2EE development support preview coming in October will be interesting. Additional exciting coming feature is the Profiler. I have already tried the stand-alone preview and once again it did not manage to profile two of our main projects due to exceptions 🙁
Here is a good document on how to move from Netbeans 3.6 to Netbeans 4.0.

Heja Sverige!

Sweden secured 3 gold medals within 24 hours. That’s a very good feat considering the size of the country. Again and again they prove how talented and athletic they are.
First the heroin Carolina Klüft got gold for women’s heptathlon where she frankly dominated (6952 points). Then Christian Olsson in men’s triple jump (17.79m). Last Stefan Holm in high jump (2.36m); his first win in a major competition in a long time.
Being born in Czech Republic, raised in Sweden, living in England and soon to be married to a Brazilian wife, I sometimes get confused about who to cheer on. As long as all of them are winning gold medals, it’s all good!

Luisa Miller, Opera Holland Park

The heroine Luisa and “Carlo” fall in love but Carlo is really Rodolfo, the son of the powerful count Walter. In jealousy Wurma, the counts servant, revels the true identity of Carlo to Luisa’s father Miller.
When Walter finds out of son’s plans of marrying Luisa he feels he needs to intervene. Not only is Luisa just a farmers daughter, Walter also has plans for Rudolfo to marry the now wealthy duchess Frederica who has loved Rudolfo since he was a little boy.
The scene is set for a tragedy of love and jealousy. A tragedy that comes true.
(Spoiler below but in true Opera fashion, it’s good to be aware of the whole story so that you can appreciate the music and the singing)
Rudolfo overhears Luisa denouncing her love for him and is in despair. He doesn’t know that Luisa wasn’t telling the truth, she was only trying to save her father that had been put into prison. Rudolfo is desperate and decides to poison both Luisa and himself. Only after Luisa finds out they are both beyond saving is she able to once again proclaim her love for him.
The wardrobe was very bizarre; if not ugly. It was a modernised, 80s wardrobe. Think yellow cardigans and light blue skirts for the girls, big shoulder suits and skinny ties for the men. This in turn did not work with very well with the story. Terms like castle, villagers, count, stables and servants.
One of the highlights for me was the fact that the orchestra was on the same level as you. Playing at a mere arms length away. Normally they would be tucked away somewhere below the stage but at Opera Holland Park you can watch them every moment.

Beach bumming

Last Saturday was sunny and hot and I was looking forward to Sunday when we had plans to go the East coast of England, Broadstairs.
But on Sunday the weather turned out pretty bad. Windy and with solid overcast, not giving us more than 10 minutes of sunshine throughout the day. Still there were many persons braving the weather and swimming or playing in the water.
I was amazed to see how well prepared the beach visitors were. Normally people bring a beach towel and a good book but these beach bums had so much more. Wind shields, tents, parasols, portable BBQs, crocket and more.
The highlight of the day was ice-cream and cappuccino while overlooking the main Broadstairs beach with its (in)famous rent-a-donkey.

The gym is your friend

gym, work out, diet, exercise, effective

The last 4 years I have been struggling to motivate my self and to find the time to go to the gym.
Last 6 months I have finally enjoyed regular visits and it was down to several key issues that needed to be solved. If you also have the gym urge but never seem to find time, try the advice the below.
The gym needs to be near your home or your office. Maximum a 10 minute walk/cycle/drive away.
Get a locker at the gym where you can keep some of the things necessary for your work out that don’t need washing. Running shoes, swimming trunks/goggles, boxing gloves and “cleaning products” are good candidates. Not having to lug these things back and forward will make the session more spontaneous.
Start with short and regular work-outs instead of monster passes every now and then. Once you are comfortable with the regular sessions, you can start increasing the length of the work out. A good start would be 30 minutes (not including shower and change).
Find an aerobic exercise that distracts you from the fact that you are working out. It may be boxing on a bag, reading while cycling or catching the latest movie while working the treadmill.
Force your self to put things aside when the time for work out arrives. Don’t fall into the trap of telling your self that you have too much to do and cannot go to the gym. Everything will be where you left it when you come back one hour later; you will however be refreshed. Often I find solutions or different approaches to problems while working out.
You will sleep better. You will get stronger and have more stamina. You will get a better posture. You will loose weight. You could lower your cholesterol. The gym is your friend.

Spiderman 2 – Abridged version

A short study of the changes in Peter Parker’s feelings towards his responsibilities as Spiderman
(very cool intro)
I am Spiderman; I am happy
I am Spiderman so I cannot get the girl
I am Spiderman; I am not happy
Am I Spiderman?
Am I Spiderman?
I am not Spiderman; I am very happy
I am not Spiderman; I am conflicted
I am not Spiderman but I am pissed
I am Spiderman
I am Spiderman and I can get the girl
I am Spiderman; I am happy
(credits)

Colour vs Black and White photography

One recent subject was photographed both in black and white (with an SLR camera) and in colour (with a digital camera).
I think that showing them next to each other highlights the strengths and weaknesses of the two different mediums.
Here are some more black and white photography images to feast your eyes uppon.
The black and white photo is moody and the focus is on the subject, shadows and composition.
(28-80mm, Canon EOS5, Ilford 125 FP4)
The colour photo more impresses with its range of colours and nuances.
(~35mm, Sony DSC-FX77)
Due to the low resolution, I don’t think the example highlights differences in digital format vs. 35mm film.

Wireless network available

I don’t understand.
I have the wireless card disabled on my laptop yet when I turn the laptop on, first thing it does is to notify me that a wireless network is in the vicinity and that I have to enable wireless to be able to connect to it.
Here I was thinking that switching off wireless guaranteed that no WiFi signals would enter nor exit my laptop; that I was WiFi invisible.