Thursday, 12 November 2009

The Quest for Parallelism - Slides from JFall

Yesterday, at the 2009 edition of JFall, I gave a talk about parallelism. The slides from that presentation can now be downloaded here.

For those of you who missed my talk, stay tuned to this blog. I am working out a summary article.

--JH

Technorati Tags:

Posted by jhkuperus at 11:44 AM in Java

Thursday, 5 November 2009

Easy Event-Driven Application With Spring!

Suppose you are making an event-driven application. You have your listener interfaces and your event-generating objects. What is the most annoying part of getting this all to work?

Connecting your listeners to the event-generating objects. Every time you want some object to receive certain events, you have to register your listener with the correct producer object. This has some nasty effects on your code:

  • Either your listeners know to which object they are subscribing, or your event generators know who should be listening to their events
  • Due to this coupling, listeners and producers are difficult to test
  • Adding a new listener to your project requires some boilerplate code to get it working

Spring has a feature that can take care of all of this hassle: autowiring. For normal dependency injection, autowiring feels icky. It's just too magical and leaves me with a feeling I am not in control. The great thing about autowiring is that it can be used on a per-method base.

Suppose you have a listener interface:

 1  2  3  4 public interface MyEventListener { public void onMyEvent(MyEvent me); }

And suppose you have some class that implements this interface:

 1  2  3  4  5  6  7 public class MyListener implements MyEventListener { public void onMyEvent(MyEvent me) { System.out.println("My Event was raised!"); } }

Cool, so now we still need some event-generating class:

 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 public class MyGenerator { private MyEventListener[] listeners; public void generateEvent() { MyEvent me = new MyEvent(); for (MyEventListener mel: listeners) { mel.onMyEvent(me); } } public void setMyEventListeners(MyEventListener[] listeners) { this.listeners = listeners; } }

If you looked at the above class and wondered why I've made a setter for an array of listeners, instead of a method that registers a single listener, then prepare to be amazed. If you are familiar with Spring and autowiring, you probably know where I am headed /images/emoticons/mozilla_laughing.gif.

Neither the event listener, nor the event generator have any knowledge of each other. This is perfect, we can write unittests for each class without having to mock the other. However, the event generator still needs a reference to the listener for this thing to work. Let's put these two objects in a Spring context together:

 1  2  3  4  5  6  7 <beans ...> <bean name="myGenerator" class="MyEventGenerator"/> <bean name="myListener" class="MyListener"/> </beans>

Great! Almost there, all we need now is some magic. The magic requires two components, one in the Spring config and one in the event generator class. The Spring config requires the <context:annotation-config/> tag, to enable the annotations:

 1  2  3  4  5  6  7 <beans ...> <context:annotation-config/> ... </beans>

And finally, the generator class will get its listeners autowired:

 1  2  3  4  5 @Autowire(required=false) public void setMyEventListeners(MyEventListener[] listeners) { this.listeners = listeners; }

Tada! The generator class will now automatically have an array of listeners injected into its setter. The Spring container selects all beans that are assignable to the array value type and passes them to the event generator. The required = false bit ensures Spring won't throw an exception when you have no listeners configured.

If you now want more than one bean to listen to these events, all you have to do is add a bean to the Spring config that implements the MyEventListener interface and it will automatically get added to the array. Yes, it is really that simple.

Have fun!

--JH

Technorati Tags:

Posted by jhkuperus at 6:18 PM in Java

Thursday, 29 October 2009

New: GnuPG plugin for Outlook 2007

David Cumps has gone about developing a working GPG plugin for Outlook 2007. Now you can sign your emails from Outlook 2007 using the great Open Source GPG. He describes the installation and usage at his own blog.

--JH

Technorati Tags:

Posted by jhkuperus at 5:27 PM in Java

Tuesday, 15 September 2009

New Concurrency Classes in Java 7

I just read a few posts on the new concurrency classes available in the upcoming Java 7. Altough I haven't yet had the time to dive into them, the fork-join library and parallel collections seem very promising.

See for yourself:

Technorati Tags:

Posted by jhkuperus at 11:51 AM in Java

Thursday, 13 August 2009

Eclipse Galileo and NTLMv2 Proxies

While configuring the newest installment of Eclipse, Eclipse 3.5 (Galileo), I ran into some proxy trouble. After setting the proxy-configuration, the 'Install New Software...' window would structurally say 'No repository found on <location>'.

After some Googling and researching, it appears to be a problem with Eclipse's underlying URL/Proxy handling library. This library is now Apache httpclient, which does not support NTLMv2 proxies. Luckily, there's a workaround.

If you are behind an NTLMv2 proxy, you can force Eclipse to revert its URL/Proxy handling library to the old JRE URLConnection by adding these lines to your eclipse.ini file:

-Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient
-Dhttp.proxyPort=8080
-Dhttp.proxyHost=myproxy
-Dhttp.proxyUser=mydomain\myusername
-Dhttp.proxyPassword=mypassword
-Dhttp.nonProxyHosts=localhost|127.0.0.1

If your proxy does not require authentication, you can leave out the proxyUser and proxyPassword settings.

For more information, see http://wiki.eclipse.org/ECF_Filetransfer_Support_for_NTLMv2_Proxies.

--JH

Technorati Tags:

Posted by jhkuperus at 9:49 AM in Java

Wednesday, 10 December 2008

Connecting JBoss instances through JNDI

So here I was, cleanly splitting out the service EJB and web front of an application. We even went so far as to have the two components run in separate JBoss instances, on separate machines. But... they had to communicate to each other through a JNDI lookup. That's where we ran into a ditch, fought with Java and JBoss settings for a few days and came out victorious. Let me help you stay out of these trenches and show how to configure this.

  Read more...

Technorati Tags:

Posted by jhkuperus at 9:02 PM in Java EE

Friday, 5 December 2008

Configure JBoss WS on a multiple network interfaces

The JBoss WebServices package is a nice library to get your webservice kickstarted in no-time. One of its features is the automatic generation of a WSDL for your webservice endpoint. There is however a slight annoyance when you try to use this on a machine with two network interfaces.

  Read more...

Technorati Tags:

Posted by jhkuperus at 10:52 AM in Java EE

Tuesday, 23 September 2008

SpringSource Application Platform - My Holy Grail

The SpringSource Application Platform has been in beta for some time now. In my rare free time I have been playing with it's amazing set of features. Now that the platform is nearing its final release I want to share some of my thoughts about it.

  Read more...

Technorati Tags:

Posted by jhkuperus at 11:00 AM in Java

Shameless Devoxx Promotion

On December 8th-12th, this year's Devoxx (previously JavaPolis) conference takes place in Metropolis, Antwerp. I have been to the conference last year and enjoyed the huge offer of Java talks. I would like to recommend this conference to any Java-enthousiast!

Technorati Tags:

Posted by jhkuperus at 8:44 AM in Conferences

Tuesday, 5 August 2008

EHWOTAY!

A totally nonsensical 'phrase' that has spawned its own community: EHWOTAY!. It is the calling sign of a new entity in the Userfriendly comic.

I just like it, it has a nice ring to it... EHWOTAY!

Posted by jhkuperus at 9:59 AM in Fun

Wednesday, 30 July 2008

Fools

I am currently reading 'Refactoring: Improving the Design of Existing Code' by Martin Fowler and one of his tips made me smile:

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

It made me smile because it is spot-on when it comes to clean and maintainable code. If only you, the author, understand the code, you've done something wrong! Use a clear coding style, meaningful method/type/variable names and document EVERYTHING.

Technorati Tags:

Posted by jhkuperus at 3:28 PM in Java

Tuesday, 17 June 2008

My Free Flex Training!

Today I cashed in the free training I won from Adobe. In april I visited the J-Spring conference in the Netherlands and as usual dropped my businesscard in any box that had some description with the word 'win' in it. Although I had never won anything with this before, this year I won two Flex training sessions.

  Read more...

Technorati Tags:

Posted by jhkuperus at 3:22 PM in Flex

Monday, 9 June 2008

SpringOne 2008

This year's SpringOne conference is being held this week in Antwerp, Belgium. I will be attending this conference on behalf of my employer. Blogposts about interesting talks there should show up here starting next friday. I am going to try to crosspost the same posts in Dutch at the JCN Blog.

  Read more...
Posted by jhkuperus at 1:56 PM in Conferences

Saturday, 24 May 2008

SpringSource Application Platform

As SpringSource released its first beta version of the SpringSource Application Platform (S2AP), my attention was jerked towards it. In order to get to know more about this new project from Spring I attended a webinar last week. The platform looks very promising in terms of used technologies and the features it offers.

  Read more...
Posted by jhkuperus at 1:25 PM in Java EE

Fipo!

Finally, a personal blog for me to post my thoughts on Java Core/EE, Webapp Security and whatever interesting stuff I see out there.

--JH

Posted by jhkuperus at 12:58 AM in Uncategorized