All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.datastax.oss.driver.api.core.metadata.Metadata Maven / Gradle / Ivy

The newest version!
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.datastax.oss.driver.api.core.metadata;

import com.datastax.oss.driver.api.core.CqlIdentifier;
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
import com.datastax.oss.driver.api.core.session.Session;
import edu.umd.cs.findbugs.annotations.NonNull;
import java.net.InetSocketAddress;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;

/**
 * The metadata of the Cassandra cluster that this driver instance is connected to.
 *
 * 

Updates to this object are guaranteed to be atomic: the node list, schema, and token metadata * are immutable, and will always be consistent for a given metadata instance. The node instances * are the only mutable objects in the hierarchy, and some of their fields will be modified * dynamically (in particular the node state). * * @see Session#getMetadata() */ public interface Metadata { /** * The nodes known to the driver, indexed by their unique identifier ({@code host_id} in {@code * system.local}/{@code system.peers}). This might include nodes that are currently viewed as * down, or ignored by the load balancing policy. */ @NonNull Map getNodes(); /** * Finds the node with the given {@linkplain Node#getEndPoint() connection information}, if it * exists. * *

Note that this method performs a linear search of {@link #getNodes()}. */ @NonNull default Optional findNode(@NonNull EndPoint endPoint) { for (Node node : getNodes().values()) { if (node.getEndPoint().equals(endPoint)) { return Optional.of(node); } } return Optional.empty(); } /** * Finds the node with the given untranslated {@linkplain Node#getBroadcastRpcAddress() * broadcast RPC address}, if it exists. * *

Note that this method performs a linear search of {@link #getNodes()}. */ @NonNull default Optional findNode(@NonNull InetSocketAddress broadcastRpcAddress) { for (Node node : getNodes().values()) { Optional o = node.getBroadcastRpcAddress(); if (o.isPresent() && o.get().equals(broadcastRpcAddress)) { return Optional.of(node); } } return Optional.empty(); } /** * The keyspaces defined in this cluster. * *

Note that schema metadata can be disabled or restricted to a subset of keyspaces, therefore * this map might be empty or incomplete. * * @see DefaultDriverOption#METADATA_SCHEMA_ENABLED * @see Session#setSchemaMetadataEnabled(Boolean) * @see DefaultDriverOption#METADATA_SCHEMA_REFRESHED_KEYSPACES */ @NonNull Map getKeyspaces(); @NonNull default Optional getKeyspace(@NonNull CqlIdentifier keyspaceId) { return Optional.ofNullable(getKeyspaces().get(keyspaceId)); } /** * Shortcut for {@link #getKeyspace(CqlIdentifier) * getKeyspace(CqlIdentifier.fromCql(keyspaceName))}. */ @NonNull default Optional getKeyspace(@NonNull String keyspaceName) { return getKeyspace(CqlIdentifier.fromCql(keyspaceName)); } /** * The token map for this cluster. * *

Note that this property might be absent if token metadata was disabled, or if there was a * runtime error while computing the map (this would generate a warning log). * * @see DefaultDriverOption#METADATA_TOKEN_MAP_ENABLED */ @NonNull Optional getTokenMap(); /** * The cluster name to which this session is connected. The Optional returned should contain the * value from the server for system.local.cluster_name. * *

Note that this method has a default implementation for backwards compatibility. It is * expected that any implementing classes override this method. */ @NonNull default Optional getClusterName() { return Optional.empty(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy