Search in sources :

Example 1 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader 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;
        }
    });
}
Also used : ScriptObjectMirror(jdk.nashorn.api.scripting.ScriptObjectMirror) DefaultScriptingEngine(com.bluenimble.platform.api.scripting.impls.DefaultScriptingEngine) Reader(java.io.Reader) FileReader(java.io.FileReader) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) Bindings(javax.script.Bindings) SimpleBindings(javax.script.SimpleBindings) ScriptableApiServiceSpi(com.bluenimble.platform.api.impls.scripting.ScriptableApiServiceSpi) ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) SimpleBindings(javax.script.SimpleBindings) ScriptableApiSpi(com.bluenimble.platform.api.impls.scripting.ScriptableApiSpi) FileReader(java.io.FileReader) File(java.io.File) PackageClassLoader(com.bluenimble.platform.PackageClassLoader) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 2 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader in project serverless by bluenimble.

the class Log4JTracerPlugin method init.

@Override
public void init(ApiServer server) throws Exception {
    PackageClassLoader pcl = (PackageClassLoader) Log4JTracerPlugin.class.getClassLoader();
    pcl.addSynonym(Synonyms.Default, DefaultTracer.class.getName());
}
Also used : DefaultTracer(com.bluenimble.platform.tracing.impls.log4j.DefaultTracer) PackageClassLoader(com.bluenimble.platform.PackageClassLoader)

Example 3 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader 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;
        }
    });
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) HttpRemote(com.bluenimble.platform.remote.impls.http.HttpRemote) ApiSpace(com.bluenimble.platform.api.ApiSpace) JsonObject(com.bluenimble.platform.json.JsonObject) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) PackageClassLoader(com.bluenimble.platform.PackageClassLoader) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 4 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader 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;
        }
    });
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) Remote(com.bluenimble.platform.remote.Remote) JsonObject(com.bluenimble.platform.json.JsonObject) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) PackageClassLoader(com.bluenimble.platform.PackageClassLoader) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin) ElasticSearchIndexer(com.bluenimble.platform.indexer.impls.ElasticSearchIndexer)

Example 5 with PackageClassLoader

use of com.bluenimble.platform.PackageClassLoader in project serverless by bluenimble.

the class IMPlugin method init.

@Override
public void init(ApiServer server) throws Exception {
    PackageClassLoader pcl = (PackageClassLoader) IMPlugin.class.getClassLoader();
    pcl.registerObject(Registered.LoginSpi, new LoginServiceSpi());
    pcl.registerObject(Registered.SignupSpi, new SignupServiceSpi());
    pcl.registerObject(Registered.ActivateSpi, new ActivateServiceSpi());
    pcl.registerObject(Registered.OAuthSpi, new OAuthServiceSpi());
    pcl.registerObject(Registered.ChangePasswordSpi, new ChangePasswordSpi());
    pcl.registerObject(Registered.ResendActivationSpi, new ResendActivationRequestSpi());
}
Also used : ResendActivationRequestSpi(com.bluenimble.platform.api.impls.im.ResendActivationRequestSpi) SignupServiceSpi(com.bluenimble.platform.api.impls.im.SignupServiceSpi) ActivateServiceSpi(com.bluenimble.platform.api.impls.im.ActivateServiceSpi) LoginServiceSpi(com.bluenimble.platform.api.impls.im.LoginServiceSpi) ChangePasswordSpi(com.bluenimble.platform.api.impls.im.ChangePasswordSpi) OAuthServiceSpi(com.bluenimble.platform.api.impls.im.OAuthServiceSpi) PackageClassLoader(com.bluenimble.platform.PackageClassLoader)

Aggregations

PackageClassLoader (com.bluenimble.platform.PackageClassLoader)8 Feature (com.bluenimble.platform.Feature)3 ApiSpace (com.bluenimble.platform.api.ApiSpace)3 JsonObject (com.bluenimble.platform.json.JsonObject)3 Plugin (com.bluenimble.platform.plugins.Plugin)3 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)3 ServerFeature (com.bluenimble.platform.server.ServerFeature)3 File (java.io.File)3 ActivateServiceSpi (com.bluenimble.platform.api.impls.im.ActivateServiceSpi)1 ChangePasswordSpi (com.bluenimble.platform.api.impls.im.ChangePasswordSpi)1 LoginServiceSpi (com.bluenimble.platform.api.impls.im.LoginServiceSpi)1 OAuthServiceSpi (com.bluenimble.platform.api.impls.im.OAuthServiceSpi)1 ResendActivationRequestSpi (com.bluenimble.platform.api.impls.im.ResendActivationRequestSpi)1 SignupServiceSpi (com.bluenimble.platform.api.impls.im.SignupServiceSpi)1 ScriptableApiServiceSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiServiceSpi)1 ScriptableApiSpi (com.bluenimble.platform.api.impls.scripting.ScriptableApiSpi)1 DefaultScriptingEngine (com.bluenimble.platform.api.scripting.impls.DefaultScriptingEngine)1 ElasticSearchIndexer (com.bluenimble.platform.indexer.impls.ElasticSearchIndexer)1 Remote (com.bluenimble.platform.remote.Remote)1 HttpRemote (com.bluenimble.platform.remote.impls.http.HttpRemote)1