Discussions

General J2EE: jni

  1. jni (6 messages)

    Hello,
    I wanted to know how to implement jni from EJB.
    Do u guys have any specific way of implementation for jni with J2EE?
    Plz let me know the possibilites of implementation.

    thanks in advance.

    with regards,
    NRK.

    Threaded Messages (6)

  2. jni[ Go to top ]

    EJB -> RMI -> JNI
  3. jni[ Go to top ]

    Hello Ravi,
        Thanks for the input.
    But it was too short.
    Can u plz explain in me in detail how to implement that?

    Thanks n advance.

    with regards,
    Radhakrishnan
  4. jni[ Go to top ]

    Run an RMI server outside the weblogic JVM, and make the JNI calls from there. From the EJB, just lookup the RMI server and call the remote method, passing in whatever data is needed. The RMI server-side implementation does the JNI call and returns the results.

    Here is a way of doing it that makes the RMI server transparent to the rest of your application code.

    1. Define one or more java interfaces through which you will make your JNI calls. Let's call this MyJNI. This is not an RMI interface, it just contains the methods which you need for your Java <-> Native interaction.

    2. Implement this interface. In the implementation, you do your JNI call. This implementation is also not RMI-aware. Call this MyJNIImpl.

    3. Write a program that takes this interface and generates an RMI interface and server implementation wrapping this interface. This is very easily done using reflection. Call these MyJNIRemote and MyJNIRemoteImpl. Of course, you can also hand-code these classes if there aren't too many.

    4. MyJNIRemote interface has the same method signatures as MyJNI, except that it throws RemoteException.

    5. MyJNIRemoteImpl just instantiates MyJNIImpl and delegates all method calls.

    6. Write a class MyJNIFacade, which implements the MyJNI interface. MyJNIFacade encapsulates the RMI/JNDI lookup for MyJNIRemote. MyJNIFacade can also be one of the outputs of the tool you wrote in step 3.

    7. From your EJB, just instantiate MyJNIFacade and start calling the methods in its MyJNI interface. The sequence of invocations will be as follows:
    EJB -> MyJNIFacade --(RMI)--> MyJNIRemoteImpl -> MyJNIImpl -> Native code. And back the same way.

    And the point is, neither your EJB nor the MyJNIImpl class is aware of an RMI pipe in the middle. So, if you need to get rid of RMI for some reason, all you have to do is to change MyJNIFacade to directly invoke MyJNIImpl and you are done.
  5. jni[ Go to top ]

    Hello Ravi,
        Thanks a lot for the detailed explanation.
    It was very useful.
    I will try to implement that.

    On curious i like to know whether u have any idea on some EIS Resource Adapters.
    If so plz let me know at nrk74 at yahoo dot com.

    with regards,
    Radhakrishnan.
  6. jni[ Go to top ]

    Ravi,
       I didn't follow your 3rd step.

    Can u plz provide some more details or some example code?
    Thanks in advance.

    with regards,
    Radhakrishnan.
  7. jni[ Go to top ]

    Hello Ravi,
        Thanks for the input.
    But it was too short.
    Can u plz explain in me in detail how to implement that?

    Thanks n advance.

    with regards,
    Radhakrishnan