本文整理汇总了Java中org.apache.cassandra.thrift.TokenRange类的典型用法代码示例。如果您正苦于以下问题:Java TokenRange类的具体用法?Java TokenRange怎么用?Java TokenRange使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TokenRange类属于org.apache.cassandra.thrift包,在下文中一共展示了TokenRange类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: describeRingJMX
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The same as {@code describeRing(String)} but converts TokenRange to the String for JMX compatibility
*
* @param keyspace The keyspace to fetch information about
*
* @return a List of TokenRange(s) converted to String for the given keyspace
*/
public List<String> describeRingJMX(String keyspace) throws IOException
{
List<TokenRange> tokenRanges;
try
{
tokenRanges = describeRing(keyspace);
}
catch (InvalidRequestException e)
{
throw new IOException(e.getMessage());
}
List<String> result = new ArrayList<>(tokenRanges.size());
for (TokenRange tokenRange : tokenRanges)
result.add(tokenRange.toString());
return result;
}
示例2: describeRingJMX
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The same as {@code describeRing(String)} but converts TokenRange to the String for JMX compatibility
*
* @param keyspace The keyspace to fetch information about
*
* @return a List of TokenRange(s) converted to String for the given keyspace
*/
public List<String> describeRingJMX(String keyspace) throws IOException
{
List<TokenRange> tokenRanges;
try
{
tokenRanges = describeRing(keyspace);
}
catch (InvalidRequestException e)
{
throw new IOException(e.getMessage());
}
List<String> result = new ArrayList<String>(tokenRanges.size());
for (TokenRange tokenRange : tokenRanges)
result.add(tokenRange.toString());
return result;
}
示例3: describeRingJMX
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The same as {@code describeRing(String)} but converts TokenRange to the String for JMX compatibility
*
* @param keyspace The keyspace to fetch information about
*
* @return a List of TokenRange(s) converted to String for the given keyspace
*/
public List<String> describeRingJMX(String keyspace) throws IOException
{
List<TokenRange> tokenRanges = null;
try
{
tokenRanges = describeRing(keyspace);
}
catch (InvalidRequestException e)
{
throw new IOException(e.getMessage());
}
List<String> result = new ArrayList<String>(tokenRanges.size());
for (TokenRange tokenRange : tokenRanges)
result.add(tokenRange.toString());
return result;
}
示例4: describeRing
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The TokenRange for a given keyspace.
*
* @param keyspace The keyspace to fetch information about
*
* @return a List of TokenRange(s) for the given keyspace
*
* @throws InvalidRequestException if there is no ring information available about keyspace
*/
public List<TokenRange> describeRing(String keyspace) throws InvalidRequestException
{
if (keyspace == null || Keyspace.open(keyspace).getReplicationStrategy() instanceof LocalStrategy)
throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);
List<TokenRange> ranges = new ArrayList<TokenRange>();
Token.TokenFactory tf = getPartitioner().getTokenFactory();
for (Map.Entry<Range<Token>, List<InetAddress>> entry : getRangeToAddressMap(keyspace).entrySet())
{
Range range = entry.getKey();
List<InetAddress> addresses = entry.getValue();
List<String> endpoints = new ArrayList<String>(addresses.size());
List<String> rpc_endpoints = new ArrayList<String>(addresses.size());
List<EndpointDetails> epDetails = new ArrayList<EndpointDetails>(addresses.size());
for (InetAddress endpoint : addresses)
{
EndpointDetails details = new EndpointDetails();
details.host = endpoint.getHostAddress();
details.datacenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint);
details.rack = DatabaseDescriptor.getEndpointSnitch().getRack(endpoint);
endpoints.add(details.host);
rpc_endpoints.add(getRpcaddress(endpoint));
epDetails.add(details);
}
TokenRange tr = new TokenRange(tf.toString(range.left.getToken()), tf.toString(range.right.getToken()), endpoints)
.setEndpoint_details(epDetails)
.setRpc_endpoints(rpc_endpoints);
ranges.add(tr);
}
return ranges;
}
示例5: getRangeMap
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
public List<TokenRange> getRangeMap(String keyspace)
{
Client client = connectionFactory.create();
try {
return client.describe_ring(keyspace);
}
catch (TException e) {
throw new RuntimeException(e);
}
finally {
closeQuietly(client);
}
}
示例6: getSplits
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
public List<TokenSplit> getSplits(String keyspace, String columnFamily)
throws IOException
{
List<TokenRange> masterRangeNodes = cassandraThriftClient.getRangeMap(keyspace);
// canonical ranges, split into pieces, fetching the splits in parallel
List<TokenSplit> splits = new ArrayList<>();
List<Future<List<TokenSplit>>> splitFutures = new ArrayList<>();
for (TokenRange range : masterRangeNodes) {
// for each range, pick a live owner and ask it to compute bite-sized splits
splitFutures.add(executor.submit(new SplitCallable<>(range, keyspace, columnFamily, splitSize, cassandraThriftClient, partitioner)));
}
// wait until we have all the results back
for (Future<List<TokenSplit>> futureInputSplits : splitFutures) {
try {
splits.addAll(futureInputSplits.get());
}
catch (Exception e) {
throw new IOException("Could not get input splits", e);
}
}
checkState(!splits.isEmpty(), "No splits created");
//noinspection SharedThreadLocalRandom
Collections.shuffle(splits, ThreadLocalRandom.current());
return splits;
}
示例7: SplitCallable
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
public SplitCallable(TokenRange range, String keyspace, String columnFamily, int splitSize, CassandraThriftClient client, IPartitioner<T> partitioner)
{
checkArgument(range.rpc_endpoints.size() == range.endpoints.size(), "rpc_endpoints size must match endpoints size");
this.range = range;
this.keyspace = keyspace;
this.columnFamily = columnFamily;
this.splitSize = splitSize;
this.client = client;
this.partitioner = partitioner;
}
示例8: describeRing
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The TokenRange for a given keyspace.
*
* @param keyspace The keyspace to fetch information about
*
* @return a List of TokenRange(s) for the given keyspace
*
* @throws InvalidRequestException if there is no ring information available about keyspace
*/
public List<TokenRange> describeRing(String keyspace) throws InvalidRequestException
{
if (keyspace == null || Table.open(keyspace).getReplicationStrategy() instanceof LocalStrategy)
throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);
List<TokenRange> ranges = new ArrayList<TokenRange>();
Token.TokenFactory tf = getPartitioner().getTokenFactory();
for (Map.Entry<Range<Token>, List<InetAddress>> entry : getRangeToAddressMap(keyspace).entrySet())
{
Range range = entry.getKey();
List<InetAddress> addresses = entry.getValue();
List<String> endpoints = new ArrayList<String>(addresses.size());
List<String> rpc_endpoints = new ArrayList<String>(addresses.size());
List<EndpointDetails> epDetails = new ArrayList<EndpointDetails>(addresses.size());
for (InetAddress endpoint : addresses)
{
EndpointDetails details = new EndpointDetails();
details.host = endpoint.getHostAddress();
details.datacenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint);
details.rack = DatabaseDescriptor.getEndpointSnitch().getRack(endpoint);
endpoints.add(details.host);
rpc_endpoints.add(getRpcaddress(endpoint));
epDetails.add(details);
}
TokenRange tr = new TokenRange(tf.toString(range.left.getToken()), tf.toString(range.right.getToken()), endpoints)
.setEndpoint_details(epDetails)
.setRpc_endpoints(rpc_endpoints);
ranges.add(tr);
}
return ranges;
}
示例9: getAllServers
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
private List<String> getAllServers(List<TokenRange> input) {
HashMap<String, Integer> map = new HashMap<String, Integer>(input.size());
for (TokenRange thisRange : input) {
List<String> servers = thisRange.rpc_endpoints;
for (String newServer : servers) {
map.put(newServer, new Integer(1));
}
}
return new ArrayList<String>(map.keySet());
}
示例10: getAllServers
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
private List<String> getAllServers(List<TokenRange> input) {
HashMap<String, Integer> map = new HashMap<String, Integer>(input.size());
for (TokenRange thisRange : input) {
List<String> servers = thisRange.rpc_endpoints;
for (String newServer : servers) {
map.put(newServer, new Integer(1));
}
}
return new ArrayList<String>(map.keySet());
}
示例11: testDescribeRing
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
public void testDescribeRing ()
throws Exception
{
TSocket sock = new TSocket("caleb-htpc", 9160, 5000);
TTransport tr = new TFramedTransport(sock);
tr.open();
Cassandra.Client client = new Cassandra.Client(new TBinaryProtocol(tr));
for ( TokenRange range : client.describe_ring("Outerspacecat") ) {
for ( EndpointDetails endpoint : range.getEndpoint_details() ) {
System.out.println(endpoint.getHost());
}
}
}
示例12: SplitCallable
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
public SplitCallable(TokenRange tr, Configuration conf)
{
this.range = tr;
this.conf = conf;
}
示例13: describeLocalRing
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
/**
* The same as {@code describeRing(String)} but considers only the part of the ring formed by nodes in the local DC.
*/
public List<TokenRange> describeLocalRing(String keyspace) throws InvalidRequestException
{
return describeRing(keyspace, true);
}
示例14: describeRing
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
private List<TokenRange> describeRing(String keyspace, boolean includeOnlyLocalDC) throws InvalidRequestException
{
if (!Schema.instance.getKeyspaces().contains(keyspace))
throw new InvalidRequestException("No such keyspace: " + keyspace);
if (keyspace == null || Keyspace.open(keyspace).getReplicationStrategy() instanceof LocalStrategy)
throw new InvalidRequestException("There is no ring for the keyspace: " + keyspace);
List<TokenRange> ranges = new ArrayList<>();
Token.TokenFactory tf = getPartitioner().getTokenFactory();
Map<Range<Token>, List<InetAddress>> rangeToAddressMap =
includeOnlyLocalDC
? getRangeToAddressMapInLocalDC(keyspace)
: getRangeToAddressMap(keyspace);
for (Map.Entry<Range<Token>, List<InetAddress>> entry : rangeToAddressMap.entrySet())
{
Range range = entry.getKey();
List<InetAddress> addresses = entry.getValue();
List<String> endpoints = new ArrayList<>(addresses.size());
List<String> rpc_endpoints = new ArrayList<>(addresses.size());
List<EndpointDetails> epDetails = new ArrayList<>(addresses.size());
for (InetAddress endpoint : addresses)
{
EndpointDetails details = new EndpointDetails();
details.host = endpoint.getHostAddress();
details.datacenter = DatabaseDescriptor.getEndpointSnitch().getDatacenter(endpoint);
details.rack = DatabaseDescriptor.getEndpointSnitch().getRack(endpoint);
endpoints.add(details.host);
rpc_endpoints.add(getRpcaddress(endpoint));
epDetails.add(details);
}
TokenRange tr = new TokenRange(tf.toString(range.left.getToken()), tf.toString(range.right.getToken()), endpoints)
.setEndpoint_details(epDetails)
.setRpc_endpoints(rpc_endpoints);
ranges.add(tr);
}
return ranges;
}
示例15: describe_ring
import org.apache.cassandra.thrift.TokenRange; //导入依赖的package包/类
List<TokenRange> describe_ring(String keyspace) throws InvalidRequestException, TException
{
return client.describe_ring(keyspace);
}