MCPcopy Create free account
hub / github.com/apache/pig / Holder

Class Holder

src/org/apache/pig/scripting/js/JsScriptEngine.java:54–81  ·  view source on GitHub ↗

holds the singleton for UDFs

Source from the content-addressed store, hash-verified

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;

Callers

nothing calls this directly

Calls 8

getUDFContextMethod · 0.95
getScriptAsStreamMethod · 0.80
getMethod · 0.65
closeMethod · 0.65
warnMethod · 0.65
getUDFPropertiesMethod · 0.45
getNameMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected