googleanalytics
/
lib
/
analytics-admin
/
vendor
/
google
/
grpc-gcp
/
src
/
GCPClientStreamCall.php
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
GCPClientStreamCall.php
77 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 | * Represents an active call that sends a stream of messages and then gets |
| 23 | * a single response. |
| 24 | */ |
| 25 | class GCPClientStreamCall extends GcpBaseCall |
| 26 | { |
| 27 | protected function createRealCall($data = null) |
| 28 | { |
| 29 | $channel_ref = $this->_rpcPreProcess($data); |
| 30 | $this->real_call = new \Grpc\ClientStreamingCall($channel_ref->getRealChannel( |
| 31 | $this->gcp_channel->credentials), $this->method, $this->deserialize, $this->options); |
| 32 | $this->real_call->start($this->metadata_rpc); |
| 33 | return $this->real_call; |
| 34 | } |
| 35 | /** |
| 36 | * Pick a channel and start the call. |
| 37 | * |
| 38 | * @param array $metadata Metadata to send with the call, if applicable |
| 39 | * (optional) |
| 40 | */ |
| 41 | public function start(array $metadata = []) |
| 42 | { |
| 43 | // Postpone first rpc to write function(), where we can pick a channel |
| 44 | // from the channel pool. |
| 45 | $this->metadata_rpc = $metadata; |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Write a single message to the server. This cannot be called after |
| 50 | * wait is called. |
| 51 | * |
| 52 | * @param ByteBuffer $data The data to write |
| 53 | * @param array $options An array of options, possible keys: |
| 54 | * 'flags' => a number (optional) |
| 55 | */ |
| 56 | public function write($data, array $options = []) |
| 57 | { |
| 58 | if (!$this->has_real_call) { |
| 59 | $this->createRealCall($data); |
| 60 | $this->has_real_call = true; |
| 61 | } |
| 62 | $this->real_call->write($data, $options); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Wait for the server to respond with data and a status. |
| 67 | * |
| 68 | * @return array [response data, status] |
| 69 | */ |
| 70 | public function wait() |
| 71 | { |
| 72 | list($response, $status) = $this->real_call->wait(); |
| 73 | $this->_rpcPostProcess($status, $response); |
| 74 | return [$response, $status]; |
| 75 | } |
| 76 | } |
| 77 |