Search in sources :

Example 11 with DHTClient

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

the class HelloAsyncDHT method runExample.

public static String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncPut<String> asyncPut;
        AsyncSingleValueRetrieval<String, String> asyncGet;
        asyncNSP = new DHTClient().openSession(gridConfig).openAsyncNamespacePerspective("_MyNamespace", String.class, String.class);
        asyncPut = asyncNSP.put("Hello async", "async world!");
        asyncPut.waitForCompletion();
        asyncGet = asyncNSP.get("Hello async");
        asyncGet.waitForCompletion();
        return asyncGet.getValue();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Example 12 with DHTClient

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

the class HelloCallbackDHT method runExample.

public String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncPut<String> asyncPut;
        AsyncSingleValueRetrieval<String, String> asyncGet;
        s = new Semaphore(0);
        asyncNSP = new DHTClient().openSession(gridConfig).openAsyncNamespacePerspective("_MyNamespace" + System.currentTimeMillis(), String.class, String.class);
        asyncPut = asyncNSP.put("Hello callback", "callback world!");
        asyncPut.addListener(this, OperationState.SUCCEEDED, OperationState.FAILED, OperationState.INCOMPLETE);
        s.acquire();
        s.drainPermits();
        asyncGet = asyncNSP.get("Hello callback");
        asyncGet.addListener(this);
        s.acquire();
        return asyncGet.getValue();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : Semaphore(java.util.concurrent.Semaphore) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Example 13 with DHTClient

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

the class HelloDHT method runExample.

public static String runExample(SKGridConfiguration gridConfig) {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP;
        syncNSP = new DHTClient().openSession(gridConfig).openSyncNamespacePerspective("_MyNamespace", String.class, String.class);
        syncNSP.put("Hello", "world!");
        return syncNSP.get("Hello");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Aggregations

DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)13 IOException (java.io.IOException)10 ClientDHTConfiguration (com.ms.silverking.cloud.dht.client.ClientDHTConfiguration)3 GetOptions (com.ms.silverking.cloud.dht.GetOptions)2 PutOptions (com.ms.silverking.cloud.dht.PutOptions)2 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)2 Semaphore (java.util.concurrent.Semaphore)2 ClientException (com.ms.silverking.cloud.dht.client.ClientException)1 Namespace (com.ms.silverking.cloud.dht.client.Namespace)1 RetrievalException (com.ms.silverking.cloud.dht.client.RetrievalException)1 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1