Search in sources :

Example 1 with Entry

use of com.eightkdata.mongowp.bson.BsonDocument.Entry in project torodb by torodb.

the class MemberConfig method fromDocument.

public static MemberConfig fromDocument(BsonDocument bson) throws TypesMismatchException, NoSuchKeyException, BadValueException {
    int id = BsonReaderTool.getNumeric(bson, "_id").intValue();
    HostAndPort host = BsonReaderTool.getHostAndPort(bson, "host");
    Builder builder = new Builder(id, host).setVotes(BsonReaderTool.getInteger(bson, "votes", DEFAULT_VOTES)).setPriority(BsonReaderTool.getDouble(bson, "priority", DEFAULT_PRIORITY)).setArbiterOnly(BsonReaderTool.getBooleanOrNumeric(bson, "arbiterOnly", DEFAULT_ARBITER_ONLY)).setSlaveDelay(BsonReaderTool.getNumeric(bson, "slaveDelay", DEFAULT_SLAVE_DELAY).longValue()).setHidden(BsonReaderTool.getBooleanOrNumeric(bson, "hidden", DEFAULT_HIDDEN)).setBuildIndexes(BsonReaderTool.getBooleanOrNumeric(bson, "buildIndexes", DEFAULT_BUILD_INDEXES));
    BsonDocument castedTags = BsonReaderTool.getDocument(bson, "tags");
    for (Entry entry : castedTags) {
        BsonValue value = entry.getValue();
        if (value.isString()) {
            throw new TypesMismatchException(entry.getKey(), "string", value.getType());
        }
        String castedValue = value.asString().getValue();
        builder.putTag(entry.getKey(), castedValue);
    }
    return builder.build();
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Entry(com.eightkdata.mongowp.bson.BsonDocument.Entry) BsonDocument(com.eightkdata.mongowp.bson.BsonDocument) BsonDocumentBuilder(com.eightkdata.mongowp.utils.BsonDocumentBuilder) TypesMismatchException(com.eightkdata.mongowp.exceptions.TypesMismatchException) BsonValue(com.eightkdata.mongowp.bson.BsonValue)

Aggregations

BsonDocument (com.eightkdata.mongowp.bson.BsonDocument)1 Entry (com.eightkdata.mongowp.bson.BsonDocument.Entry)1 BsonValue (com.eightkdata.mongowp.bson.BsonValue)1 TypesMismatchException (com.eightkdata.mongowp.exceptions.TypesMismatchException)1 BsonDocumentBuilder (com.eightkdata.mongowp.utils.BsonDocumentBuilder)1 HostAndPort (com.google.common.net.HostAndPort)1