use of com.bluenimble.platform.api.impls.scripting.ScriptableApiSpi in project serverless by bluenimble.
the class ScriptingPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
if (Lang.isNullOrEmpty(vmArgs)) {
masterEngine = Manager.getScriptEngine(ScriptingPlugin.class.getClassLoader());
} else {
masterEngine = Manager.getScriptEngine(Lang.split(vmArgs, Lang.SPACE, true), ScriptingPlugin.class.getClassLoader());
}
Feature aFeature = ScriptingEngine.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
PackageClassLoader pcl = (PackageClassLoader) ScriptingPlugin.class.getClassLoader();
pcl.registerObject(Registered.ApiSpi, new ScriptableApiSpi());
pcl.registerObject(Registered.ServiceSpi, new ScriptableApiServiceSpi());
File platform = new File(home, "platform");
// load platform
Reader pReader = null;
try {
pReader = new FileReader(new File(platform, "Platform.js"));
Bindings bindings = new SimpleBindings();
bindings.put(Vars.Core, new File(platform, Vars.Core).getAbsolutePath());
bindings.put(Vars.Tools, new File(platform, Vars.Tools).getAbsolutePath());
shared = new DefaultScriptingEngine(this, (ScriptObjectMirror) masterEngine.eval(pReader, bindings), server.getMapProvider());
} finally {
IOUtils.closeQuietly(pReader);
}
// add features
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 2626039344401539390L;
@Override
public Class<?> type() {
return ScriptingEngine.class;
}
@Override
public Object get(ApiSpace space, String name) {
return shared;
}
@Override
public String provider() {
return ScriptingPlugin.this.getName();
}
@Override
public Plugin implementor() {
return ScriptingPlugin.this;
}
});
}
Aggregations