本文整理了Java中com.datastax.driver.core.Cluster.getClusterName()
方法的一些代码示例,展示了Cluster.getClusterName()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Cluster.getClusterName()
方法的具体详情如下:
包路径:com.datastax.driver.core.Cluster
类名称:Cluster
方法名:getClusterName
[英]The name of this cluster object.
Note that this is not the Cassandra cluster name, but rather a name assigned to this Cluster object. Currently, that name is only used for one purpose: to distinguish exposed JMX metrics when multiple Cluster instances live in the same JVM (which should be rare in the first place). That name can be set at Cluster building time (through Builder#withClusterName for instance) but will default to a name like cluster1 where each Cluster instance in the same JVM will have a different number.
[中]此群集对象的名称。
请注意,这不是Cassandra集群名称,而是分配给该集群对象的名称。目前,该名称仅用于一个目的:当多个集群实例生活在同一个JVM中时,区分公开的JMX度量(首先应该很少使用)。该名称可以在集群构建时设置(例如通过Builder#with clustername),但默认为cluster1这样的名称,其中同一JVM中的每个集群实例都有不同的编号。
代码示例来源:origin: apache/storm
/**
* {@inheritDoc}
*/
@Override
public void close() {
if (cluster != null && !cluster.isClosed()) {
LOG.info("Try to close connection to cluster: {}", cluster.getClusterName());
session.close();
cluster.close();
}
}
代码示例来源:origin: apache/storm
/**
* {@inheritDoc}
*/
@Override
public synchronized Session connect() throws NoHostAvailableException {
if (isDisconnected()) {
LOG.info("Connected to cluster: {}", cluster.getClusterName());
for (Host host : getAllHosts())
LOG.info("Datacenter: {}; Host: {}; Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack());
LOG.info("Connect to cluster using keyspace %s", keyspace);
session = cluster.connect(keyspace);
} else {
LOG.warn("{} - Already connected to cluster: {}", getExecutorName(), cluster.getClusterName());
}
if (session.isClosed()) {
LOG.warn("Session has been closed - create new one!");
this.session = cluster.newSession();
}
return session;
}
代码示例来源:origin: apache/usergrid
@Test
public void testGetClusterSession() {
Session session = dataStaxCluster.getClusterSession();
String clusterName = session.getCluster().getClusterName();
String keyspaceName = session.getLoggedKeyspace();
// cluster session is not logged to a keyspace
assertNull(keyspaceName);
assertNotNull(clusterName);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
protected void maybeLogNormalQuery(Host host, Statement statement, long latencyMs) {
if (NORMAL_LOGGER.isDebugEnabled()) {
String message =
String.format(
NORMAL_TEMPLATE,
cluster.getClusterName(),
host,
latencyMs,
statementAsString(statement));
logQuery(statement, null, NORMAL_LOGGER, message);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
protected void maybeLogSlowQuery(Host host, Statement statement, long latencyMs) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message =
String.format(
SLOW_TEMPLATE_MILLIS,
cluster.getClusterName(),
host,
latencyMs,
statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
protected void maybeLogErrorQuery(
Host host, Statement statement, Exception exception, long latencyMs) {
if (ERROR_LOGGER.isDebugEnabled()
&& !(exception instanceof CancelledSpeculativeExecutionException)) {
String message =
String.format(
ERROR_TEMPLATE,
cluster.getClusterName(),
host,
latencyMs,
statementAsString(statement));
logQuery(statement, exception, ERROR_LOGGER, message);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
protected void maybeLogSlowQuery(
Host host, Statement statement, long latencyMs, long threshold) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message =
String.format(
SLOW_TEMPLATE_PERCENTILE,
cluster.getClusterName(),
host,
latencyMs,
slowQueryLatencyThresholdPercentile,
threshold,
statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that metrics are enabled and exposed by JMX by default by checking that {@link
* Cluster#getMetrics()} is not null and 'clusterName-metrics:name=connected-to' MBean is present.
*
* @test_category metrics
*/
@Test(groups = "short")
public void should_enable_metrics_and_jmx_by_default() throws Exception {
assertThat(cluster().getMetrics()).isNotNull();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster().getClusterName() + "-metrics:name=connected-to");
MBeanInfo mBean = server.getMBeanInfo(clusterMetricsON);
assertThat(mBean).isNotNull();
assertThat(cluster().getConfiguration().getMetricsOptions().isEnabled()).isTrue();
assertThat(cluster().getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isTrue();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
.build();
try {
String clusterName = cluster.getClusterName();
cluster.init();
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that when metrics are enabled but JMX reporting is disabled via {@link
* Cluster.Builder#withoutJMXReporting()} that {@link Cluster#getMetrics()} is not null and
* 'clusterName-metrics:name=connected-to' MBean is present.
*
* @test_category metrics
*/
@Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
public void should_be_no_jmx_mbean_when_jmx_is_disabled() throws Exception {
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withoutJMXReporting()
.build());
try {
cluster.init();
assertThat(cluster.getMetrics()).isNotNull();
assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isTrue();
assertThat(cluster.getConfiguration().getMetricsOptions().isJMXReportingEnabled()).isFalse();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
server.getMBeanInfo(clusterMetricsON);
} finally {
cluster.close();
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that when metrics are disabled using {@link Cluster.Builder#withoutMetrics()} that
* {@link Cluster#getMetrics()} returns null and 'clusterName-metrics:name=connected-to' MBean is
* not present.
*
* @test_category metrics
*/
@Test(groups = "short", expectedExceptions = InstanceNotFoundException.class)
public void metrics_should_be_null_when_metrics_disabled() throws Exception {
Cluster cluster =
register(
Cluster.builder()
.addContactPoints(getContactPoints())
.withPort(ccm().getBinaryPort())
.withoutMetrics()
.build());
try {
cluster.init();
assertThat(cluster.getMetrics()).isNull();
assertThat(cluster.getConfiguration().getMetricsOptions().isEnabled()).isFalse();
ObjectName clusterMetricsON =
ObjectName.getInstance(cluster.getClusterName() + "-metrics:name=connected-to");
server.getMBeanInfo(clusterMetricsON);
} finally {
cluster.close();
}
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
protected void maybeLogErrorQuery(Host host, Statement statement, Exception exception, long latencyMs) {
if (ERROR_LOGGER.isDebugEnabled()) {
String message = String.format(ERROR_TEMPLATE, cluster.getClusterName(), host, latencyMs, statementAsString(statement));
logQuery(statement, exception, ERROR_LOGGER, message);
}
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
protected void maybeLogSlowQuery(Host host, Statement statement, long latencyMs) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message = String.format(SLOW_TEMPLATE_MILLIS, cluster.getClusterName(), host, latencyMs, statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
protected void maybeLogSlowQuery(Host host, Statement statement, long latencyMs, long threshold) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message = String.format(SLOW_TEMPLATE_PERCENTILE, cluster.getClusterName(), host, latencyMs, slowQueryLatencyThresholdPercentile, threshold, statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
代码示例来源:origin: io.zipkin/zipkin-cassandra-core
private static KeyspaceMetadata getKeyspaceMetadata(String keyspace, Cluster cluster) {
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new IllegalStateException(String.format(
"Cannot read keyspace metadata for give keyspace: %s and cluster: %s",
keyspace, cluster.getClusterName()));
}
return keyspaceMetadata;
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
protected void maybeLogSlowQuery(Host host, Statement statement, long latencyMs) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message = String.format(SLOW_TEMPLATE_MILLIS, cluster.getClusterName(), host, latencyMs, statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
protected void maybeLogNormalQuery(Host host, Statement statement, long latencyMs) {
if (NORMAL_LOGGER.isDebugEnabled()) {
String message = String.format(NORMAL_TEMPLATE, cluster.getClusterName(), host, latencyMs, statementAsString(statement));
logQuery(statement, null, NORMAL_LOGGER, message);
}
}
代码示例来源:origin: io.prestosql.cassandra/cassandra-driver
protected void maybeLogSlowQuery(Host host, Statement statement, long latencyMs) {
if (SLOW_LOGGER.isDebugEnabled()) {
String message = String.format(SLOW_TEMPLATE_MILLIS, cluster.getClusterName(), host, latencyMs, statementAsString(statement));
logQuery(statement, null, SLOW_LOGGER, message);
}
}
}
代码示例来源:origin: composable-systems/dropwizard-cassandra
public CassandraMetricSet(Cluster cluster) {
final String clusterName = cluster.getClusterName();
Map<String, Metric> driverMetrics = cluster.getMetrics().getRegistry().getMetrics();
ImmutableMap.Builder<String, Metric> builder = ImmutableMap.builder();
driverMetrics.forEach((k, v) -> builder.put(name(Cluster.class, clusterName, k), v));
metrics = builder.build();
}
代码示例来源:origin: io.zipkin.java/zipkin-storage-cassandra
static KeyspaceMetadata getKeyspaceMetadata(Session session) {
String keyspace = session.getLoggedKeyspace();
Cluster cluster = session.getCluster();
KeyspaceMetadata keyspaceMetadata = cluster.getMetadata().getKeyspace(keyspace);
if (keyspaceMetadata == null) {
throw new IllegalStateException(String.format(
"Cannot read keyspace metadata for give keyspace: %s and cluster: %s",
keyspace, cluster.getClusterName()));
}
return keyspaceMetadata;
}
内容来源于网络,如有侵权,请联系作者删除!