1414
1515namespace Apache . IoTDB
1616{
17- public class SessionPool
17+
18+ public class SessionPool : IDisposable
1819 {
1920 private static int SuccessCode => 200 ;
2021 private static readonly TSProtocolVersion ProtocolVersion = TSProtocolVersion . IOTDB_SERVICE_PROTOCOL_V3 ;
@@ -89,7 +90,9 @@ public SessionPool(
8990 string password = "root" ,
9091 int fetchSize = 1000 ,
9192 string zoneId = "UTC+08:00" ,
92- int poolSize = 8 )
93+ int poolSize = 8 ,
94+ bool enableRpcCompression = true
95+ )
9396 {
9497 _host = host ;
9598 _port = port ;
@@ -99,8 +102,12 @@ public SessionPool(
99102 _fetchSize = fetchSize ;
100103 _debugMode = false ;
101104 _poolSize = poolSize ;
102- }
103- ILoggerFactory factory ;
105+ _enableRpcCompression = enableRpcCompression ;
106+ }
107+
108+ ILoggerFactory factory ;
109+ private bool disposedValue ;
110+
104111 public void OpenDebugMode ( Action < ILoggingBuilder > configure )
105112 {
106113 _debugMode = true ;
@@ -111,16 +118,22 @@ public void OpenDebugMode(Action<ILoggingBuilder> configure)
111118 public void CloseDebugMode ( )
112119 {
113120 _debugMode = false ;
114- }
115-
121+ }
122+
116123 public async Task Open ( bool enableRpcCompression , CancellationToken cancellationToken = default )
124+ {
125+ _enableRpcCompression = enableRpcCompression ;
126+ await Open ( cancellationToken ) ;
127+ }
128+
129+ public async Task Open ( CancellationToken cancellationToken = default )
117130 {
118- _clients = new ConcurrentClientQueue ( ) ;
119- _enableRpcCompression = enableRpcCompression ;
120-
131+ _clients = new ConcurrentClientQueue ( ) ;
132+
133+
121134 for ( var index = 0 ; index < _poolSize ; index ++ )
122135 {
123- _clients . Add ( await CreateAndOpen ( enableRpcCompression , cancellationToken ) ) ;
136+ _clients . Add ( await CreateAndOpen ( _enableRpcCompression , cancellationToken ) ) ;
124137 }
125138 }
126139
@@ -2081,15 +2094,28 @@ public async Task<List<string>> ShowPathsTemplateUsingOnAsync(string templateNam
20812094 {
20822095 _clients . Add ( client ) ;
20832096 }
2084- }
2085-
2086-
2087-
2088-
2089-
2090-
2091-
2092-
2093-
2097+ }
2098+
2099+ protected virtual void Dispose ( bool disposing )
2100+ {
2101+ if ( ! disposedValue )
2102+ {
2103+ if ( disposing )
2104+ {
2105+ #if NET461_OR_GREATER || NETSTANDARD2_0
2106+ #else
2107+ _clients . ClientQueue . Clear ( ) ;
2108+ #endif
2109+ }
2110+ _clients = null ;
2111+ disposedValue = true ;
2112+ }
2113+ }
2114+
2115+ public void Dispose ( )
2116+ {
2117+ Dispose ( disposing : true ) ;
2118+ GC . SuppressFinalize ( this ) ;
2119+ }
20942120 }
20952121}
0 commit comments