Debian Codegraph @

src/objective-c/GRPCClient/private/GRPCCore/GRPCChannelPool.h

raw
1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #import <GRPCClient/GRPCCallOptions.h>
20
21 NS_ASSUME_NONNULL_BEGIN
22
23 @protocol GRPCChannel;
24 @class GRPCChannel;
25 @class GRPCChannelPool;
26 @class GRPCCompletionQueue;
27 @class GRPCChannelConfiguration;
28 @class GRPCWrappedCall;
29
30 /**
31 * A proxied channel object that can be retained and used to create GRPCWrappedCall object
32 * regardless of the current connection status. If a connection is not established when a
33 * GRPCWrappedCall object is requested, it issues a connection/reconnection. This behavior is to
34 * follow that of gRPC core's channel object.
35 */
36 @interface GRPCPooledChannel : NSObject
37
38 - (nullable instancetype)init NS_UNAVAILABLE;
39
40 + (nullable instancetype)new NS_UNAVAILABLE;
41
42 /**
43 * Initialize with an actual channel object \a channel and a reference to the channel pool.
44 */
45 - (nullable instancetype)initWithChannelConfiguration:
46 (GRPCChannelConfiguration *)channelConfiguration;
47
48 /**
49 * Create a GRPCWrappedCall object (grpc_call) from this channel. If channel is disconnected, get a
50 * new channel object from the channel pool.
51 */
52 - (nullable GRPCWrappedCall *)wrappedCallWithPath:(NSString *)path
53 completionQueue:(GRPCCompletionQueue *)queue
54 callOptions:(GRPCCallOptions *)callOptions;
55
56 /**
57 * Notify the pooled channel that a wrapped call object is no longer referenced and will be
58 * dealloc'ed.
59 */
60 - (void)notifyWrappedCallDealloc:(GRPCWrappedCall *)wrappedCall;
61
62 /**
63 * Force the channel to disconnect immediately. GRPCWrappedCall objects previously created with
64 * \a wrappedCallWithPath are failed if not already finished. Subsequent calls to
65 * unmanagedCallWithPath: will attempt to reconnect to the remote channel.
66 */
67 - (void)disconnect;
68
69 @end
70
71 /**
72 * Manage the pool of connected channels. When a channel is no longer referenced by any call,
73 * destroy the channel after a certain period of time elapsed.
74 */
75 @interface GRPCChannelPool : NSObject
76
77 - (nullable instancetype)init NS_UNAVAILABLE;
78
79 + (nullable instancetype)new NS_UNAVAILABLE;
80
81 /**
82 * Get the global channel pool.
83 */
84 + (nullable instancetype)sharedInstance;
85
86 /**
87 * Return a channel with a particular configuration. The channel may be a cached channel.
88 */
89 - (nullable GRPCPooledChannel *)channelWithHost:(NSString *)host
90 callOptions:(GRPCCallOptions *)callOptions;
91
92 /**
93 * Disconnect all channels in this pool.
94 */
95 - (void)disconnectAllChannels;
96
97 @end
98
99 NS_ASSUME_NONNULL_END