Пример #1
0
    /** 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);
    }
Пример #2
0
 /**
  * Sets the serializer, returning the replica builder for method chaining.
  *
  * <p>The serializer will be used to serialize and deserialize operations that are sent over the
  * wire.
  *
  * @param serializer The serializer.
  * @return The replica builder.
  * @throws NullPointerException if {@code serializer} is null
  */
 public Builder withSerializer(Serializer serializer) {
   clientBuilder.withSerializer(serializer);
   serverBuilder.withSerializer(serializer);
   return this;
 }