use of org.apache.cassandra.thrift.Cassandra.Client in project atlasdb by palantir.
the class CassandraClientFactory method getRawClient.
private static Cassandra.Client getRawClient(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws TException {
TSocket thriftSocket = new TSocket(addr.getHostString(), addr.getPort(), config.socketTimeoutMillis());
thriftSocket.open();
try {
thriftSocket.getSocket().setKeepAlive(true);
thriftSocket.getSocket().setSoTimeout(config.socketQueryTimeoutMillis());
} catch (SocketException e) {
log.error("Couldn't set socket keep alive for host {}", SafeArg.of("address", CassandraLogHelper.host(addr)));
}
if (config.usingSsl()) {
boolean success = false;
try {
final SSLSocketFactory factory;
if (config.sslConfiguration().isPresent()) {
factory = SslSocketFactories.createSslSocketFactory(config.sslConfiguration().get());
} else {
factory = sslSocketFactories.getUnchecked(addr);
}
SSLSocket socket = (SSLSocket) factory.createSocket(thriftSocket.getSocket(), addr.getHostString(), addr.getPort(), true);
thriftSocket = new TSocket(socket);
success = true;
} catch (IOException e) {
throw new TTransportException(e);
} finally {
if (!success) {
thriftSocket.close();
}
}
}
TTransport thriftFramedTransport = new TFramedTransport(thriftSocket, CassandraConstants.CLIENT_MAX_THRIFT_FRAME_SIZE_BYTES);
TProtocol protocol = new TBinaryProtocol(thriftFramedTransport);
Cassandra.Client client = new Cassandra.Client(protocol);
if (config.credentials().isPresent()) {
try {
login(client, config.credentials().get());
} catch (TException e) {
client.getOutputProtocol().getTransport().close();
log.error("Exception thrown attempting to authenticate with config provided credentials", e);
throw e;
}
}
return client;
}
use of org.apache.cassandra.thrift.Cassandra.Client in project atlasdb by palantir.
the class CassandraClientFactory method getRawClientWithKeyspace.
private static Cassandra.Client getRawClientWithKeyspace(InetSocketAddress addr, CassandraKeyValueServiceConfig config) throws Exception {
Client ret = getRawClient(addr, config);
try {
ret.set_keyspace(config.getKeyspaceOrThrow());
log.debug("Created new client for {}/{}{}{}", SafeArg.of("address", CassandraLogHelper.host(addr)), UnsafeArg.of("keyspace", config.getKeyspaceOrThrow()), SafeArg.of("usingSsl", config.usingSsl() ? " over SSL" : ""), UnsafeArg.of("usernameConfig", config.credentials().isPresent() ? " as user " + config.credentials().get().username() : ""));
return ret;
} catch (Exception e) {
ret.getOutputProtocol().getTransport().close();
throw e;
}
}
Aggregations