Event Driven Architecture in Pico

We started a scary spike last night — putting a transparent ‘Type 3’ Event Driven architecture in Pico.

The idea is simple — suppose I have a Kissable interface:

public interface Kissable {
public void kiss();
}

I add some Kissable things to my Type3MsgPicoContainer:

container.registerMulticasted(Kissable.class, new Girl());
container.registerMulticasted(Kissable.class, new Grandmother());
container.registerMulticasted(Kissable.class, new Baby());
container.registerMulticasted(Kissable.class, new BlarneyStone());
container.registerMulticasted(Kissable.class, new Boy());

I also add something that understands how to kiss:

public class Boy{
public Boy(Kissable kissable) {...}
public void doSomeKissing()
{
kissable.kiss();
}
}
Boy boy = new Boy()
container.register(Boy.class, boy);

If I now do boy.doSomeKissing(), an event is generated and queued internally and (asynchronously) all Kissables in the system get kissed.

Joe Walnes suggested we call this ‘Type 3 Messaging’ since it hides the implementation in the same way that Pico itself does — and looks like ‘plain old message calls’.

In tha spike we did last night (you can see the source code here ) we use concrete objects and support round-robin multicasting as well.

Other strategies migt be available too — for example a pooled implementation for database components, or a transparent SEDA style architecture.

3 Responses to “Event Driven Architecture in Pico”

  1. Mike Porter Says:

    This is cool…
    But I am having one problem making a mental connection with your example.
    How does the public Boy(Kissable kissable) {…} constructor ever get called?
    I am using PicoContainer Beta1 and I usually use the registerComponent(classInterface, classImpl) methods… I understand how pico does its magic to call the correct constructor using the ‘greedy’ algorith for constructors. However in your example, you are doing a new Boy() thus bypassing the container.getComponent(classInterface) call… where I think pico must do its constructor magic.
    How is your constructor getting called?

  2. Chris Stevenson Says:

    You’re right of course - I have corrected it here: http://cgi.skizz.plus.com/blog/dev/archives/000151.html#000151

  3. Tieying Liu Says:

    I have just made this great thingy mutiple interfaces friendly. Now this loosk to be a very promising candidate for Object composition and AOP.

Leave a Reply