EzRpcClient must connect synchronously
This commit is contained in:
parent
23c3c789f7
commit
c9dcefb153
2 changed files with 6 additions and 27 deletions
|
@ -1,39 +1,16 @@
|
|||
package org.capnproto;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
import java.net.SocketAddress;
|
||||
import java.nio.channels.AsynchronousSocketChannel;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class EzRpcClient {
|
||||
|
||||
private final AsynchronousSocketChannel socket;
|
||||
private final TwoPartyClient twoPartyRpc;
|
||||
private final Capability.Client client;
|
||||
|
||||
public EzRpcClient(SocketAddress address) throws Exception {
|
||||
this.socket = AsynchronousSocketChannel.open();
|
||||
|
||||
var connected = new CompletableFuture<Void>();
|
||||
|
||||
this.socket.connect(address, null, new CompletionHandler<>() {
|
||||
|
||||
@Override
|
||||
public void completed(java.lang.Void result, Object attachment) {
|
||||
connected.complete(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failed(Throwable exc, Object attachment) {
|
||||
connected.completeExceptionally(exc);
|
||||
}
|
||||
});
|
||||
|
||||
public EzRpcClient(AsynchronousSocketChannel socket) {
|
||||
this.twoPartyRpc = new TwoPartyClient(socket);
|
||||
this.client = new Capability.Client(connected.thenApply(void_ -> this.twoPartyRpc.bootstrap()));
|
||||
this.client = new Capability.Client(this.twoPartyRpc.bootstrap());
|
||||
}
|
||||
|
||||
public Capability.Client getMain() {
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.capnproto;
|
|||
import org.capnproto.rpctest.Test;
|
||||
import org.junit.Assert;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.AsynchronousSocketChannel;
|
||||
|
||||
public class EzRpcTest {
|
||||
|
||||
|
@ -13,8 +14,9 @@ public class EzRpcTest {
|
|||
var server = new EzRpcServer(new RpcTestUtil.TestInterfaceImpl(callCount), address);
|
||||
server.start();
|
||||
|
||||
var client = new EzRpcClient(new InetSocketAddress("localhost", server.getPort()));
|
||||
|
||||
var clientSocket = AsynchronousSocketChannel.open();
|
||||
clientSocket.connect(new InetSocketAddress("localhost", server.getPort())).get();
|
||||
var client = new EzRpcClient(clientSocket);
|
||||
var cap = new Test.TestInterface.Client(client.getMain());
|
||||
var request = cap.fooRequest();
|
||||
request.getParams().setI(123);
|
||||
|
|
Loading…
Reference in a new issue