16
16
import NIO
17
17
18
18
// TODO: add more config option per C++ cluster impl
19
- public extension CassandraClient {
19
+ extension CassandraClient {
20
20
/// Configuration for the ``CassandraClient``.
21
- struct Configuration : CustomStringConvertible {
21
+ public struct Configuration : CustomStringConvertible {
22
22
public typealias ContactPoints = [ String ]
23
23
24
24
/// Provides the initial `ContactPoints` of the Cassandra cluster.
25
25
/// This can be a subset since each Cassandra instance is capable of discovering its peers.
26
26
public var contactPointsProvider : ( @escaping ( Result < ContactPoints , Swift . Error > ) -> Void ) -> Void
27
+
27
28
public var port : Int32
28
29
public var protocolVersion : ProtocolVersion
29
30
public var username : String ?
@@ -37,7 +38,7 @@ public extension CassandraClient {
37
38
public var coreConnectionsPerHost : UInt32 ?
38
39
public var tcpNodelay : Bool ?
39
40
public var tcpKeepalive : Bool ?
40
- public var tcpKeepaliveDelaySeconds : UInt32
41
+ public var tcpKeepaliveDelaySeconds : UInt32 = 0
41
42
public var connectionHeartbeatInterval : UInt32 ?
42
43
public var connectionIdleTimeout : UInt32 ?
43
44
public var schema : Bool ?
@@ -47,6 +48,9 @@ public extension CassandraClient {
47
48
public var prepareStrategy : PrepareStrategy ?
48
49
public var compact : Bool ?
49
50
51
+ /// Sets the cluster's consistency level. Default is `.localOne`.
52
+ public var consistency : CassandraClient . Consistency ?
53
+
50
54
public enum SpeculativeExecutionPolicy {
51
55
case constant( delayInMillseconds: Int64 , maxExecutions: Int32 )
52
56
case disabled
@@ -68,51 +72,11 @@ public extension CassandraClient {
68
72
public init (
69
73
contactPointsProvider: @escaping ( @escaping ( Result < ContactPoints , Swift . Error > ) -> Void ) -> Void ,
70
74
port: Int32 ,
71
- protocolVersion: ProtocolVersion ,
72
- username: String ? = nil ,
73
- password: String ? = nil ,
74
- ssl: SSL ? = nil ,
75
- keyspace: String ? = nil ,
76
- numIOThreads: UInt32 ? = nil ,
77
- connectTimeoutMillis: UInt32 ? = nil ,
78
- requestTimeoutMillis: UInt32 ? = nil ,
79
- resolveTimeoutMillis: UInt32 ? = nil ,
80
- coreConnectionsPerHost: UInt32 ? = nil ,
81
- tcpNodelay: Bool ? = nil ,
82
- tcpKeepalive: Bool ? = nil ,
83
- tcpKeepaliveDelaySeconds: UInt32 = 0 ,
84
- connectionHeartbeatInterval: UInt32 ? = nil ,
85
- connectionIdleTimeout: UInt32 ? = nil ,
86
- schema: Bool ? = nil ,
87
- hostnameResolution: Bool ? = nil ,
88
- randomizedContactPoints: Bool ? = nil ,
89
- speculativeExecutionPolicy: SpeculativeExecutionPolicy ? = nil ,
90
- prepareStrategy: PrepareStrategy ? = nil ,
91
- compact: Bool ? = nil
75
+ protocolVersion: ProtocolVersion
92
76
) {
93
77
self . contactPointsProvider = contactPointsProvider
94
78
self . port = port
95
79
self . protocolVersion = protocolVersion
96
- self . username = username
97
- self . password = password
98
- self . ssl = ssl
99
- self . keyspace = keyspace
100
- self . numIOThreads = numIOThreads
101
- self . connectTimeoutMillis = connectTimeoutMillis
102
- self . requestTimeoutMillis = requestTimeoutMillis
103
- self . resolveTimeoutMillis = resolveTimeoutMillis
104
- self . coreConnectionsPerHost = coreConnectionsPerHost
105
- self . tcpNodelay = tcpNodelay
106
- self . tcpKeepalive = tcpKeepalive
107
- self . tcpKeepaliveDelaySeconds = tcpKeepaliveDelaySeconds
108
- self . connectionHeartbeatInterval = connectionHeartbeatInterval
109
- self . connectionIdleTimeout = connectionIdleTimeout
110
- self . schema = schema
111
- self . hostnameResolution = hostnameResolution
112
- self . randomizedContactPoints = randomizedContactPoints
113
- self . speculativeExecutionPolicy = speculativeExecutionPolicy
114
- self . prepareStrategy = prepareStrategy
115
- self . compact = compact
116
80
}
117
81
118
82
internal func makeCluster( on eventLoop: EventLoop ) -> EventLoopFuture < Cluster > {
@@ -167,40 +131,40 @@ public extension CassandraClient {
167
131
if let ssl = self . ssl {
168
132
try cluster. setSSL ( try ssl. makeSSLContext ( ) )
169
133
}
170
- if let value = numIOThreads {
134
+ if let value = self . numIOThreads {
171
135
try cluster. setNumThreadsIO ( value)
172
136
}
173
- if let value = connectTimeoutMillis {
137
+ if let value = self . connectTimeoutMillis {
174
138
try cluster. setConnectTimeout ( value)
175
139
}
176
- if let value = requestTimeoutMillis {
140
+ if let value = self . requestTimeoutMillis {
177
141
try cluster. setRequestTimeout ( value)
178
142
}
179
- if let value = resolveTimeoutMillis {
143
+ if let value = self . resolveTimeoutMillis {
180
144
try cluster. setResolveTimeout ( value)
181
145
}
182
- if let value = coreConnectionsPerHost {
146
+ if let value = self . coreConnectionsPerHost {
183
147
try cluster. setCoreConnectionsPerHost ( value)
184
148
}
185
- if let value = tcpNodelay {
149
+ if let value = self . tcpNodelay {
186
150
try cluster. setTcpNodelay ( value)
187
151
}
188
- if let value = tcpKeepalive {
152
+ if let value = self . tcpKeepalive {
189
153
try cluster. setTcpKeepalive ( value, delayInSeconds: self . tcpKeepaliveDelaySeconds)
190
154
}
191
- if let value = connectionHeartbeatInterval {
155
+ if let value = self . connectionHeartbeatInterval {
192
156
try cluster. setConnectionHeartbeatInterval ( value)
193
157
}
194
- if let value = connectionIdleTimeout {
158
+ if let value = self . connectionIdleTimeout {
195
159
try cluster. setConnectionIdleTimeout ( value)
196
160
}
197
- if let value = schema {
161
+ if let value = self . schema {
198
162
try cluster. setUseSchema ( value)
199
163
}
200
- if let value = hostnameResolution {
164
+ if let value = self . hostnameResolution {
201
165
try cluster. setUseHostnameResolution ( value)
202
166
}
203
- if let value = randomizedContactPoints {
167
+ if let value = self . randomizedContactPoints {
204
168
try cluster. setUseRandomizedContactPoints ( value)
205
169
}
206
170
switch self . speculativeExecutionPolicy {
@@ -219,9 +183,12 @@ public extension CassandraClient {
219
183
case . none:
220
184
break
221
185
}
222
- if let value = compact {
186
+ if let value = self . compact {
223
187
try cluster. setNoCompact ( !value)
224
188
}
189
+ if let value = self . consistency {
190
+ try cluster. setConsistency ( value. cassConsistency)
191
+ }
225
192
226
193
return cluster
227
194
}
@@ -338,6 +305,10 @@ internal final class Cluster {
338
305
try self . checkResult { cass_cluster_set_no_compact ( self . rawPointer, enabled ? cass_true : cass_false) }
339
306
}
340
307
308
+ func setConsistency( _ consistency: CassConsistency ) throws {
309
+ try self . checkResult { cass_cluster_set_consistency ( self . rawPointer, consistency) }
310
+ }
311
+
341
312
func setSSL( _ ssl: SSLContext ) throws {
342
313
cass_cluster_set_ssl ( self . rawPointer, ssl. rawPointer)
343
314
}
@@ -352,8 +323,8 @@ internal final class Cluster {
352
323
353
324
// MARK: - SSL
354
325
355
- public extension CassandraClient . Configuration {
356
- struct SSL {
326
+ extension CassandraClient . Configuration {
327
+ public struct SSL {
357
328
public var trustedCertificates : [ String ] ?
358
329
public var verifyFlag : VerifyFlag ?
359
330
public var cert : String ?
@@ -373,9 +344,7 @@ public extension CassandraClient.Configuration {
373
344
case peerIdentityDNS
374
345
}
375
346
376
- public init ( trustedCertificates: [ String ] ? ) {
377
- self . trustedCertificates = trustedCertificates
378
- }
347
+ public init ( ) { }
379
348
380
349
func makeSSLContext( ) throws -> SSLContext {
381
350
let sslContext = SSLContext ( )
0 commit comments