Class: Ilios::Cassandra::Cluster
- Inherits:
-
Object
- Object
- Ilios::Cassandra::Cluster
- Defined in:
- ext/ilios/ilios.c
Constant Summary collapse
- PROTOCOL_VERSION_V1 =
INT2NUM(CASS_PROTOCOL_VERSION_V1)
- PROTOCOL_VERSION_V2 =
INT2NUM(CASS_PROTOCOL_VERSION_V2)
- PROTOCOL_VERSION_V3 =
INT2NUM(CASS_PROTOCOL_VERSION_V3)
- PROTOCOL_VERSION_V4 =
INT2NUM(CASS_PROTOCOL_VERSION_V4)
- PROTOCOL_VERSION_V5 =
INT2NUM(CASS_PROTOCOL_VERSION_V5)
- PROTOCOL_VERSION_DSEV1 =
INT2NUM(CASS_PROTOCOL_VERSION_DSEV1)
- PROTOCOL_VERSION_DSEV2 =
INT2NUM(CASS_PROTOCOL_VERSION_DSEV2)
Instance Method Summary collapse
-
#connect ⇒ Cassandra::Session
Connects a session.
-
#connect_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for connecting to a node.
-
#constant_speculative_execution_policy(constant_delay_ms, max_speculative_executions) ⇒ Cassandra::Cluster
Enable constant speculative executions with the supplied settings.
-
#hosts(hosts) ⇒ Cassandra::Cluster
Sets the contact points.
-
#initialize ⇒ Cassandra::Cluster
constructor
Creates a new cluster.
-
#keyspace(keyspace) ⇒ Cassandra::Cluster
Sets the keyspace.
-
#port(port) ⇒ Cassandra::Cluster
Sets the port number.
-
#protocol_version(version) ⇒ Cassandra::Cluster
Sets the protocol version.
-
#request_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for waiting for a response from a node.
-
#resolve_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for waiting for DNS name resolution.
Constructor Details
#initialize ⇒ Cassandra::Cluster
Creates a new cluster.
31 32 33 34 35 36 37 38 39 |
# File 'ext/ilios/cluster.c', line 31
static VALUE cluster_initialize(VALUE self)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cassandra_cluster->cluster = cass_cluster_new();
return self;
}
|
Instance Method Details
#connect ⇒ Cassandra::Session
Connects a session.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'ext/ilios/cluster.c', line 48
static VALUE cluster_connect(VALUE self)
{
CassandraSession *cassandra_session;
CassandraCluster *cassandra_cluster;
CassFuture* connect_future;
VALUE cassandra_session_obj;
const char *keyspace = "";
GET_CLUSTER(self, cassandra_cluster);
if (cassandra_cluster->keyspace) {
keyspace = StringValueCStr(cassandra_cluster->keyspace);
}
cassandra_session_obj = CREATE_SESSION(cassandra_session);
cassandra_session->cluster_obj = self;
cassandra_session->session = cass_session_new();
connect_future = cass_session_connect_keyspace(cassandra_session->session, cassandra_cluster->cluster, keyspace);
nogvl_future_wait(connect_future);
if (cass_future_error_code(connect_future) != CASS_OK) {
char error[4096] = { 0 };
strncpy(error, cass_error_desc(cass_future_error_code(connect_future)), sizeof(error) - 1);
cass_future_free(connect_future);
rb_raise(eConnectError, "Unable to connect: %s", error);
return Qnil;
}
cass_future_free(connect_future);
return cassandra_session_obj;
}
|
#connect_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for connecting to a node. Default is 5000
milliseconds.
164 165 166 167 168 169 170 171 172 |
# File 'ext/ilios/cluster.c', line 164
static VALUE cluster_connect_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_connect_timeout(cassandra_cluster->cluster, NUM2UINT(timeout_ms));
return self;
}
|
#constant_speculative_execution_policy(constant_delay_ms, max_speculative_executions) ⇒ Cassandra::Cluster
Enable constant speculative executions with the supplied settings.
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'ext/ilios/cluster.c', line 215
static VALUE cluster_constant_speculative_execution_policy(VALUE self, VALUE constant_delay_ms, VALUE max_speculative_executions)
{
CassandraCluster *cassandra_cluster;
if (NUM2LONG(constant_delay_ms) < 0 || NUM2INT(max_speculative_executions) < 0) {
rb_raise(rb_eArgError, "Bad parameters.");
}
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_constant_speculative_execution_policy(cassandra_cluster->cluster, NUM2LONG(constant_delay_ms), NUM2INT(max_speculative_executions));
return self;
}
|
#hosts(hosts) ⇒ Cassandra::Cluster
Sets the contact points.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'ext/ilios/cluster.c', line 86
static VALUE cluster_hosts(VALUE self, VALUE hosts)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
Check_Type(hosts, T_ARRAY);
if (RARRAY_LEN(hosts) == 0) {
rb_raise(rb_eArgError, "No host exists.");
}
for (int i = 0; i < RARRAY_LEN(hosts); i++) {
VALUE host = RARRAY_AREF(hosts, i);
cass_cluster_set_contact_points(cassandra_cluster->cluster, StringValueCStr(host));
}
return self;
}
|
#keyspace(keyspace) ⇒ Cassandra::Cluster
Sets the keyspace.
128 129 130 131 132 133 134 135 136 137 138 |
# File 'ext/ilios/cluster.c', line 128
static VALUE cluster_keyspace(VALUE self, VALUE keyspace)
{
CassandraCluster *cassandra_cluster;
StringValue(keyspace);
GET_CLUSTER(self, cassandra_cluster);
cassandra_cluster->keyspace = keyspace;
return self;
}
|
#port(port) ⇒ Cassandra::Cluster
Sets the port number. Default is 9042
.
112 113 114 115 116 117 118 119 120 |
# File 'ext/ilios/cluster.c', line 112
static VALUE cluster_port(VALUE self, VALUE port)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_port(cassandra_cluster->cluster, NUM2INT(port));
return self;
}
|
#protocol_version(version) ⇒ Cassandra::Cluster
Sets the protocol version. The driver will automatically downgrade to the lowest supported protocol version. Default is PROTOCOL_VERSION_V4
.
147 148 149 150 151 152 153 154 155 |
# File 'ext/ilios/cluster.c', line 147
static VALUE cluster_protocol_version(VALUE self, VALUE version)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_protocol_version(cassandra_cluster->cluster, NUM2INT(version));
return self;
}
|
#request_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for waiting for a response from a node. Default is 12000
milliseconds.
181 182 183 184 185 186 187 188 189 |
# File 'ext/ilios/cluster.c', line 181
static VALUE cluster_request_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_request_timeout(cassandra_cluster->cluster, NUM2UINT(timeout_ms));
return self;
}
|
#resolve_timeout(timeout_ms) ⇒ Cassandra::Cluster
Sets the timeout for waiting for DNS name resolution. Default is 2000
milliseconds.
198 199 200 201 202 203 204 205 206 |
# File 'ext/ilios/cluster.c', line 198
static VALUE cluster_resolve_timeout(VALUE self, VALUE timeout_ms)
{
CassandraCluster *cassandra_cluster;
GET_CLUSTER(self, cassandra_cluster);
cass_cluster_set_resolve_timeout(cassandra_cluster->cluster, NUM2UINT(timeout_ms));
return self;
}
|