tidy up branding and implement QueuedClient,getBrand() correctly

This commit is contained in:
Vaci Koblizek 2020-11-30 18:52:28 +00:00
parent c04bdb8088
commit 2b5bf0eb21
3 changed files with 20 additions and 20 deletions

View file

@ -1939,10 +1939,10 @@ final class RpcState<VatId> {
// We resolved to some other RPC capability hosted by the same peer. // We resolved to some other RPC capability hosted by the same peer.
var promise = replacement.whenMoreResolved(); var promise = replacement.whenMoreResolved();
if (promise != null) { if (promise != null) {
var other = (PromiseClient)replacement; var other = (PromiseClient) replacement;
while (other.resolutionType == ResolutionType.MERGED) { while (other.resolutionType == ResolutionType.MERGED) {
replacement = other.cap; replacement = other.cap;
other = (PromiseClient)replacement; other = (PromiseClient) replacement;
assert replacement.getBrand() == replacementBrand; assert replacement.getBrand() == replacementBrand;
} }
@ -1958,15 +1958,12 @@ final class RpcState<VatId> {
resolutionType = ResolutionType.REMOTE; resolutionType = ResolutionType.REMOTE;
} }
} }
else { else if (replacement.isNull() || replacement.isError()) {
if (replacementBrand == NULL_CAPABILITY_BRAND
|| replacementBrand == BROKEN_CAPABILITY_BRAND) {
resolutionType = ResolutionType.BROKEN; resolutionType = ResolutionType.BROKEN;
} }
else { else {
resolutionType = ResolutionType.REFLECTED; resolutionType = ResolutionType.REFLECTED;
} }
}
assert isResolved(); assert isResolved();

View file

@ -7,6 +7,9 @@ import java.util.concurrent.CompletionStage;
public final class Capability { public final class Capability {
static final Object NULL_CAPABILITY_BRAND = new Object();
static final Object BROKEN_CAPABILITY_BRAND = new Object();
static class BuilderContext { static class BuilderContext {
CapTableBuilder capTable; CapTableBuilder capTable;
} }
@ -645,15 +648,15 @@ public final class Capability {
} }
public static ClientHook newBrokenCap(String reason) { public static ClientHook newBrokenCap(String reason) {
return newBrokenClient(reason, false, ClientHook.BROKEN_CAPABILITY_BRAND); return newBrokenClient(reason, false, BROKEN_CAPABILITY_BRAND);
} }
public static ClientHook newBrokenCap(Throwable exc) { public static ClientHook newBrokenCap(Throwable exc) {
return newBrokenClient(exc, false, ClientHook.BROKEN_CAPABILITY_BRAND); return newBrokenClient(exc, false, BROKEN_CAPABILITY_BRAND);
} }
public static ClientHook newNullCap() { public static ClientHook newNullCap() {
return newBrokenClient(RpcException.failed("Called null capability"), true, ClientHook.NULL_CAPABILITY_BRAND); return newBrokenClient(RpcException.failed("Called null capability"), true, NULL_CAPABILITY_BRAND);
} }
private static ClientHook newBrokenClient(String reason, boolean resolved, Object brand) { private static ClientHook newBrokenClient(String reason, boolean resolved, Object brand) {
@ -800,6 +803,11 @@ public final class Capability {
public CompletableFuture<ClientHook> whenMoreResolved() { public CompletableFuture<ClientHook> whenMoreResolved() {
return this.promiseForClientResolution.copy(); return this.promiseForClientResolution.copy();
} }
@Override
public Object getBrand() {
return null;
}
} }
public static final class CapabilityServerSet<T extends Capability.Server> { public static final class CapabilityServerSet<T extends Capability.Server> {

View file

@ -5,9 +5,6 @@ import java.util.concurrent.CompletableFuture;
public interface ClientHook { public interface ClientHook {
Object NULL_CAPABILITY_BRAND = new Object();
Object BROKEN_CAPABILITY_BRAND = new Object();
/** /**
* Start a new call, allowing the client to allocate request/response objects as it sees fit. * Start a new call, allowing the client to allocate request/response objects as it sees fit.
* This version is used when calls are made from application code in the local process. * This version is used when calls are made from application code in the local process.
@ -56,9 +53,7 @@ public interface ClientHook {
discover when a capability it needs to marshal is one that it created in the first place, and discover when a capability it needs to marshal is one that it created in the first place, and
therefore it can transfer the capability without proxying. therefore it can transfer the capability without proxying.
*/ */
default Object getBrand() { Object getBrand();
return NULL_CAPABILITY_BRAND;
}
/** /**
* Repeatedly calls whenMoreResolved() until it returns nullptr. * Repeatedly calls whenMoreResolved() until it returns nullptr.
@ -75,14 +70,14 @@ public interface ClientHook {
* reading a null pointer out of a Cap'n Proto message. * reading a null pointer out of a Cap'n Proto message.
*/ */
default boolean isNull() { default boolean isNull() {
return getBrand() == NULL_CAPABILITY_BRAND; return getBrand() == Capability.NULL_CAPABILITY_BRAND;
} }
/** /**
* Returns true if the capability was created by newBrokenCap(). * Returns true if the capability was created by newBrokenCap().
*/ */
default boolean isError() { default boolean isError() {
return getBrand() == BROKEN_CAPABILITY_BRAND; return getBrand() == Capability.BROKEN_CAPABILITY_BRAND;
} }
/** /**