use of com.datastax.shaded.netty.channel.socket.SocketChannel in project cassandra by apache.
the class BulkLoader method buildSSLOptions.
private static SSLOptions buildSSLOptions(EncryptionOptions clientEncryptionOptions) {
if (!clientEncryptionOptions.isEnabled()) {
return null;
}
SSLContext sslContext;
try {
sslContext = SSLFactory.createSSLContext(clientEncryptionOptions, true);
} catch (IOException e) {
throw new RuntimeException("Could not create SSL Context.", e);
}
// Temporarily override newSSLEngine to set accepted protocols until it is added to
// RemoteEndpointAwareJdkSSLOptions. See CASSANDRA-13325 and CASSANDRA-16362.
RemoteEndpointAwareJdkSSLOptions sslOptions = new RemoteEndpointAwareJdkSSLOptions(sslContext, null) {
protected SSLEngine newSSLEngine(SocketChannel channel, InetSocketAddress remoteEndpoint) {
SSLEngine engine = super.newSSLEngine(channel, remoteEndpoint);
String[] acceptedProtocols = clientEncryptionOptions.acceptedProtocolsArray();
if (acceptedProtocols != null && acceptedProtocols.length > 0)
engine.setEnabledProtocols(acceptedProtocols);
return engine;
}
};
return sslOptions;
}
use of com.datastax.shaded.netty.channel.socket.SocketChannel in project cassandra by apache.
the class JavaDriverClient method connect.
public void connect(ProtocolOptions.Compression compression) throws Exception {
PoolingOptions poolingOpts = new PoolingOptions().setConnectionsPerHost(HostDistance.LOCAL, connectionsPerHost, connectionsPerHost).setMaxRequestsPerConnection(HostDistance.LOCAL, maxPendingPerConnection).setNewConnectionThreshold(HostDistance.LOCAL, 100);
HostAndPort hap = HostAndPort.fromString(host).withDefaultPort(port);
InetSocketAddress contact = new InetSocketAddress(InetAddress.getByName(hap.getHost()), hap.getPort());
Cluster.Builder clusterBuilder = Cluster.builder().addContactPointsWithPorts(contact).withPoolingOptions(poolingOpts).withoutJMXReporting().withProtocolVersion(protocolVersion).withoutMetrics();
if (loadBalancingPolicy != null)
clusterBuilder.withLoadBalancingPolicy(loadBalancingPolicy);
clusterBuilder.withCompression(compression);
if (encryptionOptions.isEnabled()) {
SSLContext sslContext;
sslContext = SSLFactory.createSSLContext(encryptionOptions, true);
// Temporarily override newSSLEngine to set accepted protocols until it is added to
// RemoteEndpointAwareJdkSSLOptions. See CASSANDRA-13325 and CASSANDRA-16362.
RemoteEndpointAwareJdkSSLOptions sslOptions = new RemoteEndpointAwareJdkSSLOptions(sslContext, null) {
protected SSLEngine newSSLEngine(SocketChannel channel, InetSocketAddress remoteEndpoint) {
SSLEngine engine = super.newSSLEngine(channel, remoteEndpoint);
String[] acceptedProtocols = encryptionOptions.acceptedProtocolsArray();
if (acceptedProtocols != null && acceptedProtocols.length > 0)
engine.setEnabledProtocols(acceptedProtocols);
return engine;
}
};
clusterBuilder.withSSL(sslOptions);
}
if (authProvider != null) {
clusterBuilder.withAuthProvider(authProvider);
} else if (username != null) {
clusterBuilder.withCredentials(username, password);
}
cluster = clusterBuilder.build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s, max pending requests per connection %d, max connections per host %d%n", metadata.getClusterName(), maxPendingPerConnection, connectionsPerHost);
for (Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s%n", host.getDatacenter(), host.getAddress() + ":" + host.getSocketAddress().getPort(), host.getRack());
}
session = cluster.connect();
}
Aggregations