39
39
40
40
import com .datastax .driver .core .AuthProvider ;
41
41
import com .datastax .driver .core .Cluster ;
42
- import com .datastax .driver .core .HostDistance ;
43
42
import com .datastax .driver .core .PoolingOptions ;
44
43
import com .datastax .driver .core .ProtocolOptions .Compression ;
45
44
import com .datastax .driver .core .Session ;
@@ -60,27 +59,31 @@ public class CassandraClusterFactoryBean implements FactoryBean<Cluster>, Initia
60
59
61
60
public static final String DEFAULT_CONTACT_POINTS = "localhost" ;
62
61
public static final boolean DEFAULT_METRICS_ENABLED = true ;
62
+ public static final boolean DEFAULT_DEFERRED_INITIALIZATION = false ;
63
+ public static final boolean DEFAULT_JMX_REPORTING_ENABLED = true ;
63
64
public static final int DEFAULT_PORT = 9042 ;
64
65
65
66
protected static final Logger log = LoggerFactory .getLogger (CassandraClusterFactoryBean .class );
66
67
67
68
private Cluster cluster ;
68
- private boolean accumulating = true ;
69
69
70
70
/*
71
71
* Attributes needed for cluster builder
72
72
*/
73
73
private String contactPoints = DEFAULT_CONTACT_POINTS ;
74
74
private int port = CassandraClusterFactoryBean .DEFAULT_PORT ;
75
75
private CompressionType compressionType ;
76
- private PoolingOptionsConfig localPoolingOptions ;
77
- private PoolingOptionsConfig remotePoolingOptions ;
78
- private SocketOptionsConfig socketOptions ;
76
+ private PoolingOptions poolingOptions ;
77
+ private SocketOptions socketOptions ;
79
78
private AuthProvider authProvider ;
79
+ private String username ;
80
+ private String password ;
80
81
private LoadBalancingPolicy loadBalancingPolicy ;
81
82
private ReconnectionPolicy reconnectionPolicy ;
82
83
private RetryPolicy retryPolicy ;
83
84
private boolean metricsEnabled = DEFAULT_METRICS_ENABLED ;
85
+ private boolean deferredInitialization = DEFAULT_DEFERRED_INITIALIZATION ;
86
+ private boolean jmxReportingEnabled = DEFAULT_JMX_REPORTING_ENABLED ;
84
87
private Set <KeyspaceActionSpecification <?>> keyspaceSpecifications = new HashSet <KeyspaceActionSpecification <?>>();
85
88
private List <CreateKeyspaceSpecification > keyspaceCreations = new ArrayList <CreateKeyspaceSpecification >();
86
89
private List <DropKeyspaceSpecification > keyspaceDrops = new ArrayList <DropKeyspaceSpecification >();
@@ -124,20 +127,20 @@ public void afterPropertiesSet() throws Exception {
124
127
builder .withCompression (convertCompressionType (compressionType ));
125
128
}
126
129
127
- if (localPoolingOptions != null ) {
128
- builder .withPoolingOptions (configPoolingOptions (HostDistance .LOCAL , localPoolingOptions ));
129
- }
130
-
131
- if (remotePoolingOptions != null ) {
132
- builder .withPoolingOptions (configPoolingOptions (HostDistance .REMOTE , remotePoolingOptions ));
130
+ if (poolingOptions != null ) {
131
+ builder .withPoolingOptions (poolingOptions );
133
132
}
134
133
135
134
if (socketOptions != null ) {
136
- builder .withSocketOptions (configSocketOptions ( socketOptions ) );
135
+ builder .withSocketOptions (socketOptions );
137
136
}
138
137
139
138
if (authProvider != null ) {
140
139
builder .withAuthProvider (authProvider );
140
+
141
+ if (username != null ) {
142
+ builder .withCredentials (username , password );
143
+ }
141
144
}
142
145
143
146
if (loadBalancingPolicy != null ) {
@@ -152,10 +155,18 @@ public void afterPropertiesSet() throws Exception {
152
155
builder .withRetryPolicy (retryPolicy );
153
156
}
154
157
158
+ if (deferredInitialization ) {
159
+ builder .withDeferredInitialization ();
160
+ }
161
+
155
162
if (!metricsEnabled ) {
156
163
builder .withoutMetrics ();
157
164
}
158
165
166
+ if (!jmxReportingEnabled ) {
167
+ builder .withoutJMXReporting ();
168
+ }
169
+
159
170
cluster = builder .build ();
160
171
161
172
generateSpecificationsFromFactoryBeans ();
@@ -256,15 +267,11 @@ public void setCompressionType(CompressionType compressionType) {
256
267
this .compressionType = compressionType ;
257
268
}
258
269
259
- public void setLocalPoolingOptions (PoolingOptionsConfig localPoolingOptions ) {
260
- this .localPoolingOptions = localPoolingOptions ;
261
- }
262
-
263
- public void setRemotePoolingOptions (PoolingOptionsConfig remotePoolingOptions ) {
264
- this .remotePoolingOptions = remotePoolingOptions ;
270
+ public void setPoolingOptions (PoolingOptions poolingOptions ) {
271
+ this .poolingOptions = poolingOptions ;
265
272
}
266
273
267
- public void setSocketOptions (SocketOptionsConfig socketOptions ) {
274
+ public void setSocketOptions (SocketOptions socketOptions ) {
268
275
this .socketOptions = socketOptions ;
269
276
}
270
277
@@ -322,55 +329,6 @@ private static Compression convertCompressionType(CompressionType type) {
322
329
throw new IllegalArgumentException ("unknown compression type " + type );
323
330
}
324
331
325
- private static PoolingOptions configPoolingOptions (HostDistance hostDistance , PoolingOptionsConfig config ) {
326
- PoolingOptions poolingOptions = new PoolingOptions ();
327
-
328
- if (config .getMinSimultaneousRequests () != null ) {
329
- poolingOptions
330
- .setMinSimultaneousRequestsPerConnectionThreshold (hostDistance , config .getMinSimultaneousRequests ());
331
- }
332
- if (config .getMaxSimultaneousRequests () != null ) {
333
- poolingOptions
334
- .setMaxSimultaneousRequestsPerConnectionThreshold (hostDistance , config .getMaxSimultaneousRequests ());
335
- }
336
- if (config .getCoreConnections () != null ) {
337
- poolingOptions .setCoreConnectionsPerHost (hostDistance , config .getCoreConnections ());
338
- }
339
- if (config .getMaxConnections () != null ) {
340
- poolingOptions .setMaxConnectionsPerHost (hostDistance , config .getMaxConnections ());
341
- }
342
-
343
- return poolingOptions ;
344
- }
345
-
346
- private static SocketOptions configSocketOptions (SocketOptionsConfig config ) {
347
- SocketOptions socketOptions = new SocketOptions ();
348
-
349
- if (config .getConnectTimeoutMls () != null ) {
350
- socketOptions .setConnectTimeoutMillis (config .getConnectTimeoutMls ());
351
- }
352
- if (config .getKeepAlive () != null ) {
353
- socketOptions .setKeepAlive (config .getKeepAlive ());
354
- }
355
- if (config .getReuseAddress () != null ) {
356
- socketOptions .setReuseAddress (config .getReuseAddress ());
357
- }
358
- if (config .getSoLinger () != null ) {
359
- socketOptions .setSoLinger (config .getSoLinger ());
360
- }
361
- if (config .getTcpNoDelay () != null ) {
362
- socketOptions .setTcpNoDelay (config .getTcpNoDelay ());
363
- }
364
- if (config .getReceiveBufferSize () != null ) {
365
- socketOptions .setReceiveBufferSize (config .getReceiveBufferSize ());
366
- }
367
- if (config .getSendBufferSize () != null ) {
368
- socketOptions .setSendBufferSize (config .getSendBufferSize ());
369
- }
370
-
371
- return socketOptions ;
372
- }
373
-
374
332
/**
375
333
* @return Returns the keyspaceSpecifications.
376
334
*/
@@ -389,16 +347,30 @@ public void setKeyspaceSpecifications(Set<KeyspaceActionSpecification<?>> keyspa
389
347
}
390
348
391
349
/**
392
- * @return Returns the accumulating.
350
+ * @param username The username to set.
351
+ */
352
+ public void setUsername (String username ) {
353
+ this .username = username ;
354
+ }
355
+
356
+ /**
357
+ * @param password The password to set.
358
+ */
359
+ public void setPassword (String password ) {
360
+ this .password = password ;
361
+ }
362
+
363
+ /**
364
+ * @param deferredInitialization The deferredInitialization to set.
393
365
*/
394
- public boolean isAccumulating ( ) {
395
- return accumulating ;
366
+ public void setDeferredInitialization ( boolean deferredInitialization ) {
367
+ this . deferredInitialization = deferredInitialization ;
396
368
}
397
369
398
370
/**
399
- * @param accumulating The accumulating to set.
371
+ * @param jmxReportingEnabled The jmxReportingEnabled to set.
400
372
*/
401
- public void setAccumulating (boolean accumulating ) {
402
- this .accumulating = accumulating ;
373
+ public void setJmxReportingEnabled (boolean jmxReportingEnabled ) {
374
+ this .jmxReportingEnabled = jmxReportingEnabled ;
403
375
}
404
376
}
0 commit comments