I''ll post some of my discussion with Paul here. Appreciate all your thoughts.
I'm up with the task of converting some existing Java code and C++ code to FBP. Our Java group would have full control of the Java side but not the C++ side. From the past experience (nightmare) of JNI coding/debugging, I think using the concept of FBP to isolate the Java and C++ threads would simplify things.
Listed in my email to Paul:
- FBP can be implemented in any languages.
- Java components and C++ components can send messages mutually.
- Reducing JNI method invocation is a great saving.
- Avoiding native threads calling into Java will save BIG debugging efforts.
- Could be combined with Jace - a free, open source toolkit that lets you easily write JNI code.
Paul responded, "are you saying that we could have Java processes talking to C++ processes in the same network? If so, how would a C++ process talk to a JFBP Connection, which is a Java object? I'm guessing that you can invoke a C++ module from a Java Thread, and somehow pass it the handles of one or more Java objects, which would look like pointers? "
Some direct anwsers to the latter 2 questions:
- Any C++ object can invoke Java objects' methods, vice versa, through JNI.
- The mappings of objects or primitive data types exchanged between Java and C++ are done in JNI library, and simplified in JACE library. Yes, pointers or references in C++.
My thoughts on the first question now is a little different. Practically I don't want to rework any part of our large C++ codebase. So I tend not want to have C++ processes as first-class citizens in a network. A Java wrapper component would provide the functionality of the C++ code to the network. The "Network" Java class only knows about Java objects anyway. Inside such a JNI component (contrary to pure Java component), Java wrapper component's execute() method can then invoke native methods in C++ library through raw JNI or JACE interface.
Of course the situation is different if the C++ code is already first-class FBP processes using some package like THREADS. Then integrating the Java processes and C++ processes into one network would be the matter of making some "JNI connections". I haven't thought throught the details on that.