Search in sources :

Example 1 with Compression

use of voldemort.serialization.Compression in project voldemort by voldemort.

the class StoreDefinitionsMapper method addSerializer.

public static void addSerializer(Element parent, SerializerDefinition def) {
    parent.addContent(new Element(STORE_SERIALIZATION_TYPE_ELMT).setText(def.getName()));
    if (def.hasSchemaInfo()) {
        for (Map.Entry<Integer, String> entry : def.getAllSchemaInfoVersions().entrySet()) {
            Element schemaElmt = new Element(STORE_SERIALIZATION_META_ELMT);
            if (def.hasVersion())
                schemaElmt.setAttribute(STORE_VERSION_ATTR, Integer.toString(entry.getKey()));
            else
                schemaElmt.setAttribute(STORE_VERSION_ATTR, "none");
            schemaElmt.setText(entry.getValue());
            parent.addContent(schemaElmt);
        }
    }
    if (def.hasCompression()) {
        Compression compression = def.getCompression();
        Element compressionElmt = new Element(STORE_COMPRESSION_ELMT);
        Element type = new Element(STORE_COMPRESSION_TYPE_ELMT);
        type.setText(compression.getType());
        compressionElmt.addContent(type);
        String optionsText = compression.getOptions();
        if (optionsText != null) {
            Element options = new Element(STORE_COMPRESSION_OPTIONS_ELMT);
            options.setText(optionsText);
            compressionElmt.addContent(options);
        }
        parent.addContent(compressionElmt);
    }
}
Also used : Compression(voldemort.serialization.Compression) Element(org.jdom.Element) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with Compression

use of voldemort.serialization.Compression in project voldemort by voldemort.

the class StoreDefinitionsMapper method readSerializer.

public static SerializerDefinition readSerializer(Element elmt) {
    String name = elmt.getChild(STORE_SERIALIZATION_TYPE_ELMT).getText();
    boolean hasVersion = true;
    Map<Integer, String> schemaInfosByVersion = new HashMap<Integer, String>();
    for (Object schemaInfo : elmt.getChildren(STORE_SERIALIZATION_META_ELMT)) {
        Element schemaInfoElmt = (Element) schemaInfo;
        String versionStr = schemaInfoElmt.getAttributeValue(STORE_VERSION_ATTR);
        int version;
        if (versionStr == null) {
            version = 0;
        } else if (versionStr.equals("none")) {
            version = 0;
            hasVersion = false;
        } else {
            version = Integer.parseInt(versionStr);
        }
        String info = schemaInfoElmt.getText();
        String previous = schemaInfosByVersion.put(version, info);
        if (previous != null)
            throw new MappingException("Duplicate version " + version + " found in schema info.");
    }
    if (!hasVersion && schemaInfosByVersion.size() > 1)
        throw new IllegalArgumentException("Specified multiple schemas AND version=none, which is not permitted.");
    Element compressionElmt = elmt.getChild(STORE_COMPRESSION_ELMT);
    Compression compression = null;
    if (compressionElmt != null)
        compression = new Compression(compressionElmt.getChildText("type"), compressionElmt.getChildText("options"));
    return new SerializerDefinition(name, schemaInfosByVersion, hasVersion, compression);
}
Also used : Compression(voldemort.serialization.Compression) HashMap(java.util.HashMap) Element(org.jdom.Element) SerializerDefinition(voldemort.serialization.SerializerDefinition)

Aggregations

HashMap (java.util.HashMap)2 Element (org.jdom.Element)2 Compression (voldemort.serialization.Compression)2 Map (java.util.Map)1 SerializerDefinition (voldemort.serialization.SerializerDefinition)1