private Builder(Address clientAddress, Address serverAddress, Collection<Address> members) { this.members = Assert.notNull(members, "members"); Serializer serializer = new Serializer(); this.clientAddress = Assert.notNull(clientAddress, "clientAddress"); this.clientBuilder = CopycatClient.builder(members).withSerializer(serializer.clone()); this.serverBuilder = CopycatServer.builder(clientAddress, serverAddress, members) .withSerializer(serializer.clone()); }
/** Builds a client for the replica. */ private ResourceClient buildClient() { buildTransport(); // Resolve resources. resourceResolver.resolve(registry); // Configure the client and server with a transport that routes all local client communication // directly through the local server, ensuring we don't incur unnecessary network traffic by // sending operations to a remote server when a local server is already available in the same // JVM.= clientBuilder .withTransport( new CombinedClientTransport( clientAddress, new LocalTransport(localRegistry), clientTransport != null ? clientTransport : serverTransport)) .withServerSelectionStrategy(new CombinedSelectionStrategy(clientAddress)); CopycatClient client = clientBuilder.build(); client.serializer().resolve(new ResourceManagerTypeResolver(registry)); return new ResourceClient(new CombinedCopycatClient(client, serverTransport), registry); }
@Override public boolean isOpen() { return client.isOpen(); }
@Override public CompletableFuture<Void> close() { return client.close(); }
@Override public CompletableFuture<CopycatClient> recover() { return client.recover(); }
@Override public CompletableFuture<CopycatClient> open() { return client.open(); }
@Override public <T> Listener<T> onEvent(String event, Consumer<T> callback) { return client.onEvent(event, callback); }
@Override public Listener<Void> onEvent(String event, Runnable callback) { return client.onEvent(event, callback); }
@Override public <T> CompletableFuture<T> submit(Command<T> command) { return client.submit(command); }
@Override public Session session() { return client.session(); }
@Override public Serializer serializer() { return client.serializer(); }
@Override public ThreadContext context() { return client.context(); }
@Override public Listener<State> onStateChange(Consumer<State> consumer) { return client.onStateChange(consumer); }
@Override public State state() { return client.state(); }
@Override public boolean isClosed() { return client.isClosed(); }
@Override public String toString() { return client.toString(); }
@Override public <T> CompletableFuture<T> submit(Query<T> query) { return client.submit(query); }