Example usage for io.vertx.core.json JsonObject getBoolean

List of usage examples for io.vertx.core.json JsonObject getBoolean

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject getBoolean.

Prototype

public Boolean getBoolean(String key) 

Source Link

Document

Get the Boolean value with the specified key

Usage

From source file:org.mustertech.webapp.vertxutils.VerticleDeployer.java

License:Open Source License

private static Promise<JsonObject, Exception, Double> deployWithOpts(JsonObject opt) {
    Deferred<JsonObject, Exception, Double> deffered = new DeferredObject<JsonObject, Exception, Double>();
    DeploymentOptions deployOpts = new DeploymentOptions();

    // Check and set Config option
    if (opt.containsKey("config")) {
        JsonObject vertCfg = opt.getJsonObject("config");
        deployOpts.setConfig(vertCfg);//from  ww  w. j  a v  a  2s  .  c  o  m
    }

    // Check and set ExtraClasspath option
    if (opt.containsKey("extCps")) {
        JsonArray extCps = opt.getJsonArray("extCps");
        Iterator<Object> cpIter = extCps.iterator();

        ArrayList<String> extCpsList = new ArrayList<String>();
        while (cpIter.hasNext()) {
            extCpsList.add((String) cpIter.next());
        }

        deployOpts.setExtraClasspath(extCpsList);
    }

    // Check and set Isolated-Group option
    if (opt.containsKey("isolatedGrp")) {
        deployOpts.setIsolationGroup(opt.getString("isolatedGrp"));
    }

    // Check and set Isolated-Classes option
    if (opt.containsKey("isolatedCls")) {
        JsonArray isoCls = opt.getJsonArray("isolatedCls");
        Iterator<Object> clsIter = isoCls.iterator();

        ArrayList<String> isoClsList = new ArrayList<String>();
        while (clsIter.hasNext()) {
            isoClsList.add((String) clsIter.next());
        }

        deployOpts.setIsolatedClasses(isoClsList);
    }

    // Check and set HA option
    deployOpts.setHa(opt.containsKey("isHa") && opt.getBoolean("isHa"));

    // Check and set instances option
    deployOpts.setInstances(opt.containsKey("nInst") ? opt.getInteger("nInst").intValue() : 1);

    // Check and set Worker/MT option
    Boolean isWorker = (opt.containsKey("isWorker") && opt.getBoolean("isWorker"));
    if (isWorker) {
        deployOpts.setWorker(true);
        deployOpts.setMultiThreaded(opt.containsKey("isMt") && opt.getBoolean("isMt"));
    }

    String vertName = opt.getString("name");

    // Finally, deploy the verticle
    vertx.deployVerticle(vertName, deployOpts, ar -> {
        if (ar.succeeded()) {
            JsonObject resObj = new JsonObject();
            resObj.put("verticleName", vertName).put("deployId", ar.result());

            deffered.resolve(resObj);
        } else {
            Throwable thr = ar.cause();
            String defErr = vertName + " => Could not be deployed!";
            deffered.reject(
                    (null != thr.getMessage()) ? new Exception(thr.getMessage()) : new Exception(defErr));
        }
    });

    return deffered.promise();
}

From source file:org.mustertech.webapp.vertxutils.VerticleDeployer.java

License:Open Source License

public static void deploy(final Vertx vertx, final String cfgJson, Handler<AsyncResult<JsonObject>> handler) {
    if (null == vertx) {
        NullPointerException e = new NullPointerException("NULL vertxutils instance is passed!");
        handler.handle(makeAsyncResult(e, null));

        return;/*from w  ww. jav a2  s  .  c o m*/
    }

    // Store the vertx instance
    VerticleDeployer.vertx = vertx;

    try {
        InputStream schStream = VerticleDeployer.class.getResourceAsStream("/schema/deploy-schema.json");
        StringWriter strWriter = new StringWriter();

        IOUtils.copy(schStream, strWriter, "UTF-8");
        JsonValidator.validateJson(strWriter.toString(), cfgJson);
        IOUtils.closeQuietly(schStream);

        JsonObject cfgObj = new JsonObject(cfgJson);
        JsonObject globalCfg = null;
        JsonObject optObj = null, optCfg = null;
        JsonArray deployOpts = cfgObj.getJsonArray("deployOpts");

        int optsLen = deployOpts.size();
        ArrayList<Promise<JsonObject, Exception, Double>> promises = new ArrayList<Promise<JsonObject, Exception, Double>>();

        if (cfgObj.containsKey("globalConf")) {
            globalCfg = cfgObj.getJsonObject("globalConf");
        }

        for (int idx = 0; idx < optsLen; idx++) {
            optObj = (JsonObject) deployOpts.getJsonObject(idx);

            if (cfgObj.containsKey("appendGlobal") && cfgObj.getBoolean("appendGlobal")) {
                if (optObj.containsKey("config")) {
                    optCfg = optObj.getJsonObject("config");

                    if (!optCfg.containsKey("global")) {
                        optCfg.put("global", globalCfg);
                    }
                } else {
                    optCfg = new JsonObject();

                    optCfg.put("global", globalCfg);
                    optObj.put("config", optCfg);
                }
            }

            promises.add(deployWithOpts(optObj));
        }

        DeferredManager defMgr = new DefaultDeferredManager();

        defMgr.when(promises.toArray(new Promise[] {})).done(new DoneCallback<MultipleResults>() {
            public void onDone(MultipleResults results) {
                JsonArray resArr = new JsonArray();
                Iterator<OneResult> oneResIter = results.iterator();

                while (oneResIter.hasNext()) {
                    resArr.add(oneResIter.next().getResult());
                }

                JsonObject resObj = new JsonObject();
                resObj.put("deployInfo", resArr);

                handler.handle(makeAsyncResult(null, resObj));
            }
        }).fail(new FailCallback<OneReject>() {
            public void onFail(OneReject err) {
                handler.handle(makeAsyncResult((Throwable) err.getReject(), null));
            }
        });
    } catch (Exception e) {
        handler.handle(makeAsyncResult(e, null));
    }
}

From source file:org.sfs.vo.BlobReference.java

License:Apache License

public T merge(JsonObject jsonObject) {
    volumeId = jsonObject.getString("volume_id");
    position = jsonObject.getLong("position");
    readSha512 = jsonObject.getBinary("read_sha512");
    readLength = jsonObject.getLong("read_length");
    acknowledged = jsonObject.getBoolean("acknowledged");
    deleted = jsonObject.getBoolean("deleted");
    verifyFailCount = jsonObject.getInteger("verify_fail_count", 0);

    return (T) this;
}

From source file:org.sfs.vo.Segment.java

License:Apache License

public T merge(JsonObject document) {
    Long id = document.getLong("id");
    checkNotNull(id, "id cannot be null");
    checkState(id == this.id, "id was %s, expected %s", id, this.id);
    setReadMd5(document.getBinary("read_md5"));
    setReadSha512(document.getBinary("read_sha512"));
    setReadLength(document.getLong("read_length"));
    setWriteSha512(document.getBinary("write_sha512"));
    setWriteLength(document.getLong("write_length"));
    isTinyData = document.getBoolean("is_tiny_data");
    tinyData = document.getBinary("tiny_data");
    isTinyDataDeleted = document.getBoolean("is_tiny_data_deleted");

    String cipherKey = document.getString("container_key_id");
    byte[] cipherSalt = document.getBinary("cipher_salt");

    segmentCipher = new SegmentCipher(cipherKey, cipherSalt);

    JsonArray blobJsonArray = document.getJsonArray("blobs");
    this.blobs.clear();
    if (blobJsonArray != null) {
        for (Object o : blobJsonArray) {
            JsonObject jsonObject = (JsonObject) o;
            TransientBlobReference transientBlobReference = new TransientBlobReference(this).merge(jsonObject);
            this.blobs.add(transientBlobReference);
        }//  w  w  w.ja va 2  s .  c o m
    }
    return (T) this;
}

From source file:org.sfs.vo.ServiceDef.java

License:Apache License

public T merge(JsonObject jsonObject) {
    this.id = jsonObject.getString("id");
    this.lastUpdate = fromDateTimeString(jsonObject.getString("update_ts"));
    this.master = jsonObject.getBoolean("master_node");
    this.dataNode = jsonObject.getBoolean("data_node");
    this.documentCount = jsonObject.getLong("document_count");
    this.availableProcessors = jsonObject.getInteger("available_processors");
    this.freeMemory = jsonObject.getLong("free_memory");
    this.maxMemory = jsonObject.getLong("max_memory");
    this.totalMemory = jsonObject.getLong("total_memory");

    JsonObject jsonFileSystem = jsonObject.getJsonObject("file_system");
    if (jsonFileSystem != null) {
        this.fileSystem = new TransientXFileSystem().merge(jsonFileSystem);
    } else {//from   w w  w  .  j a  v  a2 s  .  c  o m
        this.fileSystem = null;
    }

    JsonArray jsonListeners = jsonObject.getJsonArray("publish_addresses");
    this.publishAddresses.clear();
    if (jsonListeners != null) {
        for (Object o : jsonListeners) {
            String jsonListener = (String) o;
            this.publishAddresses.add(HostAndPort.fromString(jsonListener));
        }
    }

    JsonArray jsonVolumes = jsonObject.getJsonArray("volumes");
    this.volumes.clear();
    if (jsonVolumes != null) {
        for (Object o : jsonVolumes) {
            JsonObject jsonVolume = (JsonObject) o;
            TransientXVolume transientXVolume = new TransientXVolume().merge(jsonVolume);
            this.volumes.add(transientXVolume);
        }
    }
    return (T) this;
}

From source file:org.sfs.vo.XVersion.java

License:Apache License

public T merge(JsonObject document) {
    setDeleted(document.getBoolean("deleted"));
    setDeleteMarker(document.getBoolean("delete_marker"));

    setContentDisposition(document.getString("content_disposition"));
    setContentType(document.getString("content_type"));
    setContentEncoding(document.getString("content_encoding"));
    setContentLength(document.getLong("content_length"));
    setEtag(document.getBinary("etag"));
    setContentMd5(document.getBinary("content_md5"));
    setContentSha512(document.getBinary("content_sha512"));
    setDeleteAt(document.getLong("delete_at"));
    setServerSideEncryption(document.getBoolean("server_side_encryption"));
    setObjectManifest(document.getString("object_manifest"));
    setStaticLargeObject(document.getBoolean("static_large_object"));

    JsonArray metadataJsonObject = document.getJsonArray("metadata", new JsonArray());
    metadata.withJsonObject(metadataJsonObject);

    this.segments.clear();
    JsonArray jsonSegments = document.getJsonArray("segments", new JsonArray());
    for (Object o : jsonSegments) {
        JsonObject segmentDocument = (JsonObject) o;
        Long segmentId = segmentDocument.getLong("id");
        checkNotNull(segmentId, "Segment id cannot be null");
        TransientSegment transientSegment = new TransientSegment(this, segmentId).merge(segmentDocument);
        segments.add(transientSegment);/*from ww w .jav  a 2  s . co m*/
    }

    String createTimestamp = document.getString("create_ts");
    String updateTimestamp = document.getString("update_ts");

    if (createTimestamp != null) {
        setCreateTs(fromDateTimeString(createTimestamp));
    }
    if (updateTimestamp != null) {
        setUpdateTs(fromDateTimeString(updateTimestamp));
    }
    return (T) this;
}

From source file:shadowsocks.util.GlobalConfig.java

License:Apache License

public static void getConfigFromFile() throws ClassCastException {
    String name = GlobalConfig.get().getConfigFile();
    if (name == null)
        return;/*from   w w  w.  j a v a 2  s  .  c  o m*/
    String data = GlobalConfig.readConfigFile(name);

    JsonObject jsonobj = new JsonObject(data);

    if (jsonobj.containsKey(SERVER_ADDR)) {
        String server = jsonobj.getString(SERVER_ADDR);
        log.debug("CFG:Server address: " + server);
        GlobalConfig.get().setServer(server);
    }
    if (jsonobj.containsKey(SERVER_PORT)) {
        int port = jsonobj.getInteger(SERVER_PORT).intValue();
        log.debug("CFG:Server port: " + port);
        GlobalConfig.get().setPort(port);
    }
    if (jsonobj.containsKey(LOCAL_PORT)) {
        int lport = jsonobj.getInteger(LOCAL_PORT).intValue();
        log.debug("CFG:Local port: " + lport);
        GlobalConfig.get().setLocalPort(lport);
    }
    if (jsonobj.containsKey(PASSWORD)) {
        String password = jsonobj.getString(PASSWORD);
        log.debug("CFG:Password: " + password);
        GlobalConfig.get().setPassowrd(password);
    }
    if (jsonobj.containsKey(METHOD)) {
        String method = jsonobj.getString(METHOD);
        log.debug("CFG:Crypto method: " + method);
        GlobalConfig.get().setMethod(method);
    }
    if (jsonobj.containsKey(AUTH)) {
        boolean auth = jsonobj.getBoolean(AUTH).booleanValue();
        log.debug("CFG:One time auth: " + auth);
        GlobalConfig.get().setOTAEnabled(auth);
    }
    if (jsonobj.containsKey(TIMEOUT)) {
        int timeout = jsonobj.getInteger(TIMEOUT).intValue();
        log.debug("CFG:Timeout: " + timeout);
        GlobalConfig.get().setTimeout(timeout);
    }
    if (jsonobj.containsKey(SERVER_MODE)) {
        boolean isServer = jsonobj.getBoolean(SERVER_MODE).booleanValue();
        log.debug("CFG:Running on server mode: " + isServer);
        GlobalConfig.get().setServerMode(isServer);
    }
}