/** * Builds a server for the replica. */ private ResourceServer buildServer() { // Construct the underlying CopycatServer. The server should have been configured with a CombinedTransport // that facilitates the local client connecting directly to the server. if (clientTransport != null) { serverBuilder.withClientTransport(new CombinedServerTransport(new LocalTransport(localRegistry), clientTransport)) .withServerTransport(serverTransport); } else { serverBuilder.withTransport(new CombinedServerTransport(new LocalTransport(localRegistry), serverTransport)); } // Set the server resource state machine. serverBuilder.withStateMachine(() -> new ResourceManagerState(registry)); // If the quorum hint is ALL then set the local member to ACTIVE. if (quorumHint == Quorum.ALL.size()) { serverBuilder.withType(Member.Type.ACTIVE); } CopycatServer server = serverBuilder.build(); server.serializer().resolve(new ResourceManagerTypeResolver(registry)); return new ResourceServer(server); }
/** * 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); }