use of org.apache.storm.generated.LocalStateData in project storm by apache.
the class LocalState method partialDeserializeLatestVersion.
private Map<String, ThriftSerializedObject> partialDeserializeLatestVersion(TDeserializer td) {
try {
String latestPath = _vs.mostRecentVersionPath();
Map<String, ThriftSerializedObject> result = new HashMap<>();
if (latestPath != null) {
byte[] serialized = FileUtils.readFileToByteArray(new File(latestPath));
if (serialized.length == 0) {
LOG.warn("LocalState file '{}' contained no data, resetting state", latestPath);
} else {
if (td == null) {
td = new TDeserializer();
}
LocalStateData data = new LocalStateData();
td.deserialize(data, serialized);
result = data.get_serialized_parts();
}
}
return result;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.apache.storm.generated.LocalStateData in project storm by apache.
the class LocalState method persistInternal.
private void persistInternal(Map<String, ThriftSerializedObject> serialized, TSerializer ser, boolean cleanup) {
try {
if (ser == null) {
ser = new TSerializer();
}
byte[] toWrite = ser.serialize(new LocalStateData(serialized));
String newPath = _vs.createVersion();
File file = new File(newPath);
FileUtils.writeByteArrayToFile(file, toWrite);
if (toWrite.length != file.length()) {
throw new IOException("Tried to serialize " + toWrite.length + " bytes to " + file.getCanonicalPath() + ", but " + file.length() + " bytes were written.");
}
_vs.succeedVersion(newPath);
if (cleanup)
_vs.cleanup(4);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations