aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private/GRPCChannel.h
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-11-08 22:01:10 -0800
committerGravatar Muxi Yan <mxyan@google.com>2018-11-08 22:01:10 -0800
commit37dbad80d5254f9bf17076d12b22b7a081e6e9dc (patch)
tree367a86331b789917812b15ec4dde636b32560023 /src/objective-c/GRPCClient/private/GRPCChannel.h
parentd72d5b2c8eaa8a434a7db4624fe6a45bc0d6bde4 (diff)
Refactor channel pool
Diffstat (limited to 'src/objective-c/GRPCClient/private/GRPCChannel.h')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCChannel.h69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCChannel.h b/src/objective-c/GRPCClient/private/GRPCChannel.h
index e1bf8fb1af..bbe0ba5390 100644
--- a/src/objective-c/GRPCClient/private/GRPCChannel.h
+++ b/src/objective-c/GRPCClient/private/GRPCChannel.h
@@ -20,11 +20,37 @@
#include <grpc/grpc.h>
+@protocol GRPCChannelFactory;
+
@class GRPCCompletionQueue;
@class GRPCCallOptions;
@class GRPCChannelConfiguration;
struct grpc_channel_credentials;
+NS_ASSUME_NONNULL_BEGIN
+
+/** Caching signature of a channel. */
+@interface GRPCChannelConfiguration : NSObject<NSCopying>
+
+/** The host that this channel is connected to. */
+@property(copy, readonly) NSString *host;
+
+/**
+ * Options of the corresponding call. Note that only the channel-related options are of interest to
+ * this class.
+ */
+@property(strong, readonly) GRPCCallOptions *callOptions;
+
+/** Acquire the factory to generate a new channel with current configurations. */
+@property(readonly) id<GRPCChannelFactory> channelFactory;
+
+/** Acquire the dictionary of channel args with current configurations. */
+@property(copy, readonly) NSDictionary *channelArgs;
+
+- (nullable instancetype)initWithHost:(NSString *)host callOptions:(GRPCCallOptions *)callOptions;
+
+@end
+
/**
* Each separate instance of this class represents at least one TCP connection to the provided host.
*/
@@ -35,40 +61,45 @@ struct grpc_channel_credentials;
+ (nullable instancetype) new NS_UNAVAILABLE;
/**
- * Returns a channel connecting to \a host with options as \a callOptions. The channel may be new
- * or a cached channel that is already connected.
+ * Create a channel with remote \a host and signature \a channelConfigurations. Destroy delay is
+ * defaulted to 30 seconds.
*/
-+ (nullable instancetype)channelWithHost:(nonnull NSString *)host
- callOptions:(nullable GRPCCallOptions *)callOptions;
+- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration;
/**
- * Create a channel object with the signature \a config.
+ * Create a channel with remote \a host, signature \a channelConfigurations, and destroy delay of
+ * \a destroyDelay.
*/
-+ (nullable instancetype)createChannelWithConfiguration:(nonnull GRPCChannelConfiguration *)config;
+- (nullable instancetype)initWithChannelConfiguration:(GRPCChannelConfiguration *)channelConfiguration
+ destroyDelay:(NSTimeInterval)destroyDelay NS_DESIGNATED_INITIALIZER;
/**
- * Get a grpc core call object from this channel.
+ * Create a grpc core call object from this channel. The channel's refcount is added by 1. If no
+ * call is created, NULL is returned, and if the reason is because the channel is already
+ * disconnected, \a disconnected is set to YES. When the returned call is unreffed, the caller is
+ * obligated to call \a unref method once. \a disconnected may be null.
*/
-- (nullable grpc_call *)unmanagedCallWithPath:(nonnull NSString *)path
- completionQueue:(nonnull GRPCCompletionQueue *)queue
- callOptions:(nonnull GRPCCallOptions *)callOptions;
+- (nullable grpc_call *)unmanagedCallWithPath:(NSString *)path
+ completionQueue:(GRPCCompletionQueue *)queue
+ callOptions:(GRPCCallOptions *)callOptions
+ disconnected:(BOOL * _Nullable)disconnected;
/**
- * Increase the refcount of the channel. If the channel was timed to be destroyed, cancel the timer.
+ * Unref the channel when a call is done. It also decreases the channel's refcount. If the refcount
+ * of the channel decreases to 0, the channel is destroyed after the destroy delay.
*/
-- (void)ref;
+- (void)unref;
/**
- * Decrease the refcount of the channel. If the refcount of the channel decrease to 0, the channel
- * is destroyed after 30 seconds.
+ * Force the channel to be disconnected and destroyed.
*/
-- (void)unref;
+- (void)disconnect;
/**
- * Force the channel to be disconnected and destroyed immediately.
+ * Return whether the channel is already disconnected.
*/
-- (void)disconnect;
+@property(readonly) BOOL disconnected;
-// TODO (mxyan): deprecate with GRPCCall:closeOpenConnections
-+ (void)closeOpenConnections;
@end
+
+NS_ASSUME_NONNULL_END