}
@SuppressWarnings("unchecked")
NotifyingFuture<V> getAsync(final K key, final EnumSet<Flag> explicitFlags, final ClassLoader explicitClassLoader) {
final Transaction tx = getOngoingTransaction();
final NotifyingNotifiableFuture f = new DeferredReturnFuture();
// Optimization to not start a new thread only when the operation is cheap:
if (asyncSkipsThread(explicitFlags, key)) {
return wrapInFuture(get(key, explicitFlags, explicitClassLoader));
} else {
// Make sure the flags are cleared
final EnumSet<Flag> appliedFlags;
if (explicitFlags == null) {
appliedFlags = null;
} else {
appliedFlags = explicitFlags.clone();
explicitFlags.clear();
}
Callable<V> c = new Callable<V>() {
@Override
public V call() throws Exception {
assertKeyNotNull(key);
InvocationContext ctx = getInvocationContextForRead(tx, appliedFlags, explicitClassLoader, 1);
GetKeyValueCommand command = commandsFactory.buildGetKeyValueCommand(key, appliedFlags);
Object ret = invoker.invoke(ctx, command);
f.notifyDone();
return (V) ret;
}
};
f.setNetworkFuture(asyncExecutor.submit(c));
return f;
}
}