Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [smila-user] Calling native DLL from pipelet problem

Hi Ilias,

 

I’m not that familiar with JNI, have you also tried it without SMILA?

e.g. by just writing a simple Java class with a main() which calls your MyMethods class?

 

That’s just to make sure that your DLL can be found and is working correctly.

 

Best regards,

Andreas

 

 

Von: smila-user-bounces@xxxxxxxxxxx [mailto:smila-user-bounces@xxxxxxxxxxx] Im Auftrag von ???a? ?a?aµa???
Gesendet: Montag, 16. September 2013 12:16
An: smila-user@xxxxxxxxxxx
Betreff: [smila-user] Calling native DLL from pipelet problem

 

Hi all,

I am trying to call a native function, implemented in a dll, from inside a SMILA pipelet, but I cannot get it working. Can anyone inform me about what I am doing wrong?


The native function is declared inside a MyMethods class:

    package elias.pipelets;

    public class MyMethods
    {
        public static native void print();
       
        static
        {
            System.loadLibrary("mymethods");
        }
    }


   
The pipelet code is the following:

    package elias.pipelets;

    import org.eclipse.smila.blackboard.Blackboard;
    import org.eclipse.smila.blackboard.BlackboardAccessException;
    import org.eclipse.smila.datamodel.AnyMap;
    import org.eclipse.smila.processing.Pipelet;
    import org.eclipse.smila.processing.ProcessingException;

    public class TestPipelet1 implements Pipelet
    {
        @Override
        public String[] process(final Blackboard blackboard, final String[] recordIds) throws ProcessingException
        {
            System.out.println("Inside pipelet.");
           
            MyMethods.print();
           
            return recordIds;
        }
       
        @Override
        public void configure(final AnyMap config) throws ProcessingException
        {
           
        }
    }


   
I have created a dll called "mymethods.dll", using the JNI interface. The header file for the dll, as generated from the javah tool, is the following (elias_pipelets_MyMethods.h):

    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class elias_pipelets_MyMethods */

    #ifndef _Included_elias_pipelets_MyMethods
    #define _Included_elias_pipelets_MyMethods
    #ifdef __cplusplus
    extern "C" {
    #endif
    /*
     * Class:     elias_pipelets_MyMethods
     * Method:    print
     * Signature: ()V
     */
    JNIEXPORT void JNICALL Java_elias_pipelets_MyMethods_print
      (JNIEnv *, jclass);

    #ifdef __cplusplus
    }
    #endif
    #endif


   
The C++ code which implements the print function is the following:

    #include "elias_pipelets_MyMethods.h"
    #include <iostream>

    using namespace std;

    JNIEXPORT void JNICALL Java_elias_pipelets_MyMethods_print(JNIEnv *, jclass)
    {
        cout << "DLL speaking..." << endl;
    }


   
The code has been compiled in Visual Studio 2010. I copied the generated dll file (mymethods.dll) inside a folder called "native", inside the pipelet bundle folder. The bundle's MANIFEST.MF is the following:

    Manifest-Version: 1.0
    Bundle-ManifestVersion: 2
    Bundle-Name: Pipelets
    Bundle-SymbolicName: elias.pipelets
    Bundle-Version: 1.0.0.qualifier
    Bundle-RequiredExecutionEnvironment: JavaSE-1.6
    Import-Package: org.eclipse.smila.blackboard;version="1.1.0",
     org.eclipse.smila.datamodel;version="1.1.0",
     org.eclipse.smila.processing;version="1.1.0",
     org.eclipse.smila.processing.parameters;version="1.1.0",
     org.eclipse.smila.processing.util;version="1.1.0",
     org.eclipse.smila.utils;version="1.1.0"
    Export-Package: elias.pipelets
    Bundle-NativeCode: native/mymethods.dll;osname=win32


   
I have also included the "native" folder in the binary build. The build.properties file contains the following:

    source.. = code/src/
    output.. = code/bin/
    bin.includes = META-INF/,\
                   .,\
                   SMILA-INF/,\
                   native/

                  

I invoke the pipelet through a pipeline which is called using the REST interface. The pipelet is invoked (the "Inside pipelet." message appears), however, the system hangs when calling the MyMethods.print() method. While debugging the code, when the MyMethods.print() line is executed, it jumps inside PipeletManager, to the "finally" block of the doInvoke method.



Can anyone inform me about what I am doing wrong? Please let me know if there is any more information that you need from me.

Thank you very much in advance.

Ilias Kalamaras


Back to the top