## org.apache.solr.common.cloud
Class ClusterState

    java.lang.Object
      org.apache.solr.common.cloud.ClusterState

All Implemented Interfaces:
  JSONWriter.Writable

    public class ClusterState

extends Object
implements JSONWriter.Writable

Immutable state of the cloud. Normally you can get the state by using `ZkStateReader.getClusterState()`.

WARNING: This API is experimental and might change in incompatible ways in the next release.

Constructor Summary
`ClusterState(Integer zkClusterStateVersion, Set<String> liveNodes, Map<String,DocCollection> collectionStates)` Use this constr when ClusterState is meant for consumption.
`ClusterState(Set<String> liveNodes, Map<String,DocCollection> collectionStates)` Use this constr when ClusterState is meant for publication.

Method Summary
`boolean` `equals(Object obj)`
`Map<String,Slice>` `getAllSlicesMap(String collection)`
`DocCollection` `getCollection(String collection)` Get the named DocCollection object, or throw an exception if it doesn't exist.
`Set<String>` `getCollections()` Get collection names.
`Map<String,DocCollection>` `getCollectionStates()`
`Replica` `getLeader(String collection, String sliceName)` Get the lead replica for specific collection, or null if one currently doesn't exist.
`Set<String>` `getLiveNodes()` Get names of the currently live nodes.
`Replica` `getReplica(String collection, String coreNodeName)` Gets the replica by the core name (assuming the slice is unknown) or null if replica is not found.
`String` `getShardId(String coreNodeName)` Get the slice/shardId for a core.
`Slice` `getSlice(String collection, String sliceName)` Get the named Slice for collection, or null if not found.
`Collection<Slice>` `getSlices(String collection)`
`Map<String,Slice>` `getSlicesMap(String collection)`
`Integer` `getZkClusterStateVersion()` The version of clusterstate.json in ZooKeeper.
`int` `hashCode()`
`boolean` `liveNodesContain(String name)` Check if node is alive.
`static Aliases` `load(byte[] bytes)`
`static ClusterState` `load(Integer version, byte[] bytes, Set<String> liveNodes)` Create ClusterState from json string that is typically stored in zookeeper.
`static ClusterState` `load(SolrZkClient zkClient, Set<String> liveNodes)` Create ClusterState by reading the current state from zookeeper.
`String` `toString()`
`void` `write(JSONWriter jsonWriter)`

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

Constructor Detail

### ClusterState

    public ClusterState(Set<String> liveNodes,
                        Map<String,DocCollection> collectionStates)

  Use this constr when ClusterState is meant for publication. hashCode and equals will only depend on liveNodes and not clusterStateVersion.

### ClusterState

    public ClusterState(Integer zkClusterStateVersion,
                        Set<String> liveNodes,
                        Map<String,DocCollection> collectionStates)

  Use this constr when ClusterState is meant for consumption.

Method Detail

### getLeader

    public Replica getLeader(String collection,
                             String sliceName)

  Get the lead replica for specific collection, or null if one currently doesn't exist.

### getReplica

    public Replica getReplica(String collection,
                              String coreNodeName)

  Gets the replica by the core name (assuming the slice is unknown) or null if replica is not found. If the slice is known, do not use this method. coreNodeName is the same as replicaName

### getSlice

    public Slice getSlice(String collection,
                          String sliceName)

  Get the named Slice for collection, or null if not found.

### getSlicesMap

    public Map<String,Slice> getSlicesMap(String collection)

### getAllSlicesMap

    public Map<String,Slice> getAllSlicesMap(String collection)

### getSlices

    public Collection<Slice> getSlices(String collection)

### getCollection

    public DocCollection getCollection(String collection)

  Get the named DocCollection object, or throw an exception if it doesn't exist.

### getCollections

    public Set<String> getCollections()

  Get collection names.

### getCollectionStates

    public Map<String,DocCollection> getCollectionStates()

  Returns:
    Map<collectionName, Map<sliceName,Slice>>

### getLiveNodes

    public Set<String> getLiveNodes()

  Get names of the currently live nodes.

### getShardId

    public String getShardId(String coreNodeName)

  Get the slice/shardId for a core.

  Parameters:
    `coreNodeName` - in the form of nodeName_coreName (the name of the replica)

### liveNodesContain

    public boolean liveNodesContain(String name)

  Check if node is alive.

### toString

    public String toString()

  Overrides:
    `toString` in class `Object`

### load

    public static ClusterState load(SolrZkClient zkClient,
                                    Set<String> liveNodes)
                             throws org.apache.zookeeper.KeeperException,
                                    InterruptedException

  Create ClusterState by reading the current state from zookeeper.

  Throws:
    `org.apache.zookeeper.KeeperException`
    `InterruptedException`

### load

    public static ClusterState load(Integer version,
                                    byte[] bytes,
                                    Set<String> liveNodes)

  Create ClusterState from json string that is typically stored in zookeeper. Use `load(SolrZkClient, Set)` instead, unless you want to do something more when getting the data - such as get the stat, set watch, etc.

  Parameters:
    `version` - zk version of the clusterstate.json file (bytes)
    `bytes` - clusterstate.json as a byte array
    `liveNodes` - list of live nodes
  Returns:
    the ClusterState

### load

    public static Aliases load(byte[] bytes)

### write

    public void write(JSONWriter jsonWriter)

  Specified by:
    `write` in interface `JSONWriter.Writable`

### getZkClusterStateVersion

    public Integer getZkClusterStateVersion()

  The version of clusterstate.json in ZooKeeper.

  Returns:
    null if ClusterState was created for publication, not consumption

### hashCode

    public int hashCode()

  Overrides:
    `hashCode` in class `Object`

### equals

    public boolean equals(Object obj)

  Overrides:
    `equals` in class `Object`

Copyright © 2000-2013 Apache Software Foundation. All Rights Reserved.