From 1913b6d5ea338a813242a58eab1f7d5e50dcb49d Mon Sep 17 00:00:00 2001 From: Vaci Koblizek Date: Fri, 2 Oct 2020 21:47:04 +0100 Subject: [PATCH] minor scope changes to cap client and server --- .../main/java/org/capnproto/Capability.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/runtime/src/main/java/org/capnproto/Capability.java b/runtime/src/main/java/org/capnproto/Capability.java index 9706fd0..7762809 100644 --- a/runtime/src/main/java/org/capnproto/Capability.java +++ b/runtime/src/main/java/org/capnproto/Capability.java @@ -4,6 +4,14 @@ import java.util.concurrent.CompletableFuture; public final class Capability { + static abstract class BuilderContext { + CapTableBuilder capTable; + } + + static class ReaderContext { + CapTableReader capTable; + } + public static class Client { final ClientHook hook; @@ -17,7 +25,7 @@ public final class Capability { } public Client(Server server) { - this(server.makeLocalClient()); + this(makeLocalClient(server)); } public Client(CompletableFuture promise) { @@ -28,8 +36,8 @@ public final class Capability { this(newBrokenCap(exc)); } - public ClientHook getHook() { - return this.hook; + private static ClientHook makeLocalClient(Server server) { + return server.makeLocalClient(); } CompletableFuture whenResolved() { @@ -42,37 +50,29 @@ public final class Capability { return hook.newCall(interfaceId, methodId); } - public Request newCall(FromPointerBuilder builder, + protected Request newCall(FromPointerBuilder builder, FromPointerReader reader, long interfaceId, short methodId) { var request = hook.newCall(interfaceId, methodId); return new Request (builder, reader, request.params, request.hook); } - - public Request newCall(long interfaceId, short methodId) { - return hook.newCall(interfaceId, methodId); - } - - private static ClientHook makeLocalClient(Capability.Server server) { - return server.makeLocalClient(); - } } public abstract static class Server { private static final Object BRAND = new Object(); - ClientHook hook; + private ClientHook hook; - public ClientHook makeLocalClient() { + ClientHook makeLocalClient() { return new LocalClient(); } private final class LocalClient implements ClientHook { - CompletableFuture resolveTask; - ClientHook resolved; - boolean blocked = false; - Exception brokenException; + private CompletableFuture resolveTask; + private ClientHook resolved; + private boolean blocked = false; + private Exception brokenException; LocalClient() { Server.this.hook = this; @@ -142,12 +142,12 @@ public final class Capability { return; } this.resolveTask = resolver.thenAccept(client -> { - this.resolved = client.getHook(); + this.resolved = client.hook; }); } } - final class DispatchCallResult { + public static final class DispatchCallResult { private final CompletableFuture promise; private final boolean streaming; @@ -180,7 +180,7 @@ public final class Capability { } protected Client thisCap() { - return new Client(hook); + return new Client(this.hook); } protected final CallContext internalGetTypedContext( @@ -190,12 +190,14 @@ public final class Capability { return new CallContext<>(paramsFactory, resultsFactory, typeless.hook); } - public abstract DispatchCallResult dispatchCall(long interfaceId, short methodId, CallContext context); + public abstract DispatchCallResult dispatchCall(long interfaceId, short methodId, + CallContext context); protected DispatchCallResult internalUnimplemented(String actualInterfaceName, long requestedTypeId) { return new DispatchCallResult(RpcException.unimplemented( "Method not implemented. " + actualInterfaceName + " " + requestedTypeId)); } + protected DispatchCallResult internalUnimplemented(String interfaceName, long typeId, short methodId) { return new DispatchCallResult(RpcException.unimplemented( "Method not implemented. " + interfaceName + " " + typeId + " " + methodId));