use of com.bluenimble.platform.server.ServerFeature 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;
}
});
}
use of com.bluenimble.platform.server.ServerFeature in project serverless by bluenimble.
the class RemotePlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Remote.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
PackageClassLoader pcl = (PackageClassLoader) RemotePlugin.class.getClassLoader();
pcl.registerObject(Protocol.http.name(), new HttpRemote(null));
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = -9012279234275100528L;
@Override
public Class<?> type() {
return Remote.class;
}
@Override
public Object get(ApiSpace space, String name) {
return remotes.get(createRemoteKey(name, space));
}
@Override
public String provider() {
return RemotePlugin.this.getName();
}
@Override
public Plugin implementor() {
return RemotePlugin.this;
}
});
}
use of com.bluenimble.platform.server.ServerFeature in project serverless by bluenimble.
the class AbstractApiServer method getFeature.
@Override
public Object getFeature(ApiSpace space, Class<?> type, String name) {
Feature aFeature = type.getAnnotation(Feature.class);
JsonObject oFeature = Json.getObject(space.getFeatures(), aFeature.name());
if (oFeature == null || oFeature.isEmpty()) {
throw new FeatureNotFoundException("feature " + aFeature.name() + " not available in space " + space.getNamespace());
}
JsonObject oProvider = Json.getObject(oFeature, name);
if (oProvider == null || oProvider.isEmpty()) {
throw new FeatureNotFoundException("feature provider " + name + " not available in space " + space.getNamespace());
}
String provider = Json.getString(oProvider, ApiSpace.Features.Provider);
if (Lang.isNullOrEmpty(provider)) {
throw new FeatureNotFoundException("provider for feature " + aFeature.name() + Lang.SLASH + name + " is missing");
}
ServerFeature feature = features.get(aFeature.name() + FeatureProtocol + provider);
if (feature == null) {
throw new FeatureNotFoundException("feature " + name + Lang.COLON + aFeature.name() + FeatureProtocol + provider + " not found");
}
return feature.get(space, name);
}
use of com.bluenimble.platform.server.ServerFeature in project serverless by bluenimble.
the class ElasticSearchPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Indexer.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = -9012279234275100528L;
@Override
public Class<?> type() {
return Indexer.class;
}
@Override
public Object get(ApiSpace space, String name) {
String remotePluginName = Json.getString(remote, Spec.RemotePlugin);
String remoteObjectId = Json.getString(remote, Spec.RemoteObject);
if (Lang.isNullOrEmpty(remotePluginName) || Lang.isNullOrEmpty(remoteObjectId)) {
return null;
}
Plugin pRemote = server.getPluginsRegistry().lockup(Json.getString(remote, Spec.RemotePlugin));
if (pRemote == null) {
return null;
}
PackageClassLoader pcl = (PackageClassLoader) pRemote.getClass().getClassLoader();
Remote iRemote = (Remote) pcl.lookupObject(Json.getString(remote, Spec.RemoteObject));
if (iRemote == null) {
return null;
}
// build basic auth and url
String token = buildAuthToken(space, name);
if (Lang.isNullOrEmpty(token)) {
return null;
}
String url = buildUrl(space, name);
if (Lang.isNullOrEmpty(url)) {
return null;
}
return new ElasticSearchIndexer(iRemote, url, token, tracer());
}
@Override
public String provider() {
return ElasticSearchPlugin.this.getName();
}
@Override
public Plugin implementor() {
return ElasticSearchPlugin.this;
}
});
}
use of com.bluenimble.platform.server.ServerFeature in project serverless by bluenimble.
the class SmtpMessengerPlugin method init.
@Override
public void init(final ApiServer server) throws Exception {
Feature aFeature = Messenger.class.getAnnotation(Feature.class);
if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
return;
}
feature = aFeature.name();
server.addFeature(new ServerFeature() {
private static final long serialVersionUID = 3585173809402444745L;
@Override
public Class<?> type() {
return Messenger.class;
}
@Override
public Object get(ApiSpace space, String name) {
return ((RecyclableMessenger) (space.getRecyclable(createKey(name)))).messenger();
}
@Override
public String provider() {
return SmtpMessengerPlugin.this.getName();
}
@Override
public Plugin implementor() {
return SmtpMessengerPlugin.this;
}
});
}
Aggregations