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:io.nonobot.core.chat.impl.ChatRouterImpl.java

License:Apache License

private void handle(io.vertx.core.eventbus.Message<JsonObject> message) {
    JsonObject body = message.body();
    boolean respond = body.getBoolean("respond");
    String content = body.getString("content");
    String replyAddress = body.getString("replyAddress");
    String chatId = body.getString("chatId");
    for (MessageHandlerImpl handler : messageHandlers) {
        if (handler.respond == respond) {
            Matcher matcher = handler.pattern.matcher(content);
            if (matcher.matches()) {
                handler.handler.handle(new Message() {
                    boolean replied;

                    @Override/*from   w w  w  .j  av a2  s .  c o  m*/
                    public String chatId() {
                        return chatId;
                    }

                    @Override
                    public String body() {
                        return content;
                    }

                    @Override
                    public String matchedGroup(int index) {
                        if (index > 0 && index <= matcher.groupCount()) {
                            return matcher.group(index);
                        } else {
                            return null;
                        }
                    }

                    @Override
                    public void reply(String msg) {
                        reply(msg, null);
                    }

                    @Override
                    public void reply(String msg, Handler<AsyncResult<Void>> ackHandler) {
                        reply(msg, DeliveryOptions.DEFAULT_TIMEOUT, ackHandler);
                    }

                    @Override
                    public void reply(String msg, long ackTimeout, Handler<AsyncResult<Void>> ackHandler) {
                        if (!replied) {
                            replied = true;
                            if (ackHandler != null) {
                                vertx.eventBus().send(replyAddress, msg,
                                        new DeliveryOptions().setSendTimeout(ackTimeout), ack -> {
                                            if (ack.succeeded()) {
                                                ackHandler.handle(Future.succeededFuture());
                                            } else {
                                                ackHandler.handle(Future.failedFuture(ack.cause()));
                                            }
                                        });
                            } else {
                                vertx.eventBus().send(replyAddress, msg);
                            }
                        } else if (ackHandler != null) {
                            ackHandler.handle(Future.failedFuture("Already replied"));
                        }
                    }
                });
                return;
            }
        }
    }
    message.reply(null);
}

From source file:net.kuujo.vertigo.cluster.ClusterOptions.java

License:Apache License

@SuppressWarnings("unchecked")
public ClusterOptions(JsonObject options) {
    this.clustered = options.containsKey("clustered") ? options.getBoolean("clustered")
            : options.getString("cluster") != null;
    this.clusterAddress = options.getString("cluster", clusterAddress);
    this.nodeAddress = options.getString("node", nodeAddress);
    this.nodes = new HashSet(options.getJsonArray("nodes", new JsonArray()).getList());
}

From source file:net.kuujo.vertigo.deployment.ComponentFactory.java

License:Apache License

@Override
public void resolve(String identifier, DeploymentOptions options, ClassLoader classLoader,
        Future<String> resolution) {

    identifier = VerticleFactory.removePrefix(identifier);
    JsonObject config = Configs.load(identifier);
    String main = config.getString("identifier");
    if (main == null) {
        throw new VertxException(identifier + " does not contain a identifier field");
    }/*  ww w. j a v  a 2  s.  co m*/

    JsonObject deployment = config.getJsonObject("deployment");
    if (deployment != null) {
        if (deployment.containsKey("worker")) {
            options.setWorker(deployment.getBoolean("worker"));
        }
        if (deployment.containsKey("multi-threaded")) {
            options.setMultiThreaded(deployment.getBoolean("multi-threaded"));
        }
    }

    resolution.complete(main);
}

From source file:net.kuujo.vertigo.network.impl.ComponentConfigImpl.java

License:Apache License

@Override
@SuppressWarnings("unchecked")
public void update(JsonObject component) {
    if (this.name == null) {
        this.name = component.getString(COMPONENT_NAME, UUID.randomUUID().toString());
    }/*from  w  w w. j  av a  2s.  co m*/
    if (this.identifier == null) {
        this.identifier = component.getString(COMPONENT_IDENTIFIER);
        if (this.identifier == null) {
            throw new NetworkFormatException("Component " + this.name + " did not specify an identifier.");
        }
    }
    if (component.containsKey(COMPONENT_CONFIG)) {
        this.config = component.getJsonObject(COMPONENT_CONFIG);
    }
    if (component.containsKey(COMPONENT_WORKER)) {
        this.worker = component.getBoolean(COMPONENT_WORKER);
    }
    if (component.containsKey(COMPONENT_MULTI_THREADED)) {
        this.multiThreaded = component.getBoolean(COMPONENT_MULTI_THREADED);
    }
    if (component.containsKey(COMPONENT_STATEFUL)) {
        this.stateful = component.getBoolean(COMPONENT_STATEFUL);
    }
    if (component.containsKey(COMPONENT_REPLICAS)) {
        this.replicas = component.getInteger(COMPONENT_REPLICAS, 1);
    }
    if (component.containsKey(COMPONENT_RESOURCES)) {
        this.resources.addAll(component.getJsonArray(COMPONENT_RESOURCES, new JsonArray()).getList());
    }
    JsonObject inputs = component.getJsonObject(COMPONENT_INPUT);
    if (inputs == null) {
        inputs = new JsonObject();
    }
    if (this.input == null) {
        this.input = new InputConfigImpl(inputs).setComponent(this);
    } else {
        this.input.update(inputs);
    }
    JsonObject outputs = component.getJsonObject(COMPONENT_OUTPUT);
    if (outputs == null) {
        outputs = new JsonObject();
    }
    if (this.output == null) {
        this.output = new OutputConfigImpl(outputs).setComponent(this);
    } else {
        this.output.update(outputs);
    }
}

From source file:net.kuujo.vertigo.network.impl.ConnectionConfigImpl.java

License:Apache License

@Override
public void update(JsonObject connection) {
    if (connection.containsKey(CONNECTION_SOURCE)) {
        if (this.source == null) {
            this.source = new SourceConfigImpl(connection.getJsonObject(CONNECTION_SOURCE));
        } else {//  w ww .j  a  va 2 s  . c o m
            this.source.update(connection.getJsonObject(CONNECTION_SOURCE));
        }
    }
    if (connection.containsKey(CONNECTION_TARGET)) {
        if (this.target == null) {
            this.target = new TargetConfigImpl(connection.getJsonObject(CONNECTION_TARGET));
        } else {
            this.target.update(connection.getJsonObject(CONNECTION_TARGET));
        }
    }
    if (connection.containsKey(CONNECTION_ORDERED)) {
        this.ordered = connection.getBoolean(CONNECTION_ORDERED);
    }
    if (connection.containsKey(CONNECTION_AT_LEAST_ONCE)) {
        this.atLeastOnce = connection.getBoolean(CONNECTION_AT_LEAST_ONCE);
    }
    if (connection.containsKey(CONNECTION_SEND_TIMEOUT)) {
        this.sendTimeout = connection.getLong(CONNECTION_SEND_TIMEOUT);
    }
}

From source file:net.kuujo.vertigo.network.impl.EndpointConfigImpl.java

License:Apache License

@Override
public void update(JsonObject endpoint) {
    if (endpoint.containsKey(ENDPOINT_COMPONENT)) {
        this.component = endpoint.getString(ENDPOINT_COMPONENT);
    }//  w ww.j  a  v  a 2  s  . com
    if (endpoint.containsKey(ENDPOINT_PORT)) {
        this.port = endpoint.getString(ENDPOINT_PORT);
    }
    if (endpoint.containsKey(ENDPOINT_IS_NETWORK)) {
        this.isNetwork = endpoint.getBoolean(ENDPOINT_IS_NETWORK);
    }
}

From source file:net.sf.sgsimulator.sgsrest.vertx.services.GridLabSimulatorService.java

License:Open Source License

private void onInit(Vertx vertx, JsonObject config) throws IOException {
    config = config.getJsonObject("gridlab");
    int cycleTimeInMillis = config.getInteger("cycleTimeInMillis");// 60000;
    boolean intelligence = config.getBoolean("intelligence");// true;
    int moments = config.getInteger("moments");// 30;
    Double minRange = config.getDouble("minRange", null);
    Double maxRange = config.getDouble("maxRange", null);
    millisperwebpoll = config.getDouble("millisperwebpoll", null);
    boolean activeClients = config.getBoolean("activeClients");// true;
    // TODO parametrize
    Tariff tariff = new TariffExample();

    JsonArray sdjson = config.getJsonArray("startDate");
    JsonArray edjson = config.getJsonArray("endDate");
    Calendar calendarStart = Calendar.getInstance();
    calendarStart.set(sdjson.getInteger(0), sdjson.getInteger(1), sdjson.getInteger(2), sdjson.getInteger(3),
            sdjson.getInteger(4), sdjson.getInteger(5));

    Calendar calendarEnd = Calendar.getInstance();
    calendarEnd.set(edjson.getInteger(0), edjson.getInteger(1), edjson.getInteger(2), edjson.getInteger(3),
            edjson.getInteger(4), edjson.getInteger(5));

    String configurationFile = config.getString("configurationFile");
    String gridFile = config.getString("gridFile");
    // definition
    String scenarioFile = config.getString("scenarioFile");
    String gridLabFolder = config.getString("gridLabFolder");
    PATHS paths = new PATHS(configurationFile, gridFile, scenarioFile, gridLabFolder);

    Date[] dates = readSimulationTime(paths.getNetXmlSrcFile());
    long diffInMillies = calendarEnd.getTimeInMillis() - calendarStart.getTimeInMillis();

    int hoursOfSimulation = (int) TimeUnit.HOURS.convert(diffInMillies, TimeUnit.MILLISECONDS);
    startDate = calendarStart.getTime();
    init(title, startDate, cycleTimeInMillis, paths, intelligence, hoursOfSimulation, tariff, moments, minRange,
            maxRange, activeClients);//from   www .j a  v a2s.  c  o  m
}

From source file:org.eclipse.hono.deviceregistry.FileBasedCredentialsService.java

License:Open Source License

private CredentialsResult<JsonObject> getCredentialsResult(final String tenantId, final String authId,
        final String type) {
    JsonObject data = getCredentials(tenantId, authId, type);
    if (data != null) {
        JsonObject resultPayload = getResultPayload(data.getString(FIELD_DEVICE_ID), data.getString(FIELD_TYPE),
                data.getString(FIELD_AUTH_ID), data.getBoolean(FIELD_ENABLED),
                data.getJsonArray(FIELD_SECRETS));
        return CredentialsResult.from(HTTP_OK, resultPayload);
    } else {/*from w  w  w . j ava2 s.  co m*/
        return CredentialsResult.from(HTTP_NOT_FOUND, (JsonObject) null);
    }
}

From source file:org.eclipse.hono.service.credentials.impl.FileBasedCredentialsService.java

License:Open Source License

protected CredentialsResult getCredentialsResult(final String tenantId, final String authId,
        final String type) {
    JsonObject data = getCredentials(tenantId, authId, type);
    if (data != null) {
        JsonObject resultPayload = getResultPayload(data.getString(FIELD_DEVICE_ID), data.getString(FIELD_TYPE),
                data.getString(FIELD_AUTH_ID), data.getBoolean(FIELD_ENABLED),
                data.getJsonArray(FIELD_SECRETS));
        return CredentialsResult.from(HTTP_OK, resultPayload);
    } else {/*  ww w.  ja  v  a 2s .c  o m*/
        return CredentialsResult.from(HTTP_NOT_FOUND);
    }
}

From source file:org.eclipse.hono.service.registration.BaseRegistrationService.java

License:Open Source License

private JsonObject getRequestPayload(final JsonObject request) {

    final JsonObject payload = request.getJsonObject(RegistrationConstants.FIELD_PAYLOAD, new JsonObject());
    Boolean enabled = payload.getBoolean(FIELD_ENABLED);
    if (enabled == null) {
        log.debug("adding 'enabled' key to payload");
        payload.put(FIELD_ENABLED, Boolean.TRUE);
    }/* w  w  w  .jav  a2  s  .  com*/
    return payload;
}