Search in sources :

Example 36 with ApiSpace

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

Example 37 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class FileSystemStoragePlugin method init.

@Override
public void init(final ApiServer server) throws Exception {
    Feature aFeature = Storage.class.getAnnotation(Feature.class);
    if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
        return;
    }
    feature = aFeature.name();
    if (!Lang.isNullOrEmpty(root)) {
        fRoot = new File(root);
    }
    if (!fRoot.exists()) {
        fRoot.mkdirs();
    }
    server.addFeature(new ServerFeature() {

        private static final long serialVersionUID = -9012279234275100528L;

        @Override
        public Class<?> type() {
            return Storage.class;
        }

        @Override
        public Object get(ApiSpace space, String name) {
            String mount = mounts.get(createStorageKey(name, space));
            if (mount == null) {
                return null;
            }
            return new FileSystemStorage(mount, new File(fRoot, mount));
        }

        @Override
        public String provider() {
            return FileSystemStoragePlugin.this.getName();
        }

        @Override
        public Plugin implementor() {
            return FileSystemStoragePlugin.this;
        }
    });
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) FileSystemStorage(com.bluenimble.platform.storage.impls.FileSystemStorage) JsonObject(com.bluenimble.platform.json.JsonObject) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) File(java.io.File) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 38 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class MemCachedPlugin method init.

@Override
public void init(final ApiServer server) throws Exception {
    Feature aFeature = Cache.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 Cache.class;
        }

        @Override
        public Object get(ApiSpace space, String name) {
            return new MemCachedCache(((RecyclableCacheClient) (space.getRecyclable(createKey(name)))).client());
        }

        @Override
        public String provider() {
            return MemCachedPlugin.this.getName();
        }

        @Override
        public Plugin implementor() {
            return MemCachedPlugin.this;
        }
    });
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) MemCachedCache(com.bluenimble.platform.cache.impls.memcached.MemCachedCache) JsonObject(com.bluenimble.platform.json.JsonObject) Feature(com.bluenimble.platform.Feature) ServerFeature(com.bluenimble.platform.server.ServerFeature) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 39 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class MongoDatabasePlugin method init.

// private int 				weight;
@Override
public void init(final ApiServer server) throws Exception {
    // weight = server.weight ();
    Feature aFeature = Database.class.getAnnotation(Feature.class);
    if (aFeature == null || Lang.isNullOrEmpty(aFeature.name())) {
        return;
    }
    feature = aFeature.name();
    // add features
    server.addFeature(new ServerFeature() {

        private static final long serialVersionUID = 2626039344401539390L;

        @Override
        public Class<?> type() {
            return Database.class;
        }

        @Override
        public Object get(ApiSpace space, String name) {
            return new MongoDatabaseImpl(MongoDatabasePlugin.this.acquire(space, name), tracer());
        }

        @Override
        public Plugin implementor() {
            return MongoDatabasePlugin.this;
        }

        @Override
        public String provider() {
            return MongoDatabasePlugin.this.getName();
        }
    });
    codecRegistry = CodecRegistries.fromRegistries(MongoClient.getDefaultCodecRegistry(), CodecRegistries.fromProviders(PojoCodecProvider.builder().automatic(true).build()));
}
Also used : ServerFeature(com.bluenimble.platform.server.ServerFeature) ApiSpace(com.bluenimble.platform.api.ApiSpace) MongoDatabaseImpl(com.bluenimble.platform.plugins.database.mongodb.impls.MongoDatabaseImpl) JsonObject(com.bluenimble.platform.json.JsonObject) ServerFeature(com.bluenimble.platform.server.ServerFeature) Feature(com.bluenimble.platform.Feature) Plugin(com.bluenimble.platform.plugins.Plugin) AbstractPlugin(com.bluenimble.platform.plugins.impls.AbstractPlugin)

Example 40 with ApiSpace

use of com.bluenimble.platform.api.ApiSpace in project serverless by bluenimble.

the class MongoDatabasePlugin method onEvent.

@Override
public void onEvent(Event event, Object target) throws PluginRegistryException {
    if (!ApiSpace.class.isAssignableFrom(target.getClass())) {
        return;
    }
    tracer().log(Tracer.Level.Info, "onEvent {0}, target {1}", event, target.getClass().getSimpleName());
    ApiSpace space = (ApiSpace) target;
    switch(event) {
        case Create:
            createClients(space);
            break;
        case AddFeature:
            // if it's database and provider is 'mongodb' create clients
            createClients(space);
            break;
        case DeleteFeature:
            // if it's database and provider is 'mongodb' stop factory
            dropClients(space);
            break;
        default:
            break;
    }
}
Also used : ApiSpace(com.bluenimble.platform.api.ApiSpace)

Aggregations

ApiSpace (com.bluenimble.platform.api.ApiSpace)48 JsonObject (com.bluenimble.platform.json.JsonObject)33 ApiServiceExecutionException (com.bluenimble.platform.api.ApiServiceExecutionException)31 ApiAccessDeniedException (com.bluenimble.platform.api.ApiAccessDeniedException)27 JsonApiOutput (com.bluenimble.platform.api.impls.JsonApiOutput)27 Feature (com.bluenimble.platform.Feature)10 Plugin (com.bluenimble.platform.plugins.Plugin)10 ServerFeature (com.bluenimble.platform.server.ServerFeature)10 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)9 Database (com.bluenimble.platform.db.Database)8 DatabaseException (com.bluenimble.platform.db.DatabaseException)8 Storage (com.bluenimble.platform.storage.Storage)6 StorageException (com.bluenimble.platform.storage.StorageException)6 StorageObject (com.bluenimble.platform.storage.StorageObject)6 ApiManagementException (com.bluenimble.platform.api.ApiManagementException)5 KeyPair (com.bluenimble.platform.security.KeyPair)5 Api (com.bluenimble.platform.api.Api)4 DatabaseObject (com.bluenimble.platform.db.DatabaseObject)4 JsonArray (com.bluenimble.platform.json.JsonArray)4 PackageClassLoader (com.bluenimble.platform.PackageClassLoader)3