## org.apache.cassandra.locator
Class TokenMetadata

    java.lang.Object
      org.apache.cassandra.locator.TokenMetadata

    public class TokenMetadata

extends java.lang.Object

Constructor Summary
`TokenMetadata()`
`TokenMetadata(com.google.common.collect.BiMap<Token,java.net.InetAddress> tokenToEndpointMap)`

Method Summary
`void` `addBootstrapToken(Token token, java.net.InetAddress endpoint)`
`void` `addLeavingEndpoint(java.net.InetAddress endpoint)`
`void` `addMovingEndpoint(Token token, java.net.InetAddress endpoint)` Add a new moving endpoint
`void` `clearUnsafe()` used by tests
`TokenMetadata` `cloneAfterAllLeft()` Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.
`TokenMetadata` `cloneAfterAllSettled()` Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave and move operations have finished.
`TokenMetadata` `cloneOnlyTokenMap()` Create a copy of TokenMetadata with only tokenToEndpointMap.
`static Token` `firstToken(java.util.ArrayList<Token> ring, Token start)`
`static int` `firstTokenIndex(java.util.ArrayList ring, Token start, boolean insertMin)`
`java.util.Map<Token,java.net.InetAddress>` `getBootstrapTokens()` caller should not modify bootstrapTokens
`java.net.InetAddress` `getEndpoint(Token token)`
`java.util.Set<java.net.InetAddress>` `getLeavingEndpoints()` caller should not modify leavingEndpoints
`java.util.Set<Pair<Token,java.net.InetAddress>>` `getMovingEndpoints()` Endpoints which are migrating to the new tokens
`java.util.Map<Token,java.net.InetAddress>` `getNormalAndBootstrappingTokenToEndpointMap()`
`java.util.Map<Range,java.util.Collection<java.net.InetAddress>>` `getPendingRanges(java.lang.String table)` a mutable map may be returned but caller should not modify it
`java.util.List<Range>` `getPendingRanges(java.lang.String table, java.net.InetAddress endpoint)`
`Token` `getPredecessor(Token token)`
`Range` `getPrimaryRangeFor(Token right)`
`Token` `getSuccessor(Token token)`
`Token` `getToken(java.net.InetAddress endpoint)`
`java.util.Map<Token,java.net.InetAddress>` `getTokenToEndpointMapForReading()`

`java.util.Collection<java.net.InetAddress>`

`getWriteEndpoints(Token token, java.lang.String table, java.util.Collection<java.net.InetAddress> naturalEndpoints)`
write endpoints may be different from read endpoints, because read endpoints only need care about the "natural" nodes for a token, but write endpoints also need to account for nodes that are bootstrapping into the ring, and write data there too so that they stay up to date during the bootstrap process.

`void` `invalidateCaches()`
`boolean` `isLeaving(java.net.InetAddress endpoint)`
`boolean` `isMember(java.net.InetAddress endpoint)`
`boolean` `isMoving(java.net.InetAddress endpoint)`
`int` `pendingRangeChanges(java.net.InetAddress source)`
`java.lang.String` `printPendingRanges()`
`void` `register(AbstractReplicationStrategy subscriber)`
`void` `removeBootstrapToken(Token token)`
`void` `removeEndpoint(java.net.InetAddress endpoint)`
`void` `removeFromMoving(java.net.InetAddress endpoint)` Remove pair of token/address from moving endpoints
`static java.util.Iterator<Token>` `ringIterator(java.util.ArrayList<Token> ring, Token start, boolean includeMin)` iterator over the Tokens in the given ring, starting with the token for the node owning start (which does not have to be a Token in the ring)
`void` `setPendingRanges(java.lang.String table, com.google.common.collect.Multimap<Range,java.net.InetAddress> rangeMap)`
`java.util.ArrayList<Token>` `sortedTokens()`
`java.lang.String` `toString()`
`void` `unregister(AbstractReplicationStrategy subscriber)`
`void` `updateNormalToken(Token token, java.net.InetAddress endpoint)`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### TokenMetadata

    public TokenMetadata()

### TokenMetadata

    public TokenMetadata(com.google.common.collect.BiMap<Token,java.net.InetAddress> tokenToEndpointMap)

Method Detail

### pendingRangeChanges

    public int pendingRangeChanges(java.net.InetAddress source)

  Returns:
    the number of nodes bootstrapping into source's primary range

### updateNormalToken

    public void updateNormalToken(Token token,
                                  java.net.InetAddress endpoint)

### addBootstrapToken

    public void addBootstrapToken(Token token,
                                  java.net.InetAddress endpoint)

### removeBootstrapToken

    public void removeBootstrapToken(Token token)

### addLeavingEndpoint

    public void addLeavingEndpoint(java.net.InetAddress endpoint)

### addMovingEndpoint

    public void addMovingEndpoint(Token token,
                                  java.net.InetAddress endpoint)

  Add a new moving endpoint

  Parameters:
    `token` - token which is node moving to
    `endpoint` - address of the moving node

### removeEndpoint

    public void removeEndpoint(java.net.InetAddress endpoint)

### removeFromMoving

    public void removeFromMoving(java.net.InetAddress endpoint)

  Remove pair of token/address from moving endpoints

  Parameters:
    `endpoint` - address of the moving node

### getToken

    public Token getToken(java.net.InetAddress endpoint)

### isMember

    public boolean isMember(java.net.InetAddress endpoint)

### isLeaving

    public boolean isLeaving(java.net.InetAddress endpoint)

### isMoving

    public boolean isMoving(java.net.InetAddress endpoint)

### cloneOnlyTokenMap

    public TokenMetadata cloneOnlyTokenMap()

  Create a copy of TokenMetadata with only tokenToEndpointMap. That is, pending ranges, bootstrap tokens and leaving endpoints are not included in the copy.

### cloneAfterAllLeft

    public TokenMetadata cloneAfterAllLeft()

  Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave operations have finished.

  Returns:
    new token metadata

### cloneAfterAllSettled

    public TokenMetadata cloneAfterAllSettled()

  Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current leave and move operations have finished.

  Returns:
    new token metadata

### getEndpoint

    public java.net.InetAddress getEndpoint(Token token)

### getPrimaryRangeFor

    public Range getPrimaryRangeFor(Token right)

### sortedTokens

    public java.util.ArrayList<Token> sortedTokens()

### getPendingRanges

    public java.util.Map<Range,java.util.Collection<java.net.InetAddress>> getPendingRanges(java.lang.String table)

  a mutable map may be returned but caller should not modify it

### getPendingRanges

    public java.util.List<Range> getPendingRanges(java.lang.String table,
                                                  java.net.InetAddress endpoint)

### setPendingRanges

    public void setPendingRanges(java.lang.String table,
                                 com.google.common.collect.Multimap<Range,java.net.InetAddress> rangeMap)

### getPredecessor

    public Token getPredecessor(Token token)

### getSuccessor

    public Token getSuccessor(Token token)

### getBootstrapTokens

    public java.util.Map<Token,java.net.InetAddress> getBootstrapTokens()

  caller should not modify bootstrapTokens

### getLeavingEndpoints

    public java.util.Set<java.net.InetAddress> getLeavingEndpoints()

  caller should not modify leavingEndpoints

### getMovingEndpoints

    public java.util.Set<Pair<Token,java.net.InetAddress>> getMovingEndpoints()

  Endpoints which are migrating to the new tokens

  Returns:
    set of addresses of moving endpoints

### firstTokenIndex

    public static int firstTokenIndex(java.util.ArrayList ring,
                                      Token start,
                                      boolean insertMin)

### firstToken

    public static Token firstToken(java.util.ArrayList<Token> ring,
                                   Token start)

### ringIterator

    public static java.util.Iterator<Token> ringIterator(java.util.ArrayList<Token> ring,
                                                         Token start,
                                                         boolean includeMin)

  iterator over the Tokens in the given ring, starting with the token for the node owning start (which does not have to be a Token in the ring)

  Parameters:
    `includeMin` - True if the minimum token should be returned in the ring even if it has no owner.

### clearUnsafe

    public void clearUnsafe()

  used by tests

### toString

    public java.lang.String toString()

  Overrides:
    `toString` in class `java.lang.Object`

### printPendingRanges

    public java.lang.String printPendingRanges()

### invalidateCaches

    public void invalidateCaches()

### register

    public void register(AbstractReplicationStrategy subscriber)

### unregister

    public void unregister(AbstractReplicationStrategy subscriber)

### getWriteEndpoints

    public java.util.Collection<java.net.InetAddress> getWriteEndpoints(Token token,
                                                                        java.lang.String table,
                                                                        java.util.Collection<java.net.InetAddress> naturalEndpoints)

  write endpoints may be different from read endpoints, because read endpoints only need care about the "natural" nodes for a token, but write endpoints also need to account for nodes that are bootstrapping into the ring, and write data there too so that they stay up to date during the bootstrap process. Thus, this method may return more nodes than the Replication Factor. If possible, will return the same collection it was passed, for efficiency. Only ReplicationStrategy should care about this method (higher level users should only ask for Hinted).

### getTokenToEndpointMapForReading

    public java.util.Map<Token,java.net.InetAddress> getTokenToEndpointMapForReading()

  Returns:
    a token to endpoint map to consider for read operations on the cluster.

### getNormalAndBootstrappingTokenToEndpointMap

    public java.util.Map<Token,java.net.InetAddress> getNormalAndBootstrappingTokenToEndpointMap()

  Returns:
    a (stable copy, won't be modified) Token to Endpoint map for all the normal and bootstrapping nodes in the cluster.

Copyright © 2012 The Apache Software Foundation