Search in sources :

Example 1 with Namespace

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

the class PerspectiveTest method testDefaultsPuts.

@Test
public void testDefaultsPuts() throws ClientException, IOException {
    Namespace ns = session.createNamespace(namespaceName, session.getDefaultNamespaceOptions().versionMode(NamespaceVersionMode.CLIENT_SPECIFIED).revisionMode(RevisionMode.UNRESTRICTED_REVISIONS).defaultPutOptions(session.getDefaultPutOptions().version(5)));
    SynchronousNamespacePerspective<String, String> syncNsp = ns.openSyncPerspective(String.class, String.class);
    PutOptions putOptions = syncNsp.getOptions().getDefaultPutOptions();
    GetOptions getOptions = syncNsp.getOptions().getDefaultGetOptions();
    syncNsp.put("k", "v1");
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v2", putOptions.version(1));
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v3");
    printKeyVals(syncNsp, "k", getOptions);
    // this guy is not working as expected
    syncNsp.setDefaultVersion(4);
    syncNsp.put("k", "v4");
    printKeyVals(syncNsp, "k", getOptions);
    // this guy is not working as expected
    syncNsp.setDefaultVersionProvider(new ConstantVersionProvider(6));
    syncNsp.put("k", "v5");
    printKeyVals(syncNsp, "k", getOptions);
    syncNsp.put("k", "v6", putOptions.version(8));
    printKeyVals(syncNsp, "k", getOptions);
}
Also used : ConstantVersionProvider(com.ms.silverking.cloud.dht.client.ConstantVersionProvider) GetOptions(com.ms.silverking.cloud.dht.GetOptions) Namespace(com.ms.silverking.cloud.dht.client.Namespace) PutOptions(com.ms.silverking.cloud.dht.PutOptions) Test(org.junit.Test)

Example 2 with Namespace

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

the class ClientSpecifiedVersionUnrestrictedRevisionsTest method setUpBeforeClass.

@BeforeClass
public static void setUpBeforeClass() throws ClientException, IOException {
    DHTSession session = createSession();
    Namespace ns = createNamespace(session, namespaceName, CLIENT_SPECIFIED, UNRESTRICTED_REVISIONS);
    syncNsp = ns.openSyncPerspective(String.class, String.class);
}
Also used : DHTSession(com.ms.silverking.cloud.dht.client.DHTSession) Namespace(com.ms.silverking.cloud.dht.client.Namespace) BeforeClass(org.junit.BeforeClass)

Example 3 with Namespace

use of com.ms.silverking.cloud.dht.client.Namespace 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 4 with Namespace

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

the class ClientTool method doAction.

public void doAction(ClientOptions options) throws Exception {
    DHTSession session;
    Action action;
    SynchronousNamespacePerspective<String, byte[]> syncNSP;
    Stopwatch sw;
    int outerReps;
    NamespacePerspectiveOptions<String, byte[]> nspOptions;
    // FUTURE - IMPLEMENT VALIDATION FLAG
    // DHTClient.setValidateChecksums(!options.noValidation);
    // note - server may be null
    session = dhtClient.openSession(new SessionOptions(SKGridConfiguration.parseFile(options.gridConfig), options.server));
    if (session == null) {
        throw new RuntimeException("null session");
    }
    if (options.action != Action.CreateNamespace) {
        Namespace ns;
        ns = session.getNamespace(options.namespace);
        nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
        if (options.checksumType != null) {
            nspOptions = nspOptions.defaultPutOptions(session.getDefaultPutOptions().checksumType(options.checksumType));
        }
        syncNSP = ns.openSyncPerspective(nspOptions);
    } else {
        syncNSP = null;
    }
    // syncNSP = session.openSyncNamespacePerspective(options.namespace, nspOptions);
    if (options.warmup) {
        outerReps = 2;
    } else {
        outerReps = 1;
    }
    for (int i = 0; i < outerReps; i++) {
        sw = new SimpleStopwatch();
        try {
            action = options.action;
            switch(action) {
                case Put:
                    doPut(options, session, syncNSP, sw);
                    break;
                case MultiPut:
                    doMultiPut(options, session, syncNSP, sw);
                    break;
                case MultiGet:
                    doMultiGet(options, syncNSP, sw);
                    break;
                case Get:
                    doGet(options, syncNSP, sw);
                    break;
                case GetMeta:
                    doGetMeta(options, syncNSP, sw);
                    break;
                case GetValueAndMeta:
                    doGetValueAndMeta(options, syncNSP, sw);
                    break;
                case WaitFor:
                    doWaitFor(options, syncNSP, sw);
                    break;
                case Snapshot:
                    doSnapshot(options, syncNSP, sw);
                    break;
                case SyncRequest:
                    doSyncRequest(options, syncNSP, sw);
                    break;
                case CreateNamespace:
                    doCreateNamespace(options, session, sw);
                    break;
                case GetNamespaceOptions:
                    doGetNamespaceOptions(options, session, sw);
                    break;
                default:
                    throw new RuntimeException("panic");
            }
        } finally {
            session.close();
        }
        // sw.stop();
        Log.warning("Elapsed:\t" + sw.getElapsedSeconds());
        if (options.warmup || i < outerReps - 1) {
            ThreadUtil.sleep(warmupDelayMillis);
        }
    }
}
Also used : SessionOptions(com.ms.silverking.cloud.dht.SessionOptions) 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) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint) Namespace(com.ms.silverking.cloud.dht.client.Namespace)

Example 5 with Namespace

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

the class SilverKingClient method doSetNamespace.

private void doSetNamespace(String[] args) {
    SynchronousNamespacePerspective<String, byte[]> _syncNSP;
    String namespace;
    namespace = args[0];
    out.printf("Setting namespace to \"%s\"\n", namespace);
    _syncNSP = syncNSP;
    try {
        Namespace ns;
        NamespacePerspectiveOptions<String, byte[]> nspOptions;
        ns = session.getNamespace(namespace);
        if (args.length > 1) {
            nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
            nspOptions = nspOptions.parse(args[1]);
        } else {
            nspOptions = ns.getDefaultNSPOptions(String.class, byte[].class);
        }
        syncNSP = null;
        syncNSP = ns.openSyncPerspective(nspOptions);
    } catch (NamespaceNotCreatedException nnce) {
        err.printf("No such namespace: %s\n", namespace);
    }
    if (syncNSP == null && _syncNSP != null) {
        syncNSP = _syncNSP;
        err.printf("Setting namespace back to: %s\n", syncNSP.getName());
    }
}
Also used : NamespaceNotCreatedException(com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException) Namespace(com.ms.silverking.cloud.dht.client.Namespace)

Aggregations

Namespace (com.ms.silverking.cloud.dht.client.Namespace)9 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)6 BeforeClass (org.junit.BeforeClass)4 GetOptions (com.ms.silverking.cloud.dht.GetOptions)2 PutOptions (com.ms.silverking.cloud.dht.PutOptions)2 SessionOptions (com.ms.silverking.cloud.dht.SessionOptions)1 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)1 ConstantVersionProvider (com.ms.silverking.cloud.dht.client.ConstantVersionProvider)1 DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)1 NamespaceNotCreatedException (com.ms.silverking.cloud.dht.daemon.storage.NamespaceNotCreatedException)1 SimpleStopwatch (com.ms.silverking.time.SimpleStopwatch)1 Stopwatch (com.ms.silverking.time.Stopwatch)1 IOException (java.io.IOException)1 Test (org.junit.Test)1