Search in sources :

Example 1 with AsyncValueRetrieval

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

the class HelloCallbackDHT2 method asyncOperationUpdated.

@Override
public void asyncOperationUpdated(AsyncOperation asyncOperation) {
    OperationState opState;
    opState = asyncOperation.getState();
    if (opState == OperationState.FAILED) {
        System.out.printf("Operation failed: %s\n", asyncOperation.getClass());
    } else if (opState == OperationState.INCOMPLETE || opState == OperationState.SUCCEEDED) {
        if (asyncOperation instanceof AsyncValueRetrieval) {
            AsyncValueRetrieval asyncValueRetrieval;
            Map<String, String> values;
            asyncValueRetrieval = (AsyncValueRetrieval) asyncOperation;
            try {
                values = asyncValueRetrieval.getLatestValues();
                for (Map.Entry<String, String> entry : values.entrySet()) {
                    System.out.printf("Complete: %s\t=>\t%s\n", entry.getKey(), entry.getValue());
                }
            } catch (RetrievalException e) {
                e.printStackTrace();
            }
        // System.out.printf("Incomplete keys: %d\n", asyncValueRetrieval.getIncompleteKeys().size());
        } else {
            System.out.printf("Operation incomplete: %s\n", asyncOperation.getClass());
        }
        if (opState == OperationState.SUCCEEDED) {
            s.release();
        }
    } else {
        s.release();
    }
// System.out.printf("%s %s %s\n", Thread.currentThread().getName(), asyncOperation.getClass(), opState);
}
Also used : AsyncValueRetrieval(com.ms.silverking.cloud.dht.client.AsyncValueRetrieval) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException) HashMap(java.util.HashMap) Map(java.util.Map) OperationState(com.ms.silverking.cloud.dht.client.OperationState)

Aggregations

AsyncValueRetrieval (com.ms.silverking.cloud.dht.client.AsyncValueRetrieval)1 OperationState (com.ms.silverking.cloud.dht.client.OperationState)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1