Search in sources :

Example 1 with DHTClient

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

the class PerspectiveTest method test.

// @Test
public void test() {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP = new DHTClient().openSession(Util.getTestGridConfig()).openSyncNamespacePerspective("_VersionTest", String.class, String.class);
        syncNSP.setDefaultRetrievalVersionConstraint(VersionConstraint.defaultConstraint);
        // syncNSP.setDefaultVersionProvider(syncNSP.getNamespace().getOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).getVersionMode());
        // syncNSP.set
        printNsoAndNspo(syncNSP);
        PutOptions po = syncNSP.getOptions().getDefaultPutOptions();
        GetOptions go = syncNSP.getOptions().getDefaultGetOptions();
        // syncNSP.setOptions( syncNSP.getOptions().defaultPutOptions( po ));
        System.out.println("\n\n" + go);
        syncNSP.getNamespace().getOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).revisionMode(RevisionMode.UNRESTRICTED_REVISIONS);
        printNsoAndNspo(syncNSP);
        syncNSP.put("k", "v1", po.version(1));
        // syncNSP.put("k", "v2", po.version(2));
        System.out.println(syncNSP.get("k"));
    // System.out.println( syncNSP.get("k", go));
    // syncNSP.setOptions( syncNSP.getOptions().defaultPutOptions( new PutOptions(opTimeoutController, secondaryTargets, compression, checksumType, checksumCompressedValues, version, userData)));
    // 
    // syncNSP.put(mapA);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : GetOptions(com.ms.silverking.cloud.dht.GetOptions) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) PutOptions(com.ms.silverking.cloud.dht.PutOptions) IOException(java.io.IOException) ClientException(com.ms.silverking.cloud.dht.client.ClientException)

Example 2 with DHTClient

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

the class AsyncInvalidationExample method runExample.

public static String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncInvalidation<String> asyncInvalidation;
        AsyncPut<String> asyncPut;
        AsyncSingleValueRetrieval<String, String> asyncGet;
        DHTSession session;
        Namespace ns;
        session = new DHTClient().openSession(gridConfig);
        ns = session.createNamespace("MyNamespace" + System.currentTimeMillis(), session.getDefaultNamespaceOptions().versionMode(NamespaceVersionMode.SYSTEM_TIME_NANOS));
        System.out.printf("Using namespace %s\n", ns.getName());
        asyncNSP = ns.openAsyncPerspective(String.class, String.class);
        asyncPut = asyncNSP.put(key, value);
        asyncPut.waitForCompletion();
        asyncPut = asyncNSP.put(key, value);
        asyncPut.waitForCompletion();
        asyncGet = asyncNSP.get(key);
        asyncGet.waitForCompletion();
        System.out.printf("Before invalidation %s\n", asyncGet.getValue());
        asyncInvalidation = asyncNSP.invalidate(key);
        asyncInvalidation.waitForCompletion();
        asyncGet = asyncNSP.get(key);
        asyncGet.waitForCompletion();
        System.out.printf("After invalidation %s\n", asyncGet.getValue());
        return asyncGet.getValue();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) Namespace(com.ms.silverking.cloud.dht.client.Namespace) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Example 3 with DHTClient

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

the class AsyncWaitForCompletion method runExample.

public static String runExample(SKGridConfiguration gridConfig) {
    try {
        AsynchronousNamespacePerspective<String, String> asyncNSP;
        AsyncSingleValueRetrieval<String, String> asyncWaitFor;
        asyncNSP = new DHTClient().openSession(gridConfig).openAsyncNamespacePerspective("_MyNamespace", String.class, String.class);
        asyncWaitFor = asyncNSP.waitFor("key.1");
        asyncNSP.put("key.1", "value.1");
        System.out.println("Waiting for active ops");
        asyncNSP.waitForActiveOps();
        System.out.println("Wait complete");
        return asyncWaitFor.getValue();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : DHTClient(com.ms.silverking.cloud.dht.client.DHTClient) IOException(java.io.IOException)

Example 4 with DHTClient

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

the class HelloEmbeddedDHT method runExample.

public static String runExample() {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP;
        ClientDHTConfiguration dhtConfig;
        System.out.println("Creating embedded SK instance");
        dhtConfig = ClientDHTConfiguration.embeddedKVS;
        System.out.println("Embedded SK instance running at: " + dhtConfig);
        syncNSP = new DHTClient().openSession(dhtConfig).openSyncNamespacePerspective("_MyNamespace", String.class, String.class);
        syncNSP.put("Hello", "world!");
        return syncNSP.get("Hello");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ClientDHTConfiguration(com.ms.silverking.cloud.dht.client.ClientDHTConfiguration) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient)

Example 5 with DHTClient

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

the class HelloEmbeddedDHT2 method runExample.

public static String runExample() {
    try {
        SynchronousNamespacePerspective<String, String> syncNSP;
        ClientDHTConfiguration dhtConfig;
        System.out.println("Creating embedded SK instance");
        dhtConfig = EmbeddedSK.createEmbeddedSKInstance();
        System.out.println("Embedded SK instance running at: " + dhtConfig);
        syncNSP = new DHTClient().openSession(dhtConfig).openSyncNamespacePerspective("_MyNamespace", String.class, String.class);
        syncNSP.put("Hello", "world!");
        return syncNSP.get("Hello");
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : ClientDHTConfiguration(com.ms.silverking.cloud.dht.client.ClientDHTConfiguration) DHTClient(com.ms.silverking.cloud.dht.client.DHTClient)

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