Search in sources :

Example 1 with PutOptions

use of com.ms.silverking.cloud.dht.PutOptions 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 PutOptions

use of com.ms.silverking.cloud.dht.PutOptions 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 3 with PutOptions

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

the class SilverKingClient method doPut.

private void doPut(String[] args) throws OperationException, IOException {
    Map<String, byte[]> map;
    ImmutableMap.Builder<String, byte[]> builder;
    PutOptions putOptions;
    if (args[0].startsWith("{")) {
        if (!args[0].endsWith("}")) {
            err.printf("putOptions missing closing }\n");
            return;
        } else {
            String[] newArgs;
            newArgs = new String[args.length - 1];
            System.arraycopy(args, 1, newArgs, 0, newArgs.length);
            putOptions = ((PutOptions) ObjectDefParser2.parse(PutOptions.class, args[0].substring(1, args[0].length() - 1)));
            if (verbose) {
                out.printf("putOptions: %s\n", putOptions);
            }
            args = newArgs;
        }
    } else {
        putOptions = syncNSP.getNamespace().getOptions().getDefaultPutOptions();
    }
    builder = ImmutableMap.builder();
    for (int i = 0; i < args.length; i += 2) {
        builder.put(translateKey(args[i]), translateValue(args[i + 1]));
    }
    map = builder.build();
    opMessage("Putting");
    sw.reset();
    try {
        for (int i = 0; i < reps; i++) {
            syncNSP.put(map, putOptions);
        }
    } catch (PutException pe) {
        out.println(pe.getDetailedFailureMessage());
        throw pe;
    }
    sw.stop();
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) ImmutableMap(com.google.common.collect.ImmutableMap) PutOptions(com.ms.silverking.cloud.dht.PutOptions) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 4 with PutOptions

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

the class ClientTool method doMultiPut.

private void doMultiPut(ClientOptions options, DHTSession session, SynchronousNamespacePerspective<String, byte[]> syncNSP, Stopwatch sw) throws OperationException, IOException {
    PutOptions putOptions;
    long version;
    Map<String, byte[]> map;
    ImmutableMap.Builder<String, byte[]> builder;
    version = options.version;
    builder = ImmutableMap.builder();
    for (int i = 0; i < options.numKeys; i++) {
        builder.put(options.key + "." + i, options.getValue());
    }
    map = builder.build();
    putOptions = session.getDefaultPutOptions().compression(options.compression != null ? options.compression : Compression.NONE).checksumType(options.checksumType).version(version);
    Log.warning("Putting value for version:", version);
    sw.reset();
    try {
        for (int i = 0; i < options.reps; i++) {
            syncNSP.put(map, putOptions);
        }
    } catch (PutException pe) {
        System.out.println(pe.getDetailedFailureMessage());
        throw pe;
    }
    sw.stop();
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) PutOptions(com.ms.silverking.cloud.dht.PutOptions) ImmutableMap(com.google.common.collect.ImmutableMap) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Example 5 with PutOptions

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

the class ClientTool method doPut.

private void doPut(ClientOptions options, DHTSession session, SynchronousNamespacePerspective<String, byte[]> syncNSP, Stopwatch sw) throws OperationException, IOException {
    PutOptions putOptions;
    long version;
    byte[] value;
    version = options.version;
    putOptions = session.getDefaultPutOptions().compression(options.compression != null ? options.compression : Compression.NONE).checksumType(options.checksumType).version(version);
    Log.warning("Putting value for version:", version);
    value = options.getValue();
    sw.reset();
    try {
        for (int i = 0; i < options.reps; i++) {
            syncNSP.put(options.key, value);
        // syncNSP.put(options.key, value, putOptions);
        }
    } catch (PutException pe) {
        System.out.println(pe.getDetailedFailureMessage());
        throw pe;
    }
    sw.stop();
}
Also used : PutException(com.ms.silverking.cloud.dht.client.PutException) PutOptions(com.ms.silverking.cloud.dht.PutOptions) VersionConstraint(com.ms.silverking.cloud.dht.VersionConstraint)

Aggregations

PutOptions (com.ms.silverking.cloud.dht.PutOptions)7 GetOptions (com.ms.silverking.cloud.dht.GetOptions)4 VersionConstraint (com.ms.silverking.cloud.dht.VersionConstraint)3 PutException (com.ms.silverking.cloud.dht.client.PutException)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 DHTClient (com.ms.silverking.cloud.dht.client.DHTClient)2 Namespace (com.ms.silverking.cloud.dht.client.Namespace)2 ClientDHTConfiguration (com.ms.silverking.cloud.dht.client.ClientDHTConfiguration)1 ClientException (com.ms.silverking.cloud.dht.client.ClientException)1 ConstantVersionProvider (com.ms.silverking.cloud.dht.client.ConstantVersionProvider)1 DHTSession (com.ms.silverking.cloud.dht.client.DHTSession)1 ZooKeeperConfig (com.ms.silverking.cloud.zookeeper.ZooKeeperConfig)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