Search in sources :

Example 6 with DHTClient

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

the class DevTest method test.

public void test(int numKeys, int reps, String namespace, Compression compression, ChecksumType checksumType, EnumSet<Test> tests) throws Exception {
    DHTClient client;
    ClientDHTConfiguration dhtConfig;
    DHTSession session;
    AsynchronousNamespacePerspective<String, String> asyncNSP;
    AsyncRetrieval<String, String> asyncRetrieval;
    AsyncPut<String> asyncPut;
    Stopwatch sw;
    PutOptions putOptions;
    asyncPut = null;
    client = new DHTClient();
    dhtConfig = new ClientDHTConfiguration(dhtName, new ZooKeeperConfig(zkLocs));
    session = client.openSession(dhtConfig);
    putOptions = session.getDefaultNamespaceOptions().getDefaultPutOptions().compression(compression).checksumType(checksumType);
    asyncNSP = session.openAsyncNamespacePerspective(namespace, String.class, String.class);
    sw = new SimpleStopwatch();
    if (tests.contains(Test.Put)) {
        System.out.println("\n\n\t\tPUT");
        for (int i = 0; i < reps; i++) {
            // asyncPut = asyncNSP.put("Hello"+ i, "world!");
            asyncPut = asyncNSP.put(createMap(i, numKeys), putOptions);
            asyncPut.waitForCompletion();
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
    if (tests.contains(Test.Get)) {
        System.out.println("\n\n\t\tGET");
        GetOptions getOptions;
        sw.reset();
        getOptions = OptionsHelper.newGetOptions(RetrievalType.VALUE_AND_META_DATA, session.getDefaultNamespaceOptions().getDefaultGetOptions().getVersionConstraint());
        for (int i = 0; i < reps; i++) {
            Set<String> keys;
            Map<String, ? extends StoredValue<String>> values;
            keys = createSet(i, numKeys);
            asyncRetrieval = asyncNSP.get(keys, getOptions);
            asyncRetrieval.waitForCompletion();
            if (displayValues) {
                System.out.printf("keys: %s\n", CollectionUtil.toString(keys));
                values = asyncRetrieval.getStoredValues();
                System.out.printf("values: %s\n", CollectionUtil.toString(values.entrySet()));
                for (Entry<String, ? extends StoredValue<String>> entry : values.entrySet()) {
                    System.out.println(entry.getKey() + " -> " + entry.getValue().getValue() + "\t" + entry.getValue().getMetaData().toString(true));
                }
            }
        }
        sw.stop();
        displayTimes(sw, reps, numKeys, valueSize);
    }
}
Also used : ZooKeeperConfig(com.ms.silverking.cloud.zookeeper.ZooKeeperConfig) ClientDHTConfiguration(com.ms.silverking.cloud.dht.client.ClientDHTConfiguration) Stopwatch(com.ms.silverking.time.Stopwatch) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) SimpleStopwatch(com.ms.silverking.time.SimpleStopwatch) GetOptions(com.ms.silverking.cloud.dht.GetOptions) PutOptions(com.ms.silverking.cloud.dht.PutOptions) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient)

Example 7 with DHTClient

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

the class HelloByteArray method runExample.

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

Example 8 with DHTClient

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

the class HelloCallbackDHT2 method runExample.

public String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncPut<String> asyncPut;
        AsyncValueRetrieval<String, String> asyncGet;
        Map<String, String> v1;
        s = new Semaphore(0);
        asyncNSP = new DHTClient().openSession(gridConfig).openAsyncNamespacePerspective("_MyNamespace" + System.currentTimeMillis(), String.class, String.class);
        v1 = new HashMap<>();
        for (int i = 0; i < numValues; i++) {
            v1.put(Integer.toString(i), Integer.toString(i));
        }
        asyncPut = asyncNSP.put(v1);
        asyncPut.addListener(this, OperationState.SUCCEEDED, OperationState.FAILED, OperationState.INCOMPLETE);
        s.acquire();
        s.drainPermits();
        asyncGet = asyncNSP.get(v1.keySet());
        asyncGet.addListener(this, OperationState.SUCCEEDED, OperationState.FAILED, OperationState.INCOMPLETE);
        s.acquire();
        // asyncGet.getValues().toString();
        return "complete";
    } 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) RetrievalException(com.ms.silverking.cloud.dht.client.RetrievalException)

Example 9 with DHTClient

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

the class HelloObject method runExample.

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

Example 10 with DHTClient

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

the class HelloMap method runExample.

public static Map<String, String> runExample(SKGridConfiguration gridConfig) {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP;
        Map<String, String> mapA;
        syncNSP = new DHTClient().openSession(gridConfig).openSyncNamespacePerspective("_POTUS", String.class, String.class);
        mapA = ImmutableMap.of("George Washington", "1789-1797", "John Adams", "1797-1801", "Thomas Jefferson", "1801-1809", "James Madison", "1809-1817", "James Monroe", "1817-1825");
        syncNSP.put(mapA);
        return syncNSP.get(mapA.keySet());
    } 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