Java Code Examples for io.vertx.core.json.JsonArray#iterator()

The following examples show how to use io.vertx.core.json.JsonArray#iterator() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JsonMessageParser.java    From GDH with MIT License 6 votes vote down vote up
/**
 * 
 * @param msg
 *            the group details in json format to be parsed
 * @return the group id of the group contained in the message
 *         -2 if this message has already been received
 */
private int extractGroupInfo(String msg) {
    TreeSet<Node> set = new TreeSet<>();
    Group group = null;
    JsonObject obj = new JsonObject(msg);
    String prime = obj.getString(Constants.PRIME);
    String generator = obj.getString(Constants.GENERATOR);
    JsonArray members = obj.getJsonArray(Constants.MEMBERS);
    Iterator<?> iter = members.iterator();
    while (iter.hasNext()) {
        JsonObject member = (JsonObject) iter.next();
        String ip = member.getString(Constants.IP);
        String port = member.getString(Constants.PORT);
        Node n = new Node(ip, port);
        set.add(n);
    }
    group = new Group(generator, prime, set);
    if (stateMappings.containsKey(group.getGroupId()) && !stateMappings.get(group.getGroupId()).isDone())
        return -2; // message received twice
    group.setGenerator(new BigInteger(generator));
    group.setPrime(new BigInteger(prime));
    groupMappings.put(group.getGroupId(), group);
    stateMappings.put(group.getGroupId(), new ExchangeState(group.getGroupId(), group.getGenerator()));
    return group.getGroupId();
}
 
Example 2
Source File: FileBasedCredentialsService.java    From hono with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Remove all credentials that point to a device.
 *
 * @param tenantId The tenant to process.
 * @param deviceId The device id to look for.
 */
private void removeAllForDevice(final String tenantId, final String deviceId, final Span span) {

    final ConcurrentMap<String, JsonArray> credentialsForTenant = createOrGetCredentialsForTenant(tenantId);

    for (final JsonArray versionedCredentials : credentialsForTenant.values()) {

        for (final Iterator<Object> i = versionedCredentials.iterator(); i.hasNext();) {

            final Object o = i.next();

            if (!(o instanceof JsonObject)) {
                continue;
            }

            final JsonObject credentials = (JsonObject) o;
            final String currentDeviceId = credentials.getString(Constants.JSON_FIELD_DEVICE_ID);
            if (!deviceId.equals(currentDeviceId)) {
                continue;
            }

            verifyOverwriteEnabled(span);

            // remove device from credentials set
            i.remove();
            dirty.set(true);
        }
    }
}