FXML integration, "model" concept question, multithreading with daemon threads

51 views
Skip to first unread message

mbi...@gmail.com

unread,
Oct 13, 2014, 7:20:55 AM10/13/14
to jrebirt...@googlegroups.com
Hi,

I'm porting quite a sophisticated Android application into the desktop world and as I have a lot of business logic already written in Java, JavaFx is an excellent candidat.
I found JRebirth on the "3rd party tools & utilities"JavaFX oracle's page.
First of all, congratulation for your work, looks powerfull.

I made some prototyping which raise 3 concerns :

- I would like to use FXML as the view but I can't find any example. I surely didn't look at the right place, can you help me?

- I'm a bit confused by the "model" component which sems to be in the middle of the MVC trio (as far as I understand the "model" is creating the view and the controller !). I'm familiar with MVC frameworks which decouples the model (business logic) and the view (sets of widgets to display data) where the controllers are doing the "glueing" by creating the views, adapting data from the model to fill the view, subscribing to user input from the views, calling the model accordingly and subscribing to model updates in order to update the view, etc.... Can you elaborate on that?

- My third concerns is about multithreading. I'm integrating some business logic (java libs) which are communicating with the external world with a publish/subscribe paradigm (getting events from external hardware, getting pushed infromation from a server, ...). Those libs are starting there own threads to handle there logic and the application is notified through an Observer mechanism. The typical usage scenario is :


private var _connector:Connector;

public void start() {
    _connector = new Connector();
    _connector.start(); // starts dameon threads internally
    _connector.subscribe(this); // subsribe to get information
}

public void onUpdate(.....) {
    // get notified by the connector, the UI has to be updated !
}


onUpdate method will be typically executed by a dameon threads started internally by the connector.
I'm aware of the com.sun.javafx.runtime.Entry.deferAction( Runnable mechanism, but does it integrates with JRebirth, can I send a Wave from the run method of the deferAction for example ?
can I use JRebirth "service" component to instantiate the connectors and getting notification to update the UI? From my point of view "services" are made to execute long but "endable" tasks, with progress monitoring and result callback when the task finishes, does it fit for "endless" tasks as waiting for notification forever?
Do you have any clue on this issue ?

Kind regards,

Michel

Sebastien Bordes

unread,
Oct 13, 2014, 8:19:28 AM10/13/14
to jrebirt...@googlegroups.com
Hi Michel,

Thanks for all your kind words it's always nice to hear good feedbacks !

I will try to answer to all your questions:

=> Even I'm not a fan of FXML, I have made some custom development to support them into JRebirth, there is a showcase application available here : http://jrebirth.org/showcases/FXML.html
with source code here : https://github.com/JRebirth/JRebirth/tree/master/org.jrebirth.af/showcase/fxml
(currently it's the 7.7.2 version available on the master branch, you can also choose another development branch 7.x (for 7.7.5)  or 8.x (for 8.0.0) )

It describes all ways avaible to integrate fxml into JRebirth pattern.

=> Model creates the View (if any could be NullView or an FXML file)
View creates the controller (if any could be NullController)

The Model is a Component like Command and Service, the View and the Controller are not Component.

The Controller is an UI controller used to listen JavaFX events.
The View will setup the JavaFX nodes attached to the rootNode of the Model that can be attached anywhere later by using custom command (ShowModelCommand)
The Model manage the business logic by managing optionally an Object, doing custom stuff like calling Command or Service.

This custom MVC is flexible, as you can access all parts from one by using provided getter (getModel, getView, getController).

The Model can be viewed as a Model for UI and as a controller one level up for application.

As I described here (http://jrebirth.org/doc/Introduction.html), the pattern wCS-MVC is inspired by severals other patterns to help modularization inside application.

Another element will be added by latest 8.0.0 version: Behavior, any component can have zero or several Behavior that help to do a common task. (ie: SelectBehavior that add the current Model to an Application global selection .... etc, SecurityBehavior that manage security  credentials)

8.0.0 wil also give Component modularization configured by annotation (Interface + several implementations with an authority that load the right impl according to its priority)

=> Conerning thread, all is possible, JRebirth offers a default thread management to avoid lags and freezes or deadlocks.
The deferAction is a JavaFX 1.3 method, in JavaFX 2+ you should use Platform.runLater or JRebirth.runIntoJAT that just wrap the call (Jrebirth manage 3 kind of thread, JAT, JIT, JTP+HPTP).

Services can be used as you want (like a pojo service, a computation service, wrapper service for third library)

So yes you can easily create along-living service that create your bidge (creating and listening to a socket) and on event send a Wave by calling sendWave(final Wave wave) (the wave creation will be performed into your thread, bu then the wave will be sent and consumed into the JIT one).
But don't get a Model and call one of its method directly, you won't be into the JAT.

Hope I'm answered correctly to your questions otherwise don't hesitate to re-post :D, it's always rewarding to discuss about real use cases.

Best Regard

Seb

Sebastien Bordes

unread,
Oct 13, 2014, 9:51:01 AM10/13/14
to jrebirt...@googlegroups.com
One important thing I missed to explain.

When you are in your custom thread, if you service send a wave, all routing is done is done into JIT, but if this wave is handled by a Model the handling will be performed into JAT (so useful especially since JavaFX throw exception when UI is altered from outside its graphical thread ! ).

Please also note that this default behavior can be customized by using annotation like this :

this snippet receive a wave sent from the ExpressionBuilderService and do the job into JTP. (the job is to trigger an action of another Model (StackModel))

    @OnWave(ExpressionBuilderService.TABLES_BUILT)
    @RunInto(value = RunType.JTP, priority = RunnablePriority.High)
    public void doTablesBuilt(final boolean bool, final Wave wave) {
        // When tables are built, launch the wave that will display the game menu
        sendWave(MTWaves.SHOW_PAGE, WaveData.build(MTWaves.PAGE, Page.GameMenu));
    }

Seb

Michel Bieske

unread,
Oct 13, 2014, 10:45:59 AM10/13/14
to jrebirt...@googlegroups.com
Thank you for your quick and helpful response. Very impressive. I'm continuing digging into JRebirth with a lot of success so far. 

--
Vous recevez ce message, car vous êtes abonné à un sujet dans le groupe Google Groupes "JRebirth Users".
Pour vous désabonner de ce sujet, visitez le site https://groups.google.com/d/topic/jrebirth-users/Nnvhg1fXABA/unsubscribe.
Pour vous désabonner de ce groupe et de tous ses sujets, envoyez un e-mail à l'adresse jrebirth-user...@googlegroups.com.
Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.


--
Michel Bieske

Sebastien Bordes

unread,
Oct 13, 2014, 10:53:55 AM10/13/14
to jrebirth-users
If you want to prototype something take care of the version you choose !

7.7.2 is the latest stable without regression
7.7.3 has one regression when model are removed from their parent and are listening some WaveType
7.7.4 has the same trouble but with a lower occurrence
7.7.5 will be released this week (perhaps tonight), I'm waiting feedback of another user.

8.0.0 will be released really soon (2 features remaining); some API part have changed or evolved so I advice to start new development directly with 8.0.0-SNAPSHOT except if you are stuck with Java7

Seb



--
Vous recevez ce message, car vous êtes abonné au groupe Google Groupes "JRebirth Users".
Pour vous désabonner de ce groupe et ne plus recevoir d'e-mails le concernant, envoyez un e-mail à l'adresse jrebirth-user...@googlegroups.com.

Pour obtenir davantage d'options, consultez la page https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages