googleanalytics
/
lib
/
analytics-admin
/
vendor
/
google
/
grpc-gcp
/
src
/
GCPBidiStreamingCall.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
GCPBidiStreamingCall.php
109 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 allows for sending and recieving messages |
| 23 | * in streams in any order. |
| 24 | */ |
| 25 | class GCPBidiStreamingCall extends GcpBaseCall |
| 26 | { |
| 27 | private $response = null; |
| 28 | |
| 29 | protected function createRealCall($data = null) |
| 30 | { |
| 31 | $channel_ref = $this->_rpcPreProcess($data); |
| 32 | $this->real_call = new \Grpc\BidiStreamingCall($channel_ref->getRealChannel( |
| 33 | $this->gcp_channel->credentials), $this->method, $this->deserialize, $this->options); |
| 34 | $this->real_call->start($this->metadata_rpc); |
| 35 | return $this->real_call; |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Pick a channel and start the call. |
| 40 | * |
| 41 | * @param array $metadata Metadata to send with the call, if applicable |
| 42 | * (optional) |
| 43 | */ |
| 44 | public function start(array $metadata = []) |
| 45 | { |
| 46 | $this->metadata_rpc = $metadata; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Reads the next value from the server. |
| 51 | * |
| 52 | * @return mixed The next value from the server, or null if there is none |
| 53 | */ |
| 54 | public function read() |
| 55 | { |
| 56 | if (!$this->has_real_call) { |
| 57 | $this->createRealCall(); |
| 58 | $this->has_real_call = true; |
| 59 | } |
| 60 | $response = $this->real_call->read(); |
| 61 | if ($response) { |
| 62 | $this->response = $response; |
| 63 | } |
| 64 | return $response; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Write a single message to the server. This cannot be called after |
| 69 | * writesDone is called. |
| 70 | * |
| 71 | * @param ByteBuffer $data The data to write |
| 72 | * @param array $options An array of options, possible keys: |
| 73 | * 'flags' => a number (optional) |
| 74 | */ |
| 75 | public function write($data, array $options = []) |
| 76 | { |
| 77 | if (!$this->has_real_call) { |
| 78 | $this->createRealCall($data); |
| 79 | $this->has_real_call = true; |
| 80 | } |
| 81 | $this->real_call->write($data, $options); |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Indicate that no more writes will be sent. |
| 86 | */ |
| 87 | public function writesDone() |
| 88 | { |
| 89 | if (!$this->has_real_call) { |
| 90 | $this->createRealCall(); |
| 91 | $this->has_real_call = true; |
| 92 | } |
| 93 | $this->real_call->writesDone(); |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Wait for the server to send the status, and return it. |
| 98 | * |
| 99 | * @return \stdClass The status object, with integer $code, string |
| 100 | * $details, and array $metadata members |
| 101 | */ |
| 102 | public function getStatus() |
| 103 | { |
| 104 | $status = $this->real_call->getStatus(); |
| 105 | $this->_rpcPostProcess($status, $this->response); |
| 106 | return $status; |
| 107 | } |
| 108 | } |
| 109 |