dcsimg
Multi user connections to native code
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Bill_Tucker
Posted On:   Wednesday, November 19, 2003 04:21 PM

I have Java application that will access my native code which drives a communication board. The communications board has 4 ports so I expect to have more than a single user. I am using a web interface (JSP) so I will have a distinct ID (session ID) to track the user’s requests. My issue is how to ensure that communication/notification messages are tracked on both the native and Java side because I know that update messages will be exchanged. Question, is there way to neat clean way to handle this exchange between Java and the native code using JNI? My current prototype code passes a java array and I have a Java class to handle the return events. With that all said, it just an array and very messy. If anyone has any suggestions, it would be appreciated.   More>>

I have Java application that will access my native code which drives a communication board. The communications board has 4 ports so I expect to have more than a single user. I am using a web interface (JSP) so I will have a distinct ID (session ID) to track the user’s requests. My issue is how to ensure that communication/notification messages are tracked on both the native and Java side because I know that update messages will be exchanged.

Question, is there way to neat clean way to handle this exchange between Java and the native code using JNI? My current prototype code passes a java array and I have a Java class to handle the return events. With that all said, it just an array and very messy. If anyone has any suggestions, it would be appreciated.

   <<Less

Re: Multi user connections to native code

Posted By:   Ganesh_Iyer  
Posted On:   Thursday, December 4, 2003 09:58 AM

u can pass objects to native code. And then use jni reflection calls to access the data in the object passed. This is the cleanest way, but more complicated and less efficient.

Alternatively, u could use java nio direct buffers to implement a shared memory model. in this model java nd native code operate on same memory addresses.


ie. if u use a shared java.nio..ByteBuffer the java refernce to the bytebuffer object will correspond to a pointer on the native side.




eg:- if u perform a putInt(120) on the ByteBuffer object, the native memory at that address will alo be updated.
u could simply typecast the shared memory on the native side into a struct to access the values passed in directly.
u would of course need to build a simple serializing framework to accomodate the same, but its probably worth it.



Another advantage of doing it this way is that there is absolutly no extra memory copy between java and native layer.

About | Sitemap | Contact