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);
}
}
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);
}
Aggregations