holds the singleton for UDFs
| 52 | |
| 53 | /** holds the singleton for UDFs */ |
| 54 | private static final class Holder { |
| 55 | static JsScriptEngine instance; |
| 56 | static { |
| 57 | if (clientInstance!=null) { |
| 58 | /** on client side UDFs re-use the same instance */ |
| 59 | instance = clientInstance; |
| 60 | } else { |
| 61 | /** on the hadoop slave a new instance is created using the UDFContext for initialization */ |
| 62 | instance = new JsScriptEngine(); |
| 63 | String scriptPath = (String) UDFContext.getUDFContext().getUDFProperties(JsFunction.class).get(JsScriptEngine.class.getName()+".scriptFile"); |
| 64 | instance.scriptPath = scriptPath; |
| 65 | if (scriptPath == null) { |
| 66 | throw new IllegalStateException("could not get script path from UDFContext"); |
| 67 | } |
| 68 | InputStream is = getScriptAsStream(scriptPath); |
| 69 | try { |
| 70 | instance.load(scriptPath, is); |
| 71 | } finally { |
| 72 | try { |
| 73 | is.close(); |
| 74 | } catch (IOException e) { |
| 75 | LOG.warn("Could not close stream for file "+scriptPath, e); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | public static JsScriptEngine getInstance() { |
| 84 | JsScriptEngine instance = Holder.instance; |
nothing calls this directly
no test coverage detected