JacpFX messaging

Messaging is an essential part of JacpFX. JacpFX components (workbench, perspectives, components) have no direct reference to each other and communicate via messages. Every component has a message box and handles it's messages sequential, similar to an actor.

messaging

To send a message the JacpFX context contains following two methods:

sending a message to yourself

@Resource
private Context context;   
...    
context.send("message");

This can be interesting when you want to execute methods in a worker thread. (see non blocking UI)


sending a message to a specific Component

context.send(ComponentIds.COMPONENT_ONE,"message");


Message lifecycle

To handle a message, the JacpFX Component interfaces defines two methods which will be called sequential:

public Node handle(final Message message) {
        // runs in worker thread
        return null;
    }


and

public Node postHandle(final Node arg0,
                           final Message message) {
        // runs in FX application thread
        return null;
    }

While the "handle" method will be executed in a worker thread, the "postHandle" method is always executed on the FX application thread. For details about the Component lifecycle see the documentation about async execution

shadow