Browse Source

Put the client connection behind a protocol (#727)

Motivation:

Generated client stubs may only be initialized using a
`ClientConnection` which makes the assumption that a connection will
only ever be singular, and that all RPCs for that stub will run on a
single event loop.

However, there are scenarios where we may want to drive a stub and have
multiple connections (load balancing), or no real connection at all
(testing).

Modifications:

- Generated client stubs now depend on the implementation of a `GRPCChannel`
- The first argument label for the `init` in generated clients has
  changed from `connection` to `client`
- Added fixits for the above
- Updated generated code
- `GRPCChannel`s contract ensures that RPCs can be made but do not
  specify the transport.
- `GRPCClient` now requires a `GRPCChannel`
- `GRPCClient` provides higher level wrappers for the factory methods on
  `GRPCChannel` (i.e. provide defaults such as for call options)

Result:

- We have a better ability, in the future, to use already-generated
  stubs with different `GRPCChannel`s.
- Cleaner abstraction between call and connection.
George Barnett 6 years ago
parent
commit
a2b2cc064f
1 changed files with 4 additions and 4 deletions
  1. 4 4
      Sources/protoc-gen-grpc-swift/Generator-Client.swift

+ 4 - 4
Sources/protoc-gen-grpc-swift/Generator-Client.swift

@@ -52,17 +52,17 @@ extension Generator {
   private func printServiceClientImplementation() {
     println("\(access) final class \(serviceClassName)Client: GRPCClient, \(serviceClassName) {")
     indent()
-    println("\(access) let connection: ClientConnection")
+    println("\(access) let channel: GRPCChannel")
     println("\(access) var defaultCallOptions: CallOptions")
     println()
     println("/// Creates a client for the \(servicePath) service.")
     println("///")
     printParameters()
-    println("///   - connection: `ClientConnection` to the service host.")
+    println("///   - channel: `GRPCChannel` to the service host.")
     println("///   - defaultCallOptions: Options to use for each service call if the user doesn't provide them.")
-    println("\(access) init(connection: ClientConnection, defaultCallOptions: CallOptions = CallOptions()) {")
+    println("\(access) init(channel: GRPCChannel, defaultCallOptions: CallOptions = CallOptions()) {")
     indent()
-    println("self.connection = connection")
+    println("self.channel = channel")
     println("self.defaultCallOptions = defaultCallOptions")
     outdent()
     println("}")