All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.swisspush.reststorage.RestStorageMod Maven / Gradle / Ivy

There is a newer version: 3.1.8
Show newest version
package org.swisspush.reststorage;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerOptions;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.logging.Logger;
import io.vertx.core.logging.LoggerFactory;
import org.swisspush.reststorage.util.ModuleConfiguration;

public class RestStorageMod extends AbstractVerticle {

    private Logger log = LoggerFactory.getLogger(RestStorageMod.class);

    @Override
    public void start(Future fut) {
        ModuleConfiguration modConfig = ModuleConfiguration.fromJsonObject(config());
        log.info("Starting RestStorageMod with configuration: " + modConfig);
        Storage storage;
        switch (modConfig.getStorageType()) {
            case filesystem:
                storage = new FileSystemStorage(vertx, modConfig.getRoot());
                break;
            case redis:
                storage = new RedisStorage(vertx, modConfig);
                break;
            default:
                throw new RuntimeException("Storage not supported: " + modConfig.getStorageType());
        }

        Handler handler = new RestStorageHandler(vertx, log, storage, modConfig.getPrefix(),
                modConfig.getEditorConfig(), modConfig.isConfirmCollectionDelete(), modConfig.isRejectStorageWriteOnLowMemory());

        // in Vert.x 2x 100-continues was activated per default, in vert.x 3x it is off per default.
        HttpServerOptions options = new HttpServerOptions().setHandle100ContinueAutomatically(true);

        vertx.createHttpServer(options).requestHandler(handler).listen(modConfig.getPort(), result -> {
            if(result.succeeded()){
                new EventBusAdapter().init(vertx, modConfig.getStorageAddress(), handler);
                fut.complete();
            } else {
                fut.fail(result.cause());
            }
        });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy