Omaha #3427 decoder interface now takes full path to jar

Change-Id: I8212017cce74cb70314a2a6f72fad72f59ff19fb

Former-commit-id: d745579877 [formerly cdd64aa7ea] [formerly 32d46b0155] [formerly d745579877 [formerly cdd64aa7ea] [formerly 32d46b0155] [formerly 516575c326 [formerly 32d46b0155 [formerly 1aee051869b8aac10a233a142f758fdca82c11ab]]]]
Former-commit-id: 516575c326
Former-commit-id: b26b0e72e4 [formerly fb25c54535] [formerly 959325420c693265f9face50a7386eed5ccbc2e7 [formerly 3687dd978c]]
Former-commit-id: 9a06ec0f15ed14fd98ccb9c8c34230f0152aa3d2 [formerly 7b83403a1b]
Former-commit-id: 9d37d84624
This commit is contained in:
Brian Clements 2014-08-04 09:03:53 -05:00
parent 75d49eb9f6
commit c46863dc8f
2 changed files with 11 additions and 8 deletions

View file

@ -20,6 +20,7 @@
package com.raytheon.uf.edex.python.decoder; package com.raytheon.uf.edex.python.decoder;
import java.io.File; import java.io.File;
import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
import jep.JepException; import jep.JepException;
@ -46,6 +47,7 @@ import com.raytheon.uf.edex.core.EDEXUtil;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Apr 2, 2009 njensen Initial creation * Apr 2, 2009 njensen Initial creation
* Jul 10, 2014 2914 garmendariz Remove EnvProperties * Jul 10, 2014 2914 garmendariz Remove EnvProperties
* Aug 04, 2014 3427 bclement decoder interface now takes full path to jar
* *
* </pre> * </pre>
* *
@ -88,13 +90,15 @@ public class PythonDecoderFactory {
* python module. Synchronized as zipimport has race condition that only * python module. Synchronized as zipimport has race condition that only
* allows one interpreter to load a given jar file at a time. * allows one interpreter to load a given jar file at a time.
* *
* @param pluginName * @param pluginFQN
* @param moduleName
* @return * @return
* @throws Exception * @throws Exception
*/ */
public static synchronized PythonScript makePythonDecoder(String pluginFQN, public static synchronized PythonScript makePythonDecoder(String pluginFQN,
String moduleName) throws Exception { String moduleName) throws Exception {
PythonScript py = null; PythonScript py = null;
String jarpath = Paths.get(pluginDir, pluginFQN + ".jar").toString();
int retryCount = 0; int retryCount = 0;
// we try multiple times cause once in a blue moon we get an error on // we try multiple times cause once in a blue moon we get an error on
// zlib that is an extremely rare fluke // zlib that is an extremely rare fluke
@ -104,13 +108,12 @@ public class PythonDecoderFactory {
py = new PythonScript(decoderInterface, includePath, py = new PythonScript(decoderInterface, includePath,
PythonDecoder.class.getClassLoader()); PythonDecoder.class.getClassLoader());
HashMap<String, Object> argMap = new HashMap<String, Object>(); HashMap<String, Object> argMap = new HashMap<String, Object>();
argMap.put("pluginDir", pluginDir); argMap.put("jarpath", jarpath);
argMap.put("pluginFQN", pluginFQN);
argMap.put("moduleName", moduleName); argMap.put("moduleName", moduleName);
py.execute("loadModule", argMap); py.execute("loadModule", argMap);
} catch (JepException e) { } catch (JepException e) {
logger.error( logger.error("Error instantiating python decoder " + moduleName
"Error instantiating python decoder " + moduleName, e); + " from jar " + jarpath, e);
if (py != null) { if (py != null) {
py.dispose(); py.dispose();
py = null; py = null;

View file

@ -34,14 +34,14 @@ from java.util import ArrayList
# ------------- -------- ----------- -------------------------- # ------------- -------- ----------- --------------------------
# Sep 22, 2008 njensen Initial Creation. # Sep 22, 2008 njensen Initial Creation.
# Oct 03, 2013 2402 bsteffen Make PythonDecoder more extendable. # Oct 03, 2013 2402 bsteffen Make PythonDecoder more extendable.
# Aug 04, 2014 3427 bclement loadModule() now takes full path to jar
# #
# #
# #
def loadModule(pluginDir, pluginFQN, moduleName): def loadModule(jarpath, moduleName):
jarname = pluginDir + pluginFQN + ".jar"
if not sys.modules.has_key(moduleName): if not sys.modules.has_key(moduleName):
jar = zipimport.zipimporter(jarname) jar = zipimport.zipimporter(jarpath)
jar.load_module(moduleName) jar.load_module(moduleName)
def decode(moduleName, **kwargs): def decode(moduleName, **kwargs):