Search in sources :

Example 1 with LocalStateData

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);
    }
}
Also used : TDeserializer(org.apache.thrift.TDeserializer) LocalStateData(org.apache.storm.generated.LocalStateData) HashMap(java.util.HashMap) ThriftSerializedObject(org.apache.storm.generated.ThriftSerializedObject) File(java.io.File) IOException(java.io.IOException)

Example 2 with LocalStateData

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);
    }
}
Also used : TSerializer(org.apache.thrift.TSerializer) LocalStateData(org.apache.storm.generated.LocalStateData) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException)

Aggregations

File (java.io.File)2 IOException (java.io.IOException)2 LocalStateData (org.apache.storm.generated.LocalStateData)2 HashMap (java.util.HashMap)1 ThriftSerializedObject (org.apache.storm.generated.ThriftSerializedObject)1 TDeserializer (org.apache.thrift.TDeserializer)1 TSerializer (org.apache.thrift.TSerializer)1