Search in sources :

Example 1 with FileSystemStorage

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

Aggregations

Feature (com.bluenimble.platform.Feature)1 ApiSpace (com.bluenimble.platform.api.ApiSpace)1 JsonObject (com.bluenimble.platform.json.JsonObject)1 Plugin (com.bluenimble.platform.plugins.Plugin)1 AbstractPlugin (com.bluenimble.platform.plugins.impls.AbstractPlugin)1 ServerFeature (com.bluenimble.platform.server.ServerFeature)1 FileSystemStorage (com.bluenimble.platform.storage.impls.FileSystemStorage)1 File (java.io.File)1