Browse Source

HPCC-14246 Allow DynamicESDL service methods to be written in JAVA

Fix some build issues.

Load java plugin dynamically so that jvm is only loaded when the feature is
used.

Signed-off-by: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 9 years ago
parent
commit
e1dcd8507c

+ 3 - 0
esp/services/esdl_svc_engine/CMakeLists.txt

@@ -48,6 +48,7 @@ include_directories (
          ${HPCC_SOURCE_DIR}/system/mp
          ${HPCC_SOURCE_DIR}/common/deftype
          ${HPCC_SOURCE_DIR}/common/environment
+         ${HPCC_SOURCE_DIR}/common/dllserver 
          ${HPCC_SOURCE_DIR}/common/thorhelper
          ${HPCC_SOURCE_DIR}/common/workunit
          ${HPCC_SOURCE_DIR}/common/wuwebview
@@ -57,6 +58,7 @@ include_directories (
          ${HPCC_SOURCE_DIR}/esp/esdllib
          ${HPCC_SOURCE_DIR}/esp/logging
          ${CMAKE_BINARY_DIR}
+         ${CMAKE_BINARY_DIR}/oss
     )
 
 ADD_DEFINITIONS( -D_USRDLL )
@@ -77,6 +79,7 @@ target_link_libraries ( esdl_svc_engine
          remote
          dalibase
          esdllib
+         dllserver
     )
 
 IF (USE_OPENSSL)

+ 19 - 0
esp/services/esdl_svc_engine/esdl_binding.hpp

@@ -25,6 +25,7 @@
 #include "jptree.hpp"
 #include "xsdparser.hpp"
 #include "loggingmanager.h"
+#include "thorplugin.hpp"
 #include "eclrtl.hpp"
 
 static const char* ESDL_DEFS_ROOT_PATH="/ESDL/Definitions/";
@@ -63,7 +64,9 @@ static const char* ESDL_METHOD_HELP="help";
 #define REQ_REF_NUM_NAME    "_req_ref_num"
 #define MCACHE_OBJECT_KEY   "_mcache_object_key_"
 
+#ifdef LINK_STATICALLY  // May be useful for debugging...
 namespace javaembed { IEmbedContext* getEmbedContext(); }
+#endif
 
 class EsdlServiceImpl : public CInterface, implements IEspService
 {
@@ -72,8 +75,12 @@ private:
     MapStringToMyClass<ISmartSocketFactory> connMap;
     MapStringToMyClass<IEmbedServiceContext> javaServiceMap;
     Owned<ILoggingManager> loggingManager;
+#ifndef LINK_STATICALLY
+    Owned<ILoadedDllEntry> javaPluginDll;
+#endif
     Owned<IEmbedContext> javaplugin;
 
+
 public:
     StringBuffer                m_espServiceType;
     StringBuffer                m_espServiceName;
@@ -96,7 +103,19 @@ public:
     IEmbedContext &ensureJavaEmbeded()
     {
         if (!javaplugin)
+        {
+#ifdef LINK_STATICALLY  // May be useful for debugging...
             javaplugin.setown(javaembed::getEmbedContext());
+#else
+            javaPluginDll.setown(createDllEntry("javaembed", false, NULL));
+            if (!javaPluginDll)
+                throw makeStringException(0, "Failed to load javaembed plugin");
+            GetEmbedContextFunction pf = (GetEmbedContextFunction) javaPluginDll->getEntry("getEmbedContextDynamic");
+            if (!pf)
+                throw makeStringException(0, "Failed to load javaembed plugin");
+            javaplugin.setown(pf());
+#endif
+            }
         return *javaplugin;
     }
 

+ 2 - 0
esp/services/ws_esdlconfig/CMakeLists.txt

@@ -35,6 +35,7 @@ set (    SRCS
 include_directories (
          ${HPCC_SOURCE_DIR}/dali/base
          ${HPCC_SOURCE_DIR}/common/environment
+         ${HPCC_SOURCE_DIR}/common/dllserver
          ${HPCC_SOURCE_DIR}/system/include
          ${HPCC_SOURCE_DIR}/system/jlib
          ${HPCC_SOURCE_DIR}/system/security/shared
@@ -62,4 +63,5 @@ target_link_libraries ( ws_esdlconfig
          jlib
          esphttp
          environment
+         dllserver
     )

+ 7 - 0
plugins/javaembed/javaembed.cpp

@@ -3173,3 +3173,10 @@ JNIEXPORT jobject JNICALL Java_com_HPCCSystems_HpccUtils__1next (JNIEnv *JNIenv,
         return NULL;
     }
 }
+
+// Used for dynamically loading in ESDL
+
+extern "C" EXPORT IEmbedContext *getEmbedContextDynamic()
+{
+    return javaembed::getEmbedContext();
+}

+ 2 - 0
rtl/eclrtl/eclrtl.hpp

@@ -836,4 +836,6 @@ interface IEmbedContext : extends IInterface
     // MORE - add syntax checked here!
 };
 
+typedef IEmbedContext * (* GetEmbedContextFunction)();
+
 #endif