use of com.ms.silverking.cloud.dht.SessionOptions 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.SessionOptions in project SilverKing by Morgan-Stanley.
the class DebugKey method replicaContainsKey.
private boolean replicaContainsKey(IPAndPort replica, String key) throws ClientException {
DHTSession dhtSession;
SynchronousNamespacePerspective<String, byte[]> nsp;
RetrievalOptions ro;
StoredValue<byte[]> storedValue;
dhtSession = dhtClient.openSession(new SessionOptions(gc, replica.getIPAsString()));
nsp = dhtSession.openSyncNamespacePerspective(namespace, String.class, byte[].class);
ro = nsp.getNamespace().getOptions().getDefaultGetOptions();
ro = ro.retrievalType(RetrievalType.META_DATA);
ro = ro.forwardingMode(ForwardingMode.DO_NOT_FORWARD);
ro = ro.nonExistenceResponse(NonExistenceResponse.NULL_VALUE);
storedValue = nsp.retrieve(key, ro);
nsp.close();
dhtSession.close();
if (storedValue == null) {
return false;
} else {
// out.println(storedValue.getMetaData());
return true;
}
}
Aggregations