generated
3 years ago
ChannelRef.php
3 years ago
Config.php
3 years ago
CreatedByDeserializeCheck.php
3 years ago
GCPBidiStreamingCall.php
3 years ago
GCPCallInvoker.php
3 years ago
GCPClientStreamCall.php
3 years ago
GCPServerStreamCall.php
3 years ago
GCPUnaryCall.php
3 years ago
GcpBaseCall.php
3 years ago
GcpExtensionChannel.php
3 years ago
grpc_gcp.proto
3 years ago
GCPCallInvoker.php
87 lines
| 1 | <?php |
| 2 | /* |
| 3 | * |
| 4 | * Copyright 2018 gRPC authors. |
| 5 | * |
| 6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | * you may not use this file except in compliance with the License. |
| 8 | * You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, software |
| 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | * See the License for the specific language governing permissions and |
| 16 | * limitations under the License. |
| 17 | * |
| 18 | */ |
| 19 | namespace Grpc\Gcp; |
| 20 | |
| 21 | /** |
| 22 | * GCPCallInvoker updates the channel pool(GcpExtensionChannel) for |
| 23 | * each RPC. The idea is: |
| 24 | * Before the RPC starts, pick a channel from the channel pool: |
| 25 | * - if the RPC is bound to a channel, use that channel. |
| 26 | * - if the RPC doesn't bound to a channel, use the one with minimum active streams. |
| 27 | * After the RPC finishes, update the active stream ref count. |
| 28 | * - if the RPC is defined as bind, bind the channel with corresponding key like |
| 29 | * spanner session name. |
| 30 | * - if the RPC is defined as unbind, unbind the channel with the key. |
| 31 | */ |
| 32 | class GCPCallInvoker implements \Grpc\CallInvoker |
| 33 | { |
| 34 | private $channel; |
| 35 | private $affinity_conf; |
| 36 | |
| 37 | /** |
| 38 | * @param array $affinity_conf Store the affinity config for process each RPC. |
| 39 | */ |
| 40 | public function __construct($affinity_conf) |
| 41 | { |
| 42 | $this->affinity_conf = $affinity_conf; |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * @param string $hostname |
| 47 | * @param array $opts |
| 48 | * @return GcpExtensionChannel |
| 49 | */ |
| 50 | public function createChannelFactory($hostname, $opts) |
| 51 | { |
| 52 | if ($this->channel) { |
| 53 | // $call_invoker object has already created from previews PHP-FPM scripts. |
| 54 | // Only need to udpate the $opts including the credentials. |
| 55 | $this->channel->updateOpts($opts); |
| 56 | } else { |
| 57 | $opts['affinity_conf'] = $this->affinity_conf; |
| 58 | $channel = new GcpExtensionChannel($hostname, $opts); |
| 59 | $this->channel = $channel; |
| 60 | } |
| 61 | return $this->channel; |
| 62 | } |
| 63 | |
| 64 | // _getChannel is used for testing only. |
| 65 | public function GetChannel() |
| 66 | { |
| 67 | return $this->channel; |
| 68 | } |
| 69 | |
| 70 | public function UnaryCall($channel, $method, $deserialize, $options) |
| 71 | { |
| 72 | return new GCPUnaryCall($channel, $method, $deserialize, $options); |
| 73 | } |
| 74 | public function ClientStreamingCall($channel, $method, $deserialize, $options) |
| 75 | { |
| 76 | return new GCPClientStreamCall($channel, $method, $deserialize, $options); |
| 77 | } |
| 78 | public function ServerStreamingCall($channel, $method, $deserialize, $options) |
| 79 | { |
| 80 | return new GCPServerStreamCall($channel, $method, $deserialize, $options); |
| 81 | } |
| 82 | public function BidiStreamingCall($channel, $method, $deserialize, $options) |
| 83 | { |
| 84 | return new GCPBidiStreamingCall($channel, $method, $deserialize, $options); |
| 85 | } |
| 86 | } |
| 87 |