Search in sources :

Example 1 with ThriftSerializedObject

use of org.apache.storm.generated.ThriftSerializedObject 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 ThriftSerializedObject

use of org.apache.storm.generated.ThriftSerializedObject in project storm by apache.

the class LocalState method get.

public TBase get(String key) {
    TDeserializer td = new TDeserializer();
    Map<String, ThriftSerializedObject> partial = partialSnapshot(td);
    ThriftSerializedObject tso = partial.get(key);
    TBase ret = null;
    if (tso != null) {
        ret = deserialize(tso, td);
    }
    return ret;
}
Also used : TDeserializer(org.apache.thrift.TDeserializer) TBase(org.apache.thrift.TBase) ThriftSerializedObject(org.apache.storm.generated.ThriftSerializedObject)

Example 3 with ThriftSerializedObject

use of org.apache.storm.generated.ThriftSerializedObject in project storm by apache.

the class LocalState method deserializeLatestVersion.

private Map<String, TBase> deserializeLatestVersion() throws IOException {
    Map<String, TBase> result = new HashMap<>();
    TDeserializer td = new TDeserializer();
    for (Map.Entry<String, ThriftSerializedObject> ent : partialDeserializeLatestVersion(td).entrySet()) {
        result.put(ent.getKey(), deserialize(ent.getValue(), td));
    }
    return result;
}
Also used : TDeserializer(org.apache.thrift.TDeserializer) HashMap(java.util.HashMap) TBase(org.apache.thrift.TBase) HashMap(java.util.HashMap) Map(java.util.Map) ThriftSerializedObject(org.apache.storm.generated.ThriftSerializedObject)

Example 4 with ThriftSerializedObject

use of org.apache.storm.generated.ThriftSerializedObject in project storm by apache.

the class LocalState method put.

public synchronized void put(String key, TBase val, boolean cleanup) {
    Map<String, ThriftSerializedObject> curr = partialSnapshot(null);
    TSerializer ser = new TSerializer();
    curr.put(key, serialize(val, ser));
    persistInternal(curr, ser, cleanup);
}
Also used : TSerializer(org.apache.thrift.TSerializer) ThriftSerializedObject(org.apache.storm.generated.ThriftSerializedObject)

Aggregations

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