当前位置: 首页>>代码示例>>Java>>正文


Java TokenMetadata.sortedTokens方法代码示例

本文整理汇总了Java中org.apache.cassandra.locator.TokenMetadata.sortedTokens方法的典型用法代码示例。如果您正苦于以下问题:Java TokenMetadata.sortedTokens方法的具体用法?Java TokenMetadata.sortedTokens怎么用?Java TokenMetadata.sortedTokens使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.locator.TokenMetadata的用法示例。


在下文中一共展示了TokenMetadata.sortedTokens方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPrimaryRangesForEndpoint

import org.apache.cassandra.locator.TokenMetadata; //导入方法依赖的package包/类
/**
 * Get the "primary ranges" for the specified keyspace and endpoint.
 * "Primary ranges" are the ranges that the node is responsible for storing replica primarily.
 * The node that stores replica primarily is defined as the first node returned
 * by {@link AbstractReplicationStrategy#calculateNaturalEndpoints}.
 *
 * @param keyspace Keyspace name to check primary ranges
 * @param ep endpoint we are interested in.
 * @return primary ranges for the specified endpoint.
 */
public Collection<Range<Token>> getPrimaryRangesForEndpoint(String keyspace, InetAddress ep)
{
    AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy();
    Collection<Range<Token>> primaryRanges = new HashSet<>();
    TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap();
    for (Token token : metadata.sortedTokens())
    {
        List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata);
        if (endpoints.size() > 0 && endpoints.get(0).equals(ep))
            primaryRanges.add(new Range<>(metadata.getPredecessor(token), token));
    }
    return primaryRanges;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:24,代码来源:StorageService.java

示例2: getPrimaryRangeForEndpointWithinDC

import org.apache.cassandra.locator.TokenMetadata; //导入方法依赖的package包/类
/**
 * Get the "primary ranges" within local DC for the specified keyspace and endpoint.
 *
 * @see #getPrimaryRangesForEndpoint(String, java.net.InetAddress)
 * @param keyspace Keyspace name to check primary ranges
 * @param referenceEndpoint endpoint we are interested in.
 * @return primary ranges within local DC for the specified endpoint.
 */
public Collection<Range<Token>> getPrimaryRangeForEndpointWithinDC(String keyspace, InetAddress referenceEndpoint)
{
    TokenMetadata metadata = tokenMetadata.cloneOnlyTokenMap();
    String localDC = DatabaseDescriptor.getEndpointSnitch().getDatacenter(referenceEndpoint);
    Collection<InetAddress> localDcNodes = metadata.getTopology().getDatacenterEndpoints().get(localDC);
    AbstractReplicationStrategy strategy = Keyspace.open(keyspace).getReplicationStrategy();

    Collection<Range<Token>> localDCPrimaryRanges = new HashSet<>();
    for (Token token : metadata.sortedTokens())
    {
        List<InetAddress> endpoints = strategy.calculateNaturalEndpoints(token, metadata);
        for (InetAddress endpoint : endpoints)
        {
            if (localDcNodes.contains(endpoint))
            {
                if (endpoint.equals(referenceEndpoint))
                {
                    localDCPrimaryRanges.add(new Range<>(metadata.getPredecessor(token), token));
                }
                break;
            }
        }
    }

    return localDCPrimaryRanges;
}
 
开发者ID:vcostet,项目名称:cassandra-kmean,代码行数:35,代码来源:StorageService.java

示例3: beforeClass

import org.apache.cassandra.locator.TokenMetadata; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Throwable
{
    TokenMetadata tmd = StorageService.instance.getTokenMetadata();
    tmd.updateNormalToken(token(ONE), InetAddress.getByName("127.0.0.1"));
    tmd.updateNormalToken(token(SIX), InetAddress.getByName("127.0.0.6"));
    RING = tmd.sortedTokens();
}
 
开发者ID:pgaref,项目名称:ACaZoo,代码行数:9,代码来源:TokenMetadataTest.java


注:本文中的org.apache.cassandra.locator.TokenMetadata.sortedTokens方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。