Working on migration projects, I often have to share data between the old Swing part and the new JavaFX part.
To send data in a SE-environment from part A to part B you can use a MessageBus. Based on the Guava – EventBus
you can use the cdi-commons MessageBus now.
The code is available at (https://bitbucket.org/svenruppert/cdi-commons)
On producer and consumer – side you will get the MessageBus per inject.
The consumer has to implement an MessageBusCallback<T> with the consumer method.
An example is available as jUnit-Test (MessageBusTest)
The Class TestCallbackData is a pojo itself.
After you register the Callback instance with messageBus.registerCallBack(callBack); the consumer is ready to work.
If you don´t want to get the messages anymore, call messageBus.destroyCallBack(callBack);
The producer “only” has to fill the message with the data and send this via messageBus.post(message); Thats it!!
Finally the full UML-diagramm.