Search in sources :

Example 1 with ElasticSearchIndexer

use of com.bluenimble.platform.indexer.impls.ElasticSearchIndexer 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)

Aggregations

Feature (com.bluenimble.platform.Feature)1 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)1 ApiSpace (com.bluenimble.platform.api.ApiSpace)1 ElasticSearchIndexer (com.bluenimble.platform.indexer.impls.ElasticSearchIndexer)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 Plugin (com.bluenimble.platform.plugins.Plugin)1 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)1 Remote (com.bluenimble.platform.remote.Remote)1 ServerFeature (com.bluenimble.platform.server.ServerFeature)1