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);
}
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);
}
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);
}
}
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);
}
}
}
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());
}
}
Aggregations