java - JNI wrapper or alternative for callbacks -
i need call java native library , requires callback registration (and using callbacks then).
is there wrapper on jni or jni alternative such situation? seems jna, hawtjni , others not support callbacks java ...
thank you!
let have method in our c library notify application if record has been deleted process. provides method add callback,
int register_delete_monitor( void* fn);
and callback expected takes parameter of record.
in our java library, create callback method:
interface deletedrecordcallback extends callback { void callback (record r); } ... // , in our library interface: int register_delete_monitor (deletedrecordcallback drc);
now can pass in implementation of our deletedrecordcallback , have registered callback in c library.
there 1 caveat use of callbacks in jna. callback must not garbage collected unless it's been unregistered. true long lived callbacks. call garbage-collected callback crash vm. can avoided hanging on instance of callback - singleton work quite in context. otherwise, important have callback instance deregister in it's finalize method.
Comments
Post a Comment