Search in sources :

Example 1 with StoredValue

use of com.ms.silverking.cloud.dht.client.StoredValue in project SilverKing by Morgan-Stanley.

the class AsyncRetrievalOperationImpl method getLatestStoredValues.

@Override
public Map<K, ? extends StoredValue<V>> getLatestStoredValues() throws RetrievalException {
    Map<K, StoredValue<V>> storedValueMap;
    storedValueMap = new HashMap<>(retrievalOperation.size() - latestStoredReturned.size());
    for (Map.Entry<K, RetrievalResultBase<V>> resultEntry : results.entrySet()) {
        K key;
        DHTKey dhtKey;
        key = resultEntry.getKey();
        dhtKey = keyToDHTKey.get(key);
        if (!latestStoredReturned.contains(dhtKey)) {
            RetrievalResultBase<V> value;
            latestStoredReturned.add(dhtKey);
            value = resultEntry.getValue();
            if (value.getOpResult() == OpResult.SUCCEEDED) {
                storedValueMap.put(resultEntry.getKey(), value);
            }
        }
    }
    return storedValueMap;
}
Also used : DHTKey(com.ms.silverking.cloud.dht.common.DHTKey) StoredValue(com.ms.silverking.cloud.dht.client.StoredValue) HashMap(java.util.HashMap) ConcurrentMap(java.util.concurrent.ConcurrentMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConcurrentSingleMap(com.ms.silverking.collection.ConcurrentSingleMap)

Example 2 with StoredValue

use of com.ms.silverking.cloud.dht.client.StoredValue in project SilverKing by Morgan-Stanley.

the class SilverKingClient method retrieveAllValuesForKey.

private Map<String, ? extends StoredValue<byte[]>> retrieveAllValuesForKey(String key) throws RetrievalException {
    RetrievalOptions retrievalOptions;
    Map<String, StoredValue<byte[]>> keyValues;
    keyValues = new HashMap<>();
    retrievalOptions = syncNSP.getOptions().getDefaultGetOptions().retrievalType(RetrievalType.META_DATA).nonExistenceResponse(NonExistenceResponse.NULL_VALUE).versionConstraint(VersionConstraint.greatest).returnInvalidations(true);
    try {
        do {
            StoredValue<byte[]> storedValue;
            // System.out.printf("%s\t%s\n", key, retrievalOptions);
            storedValue = syncNSP.retrieve(key, retrievalOptions);
            if (storedValue != null) {
                String keyAndVersion;
                keyAndVersion = String.format("%s %d %d %s", key, storedValue.getVersion(), storedValue.getCreationTime().inNanos(), storedValue.getCreationTime().toDateString());
                keyValues.put(keyAndVersion, storedValue);
                // System.out.printf("%d\t%d\n", storedValue.getMetaData().getVersion(), storedValue.getMetaData().getCreationTime().inNanos());
                // retrievalOptions = retrievalOptions.versionConstraint(retrievalOptions.getVersionConstraint().maxCreationTime(storedValue.getCreationTime().inNanos() - 1));
                retrievalOptions = retrievalOptions.versionConstraint(retrievalOptions.getVersionConstraint().maxBelowOrEqual(storedValue.getVersion() - 1));
            // ThreadUtil.sleep(1000);
            } else {
                break;
            }
        } while (true);
    } catch (RetrievalException re) {
        displayRetrievalExceptionDetails(re);
        throw re;
    }
    return keyValues;
}
Also used : RetrievalOptions(com.ms.silverking.cloud.dht.RetrievalOptions) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException) StoredValue(com.ms.silverking.cloud.dht.client.StoredValue)

Aggregations

StoredValue (com.ms.silverking.cloud.dht.client.StoredValue)2 RetrievalOptions (com.ms.silverking.cloud.dht.RetrievalOptions)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 DHTKey (com.ms.silverking.cloud.dht.common.DHTKey)1 ConcurrentSingleMap (com.ms.silverking.collection.ConcurrentSingleMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1