org.apache.solr.common.cloud
Class SolrZkClient

java.lang.Object
  extended by org.apache.solr.common.cloud.SolrZkClient

public class SolrZkClient
extends Object

All Solr ZooKeeper interactions should go through this class rather than ZooKeeper. This class handles synchronous connects and reconnections.


Field Summary
static AtomicLong numCloses
           
static AtomicLong numOpens
           
 
Constructor Summary
SolrZkClient(String zkServerAddress, int zkClientTimeout)
           
SolrZkClient(String zkServerAddress, int zkClientTimeout, int zkClientConnectTimeout, OnReconnect onReonnect)
           
SolrZkClient(String zkServerAddress, int zkClientTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect)
           
SolrZkClient(String zkServerAddress, int zkClientTimeout, ZkClientConnectionStrategy strat, OnReconnect onReconnect, int clientConnectTimeout)
           
 
Method Summary
 void close()
           
 String create(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)
           
 String create(String path, byte[] data, List<org.apache.zookeeper.data.ACL> acl, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)
           
 void delete(String path, int version, boolean retryOnConnLoss)
           
 Boolean exists(String path, boolean retryOnConnLoss)
           
 org.apache.zookeeper.data.Stat exists(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)
          Return the stat of the node of the given path.
 List<String> getChildren(String path, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)
           
 byte[] getData(String path, org.apache.zookeeper.Watcher watcher, org.apache.zookeeper.data.Stat stat, boolean retryOnConnLoss)
           
 SolrZooKeeper getSolrZooKeeper()
           
 boolean isClosed()
           
 boolean isConnected()
           
 void makePath(String path, boolean retryOnConnLoss)
          Creates the path in ZooKeeper, creating each node as necessary.
 void makePath(String path, boolean failOnExists, boolean retryOnConnLoss)
           
 void makePath(String path, byte[] data, boolean retryOnConnLoss)
          Creates the path in ZooKeeper, creating each node as necessary.
 void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)
          Creates the path in ZooKeeper, creating each node as necessary.
 void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)
          Creates the path in ZooKeeper, creating each node as necessary.
 void makePath(String path, byte[] data, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean failOnExists, boolean retryOnConnLoss)
          Creates the path in ZooKeeper, creating each node as necessary.
 void makePath(String path, org.apache.zookeeper.CreateMode createMode, boolean retryOnConnLoss)
           
 void makePath(String zkPath, org.apache.zookeeper.CreateMode createMode, org.apache.zookeeper.Watcher watcher, boolean retryOnConnLoss)
           
 void makePath(String path, File file, boolean retryOnConnLoss)
           
 void makePath(String path, File file, boolean failOnExists, boolean retryOnConnLoss)
           
static String prettyPrint(String input, int indent)
           
 void printLayout(String path, int indent, StringBuilder string)
          Fills string with printout of current ZooKeeper layout.
 void printLayoutToStdOut()
          Prints current ZooKeeper layout to stdout.
 void setData(String path, byte[] data, boolean retryOnConnLoss)
          Write data to ZooKeeper.
 org.apache.zookeeper.data.Stat setData(String path, byte[] data, int version, boolean retryOnConnLoss)
           
 void setData(String path, File file, boolean retryOnConnLoss)
          Write file to ZooKeeper - default system encoding used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

numOpens

public static final AtomicLong numOpens

numCloses

public static final AtomicLong numCloses
Constructor Detail

SolrZkClient

public SolrZkClient(String zkServerAddress,
                    int zkClientTimeout)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Parameters:
zkServerAddress -
zkClientTimeout -
Throws:
InterruptedException
TimeoutException
IOException

SolrZkClient

public SolrZkClient(String zkServerAddress,
                    int zkClientTimeout,
                    int zkClientConnectTimeout,
                    OnReconnect onReonnect)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Throws:
InterruptedException
TimeoutException
IOException

SolrZkClient

public SolrZkClient(String zkServerAddress,
                    int zkClientTimeout,
                    ZkClientConnectionStrategy strat,
                    OnReconnect onReconnect)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Parameters:
zkServerAddress -
zkClientTimeout -
strat -
onReconnect -
Throws:
InterruptedException
TimeoutException
IOException

SolrZkClient

public SolrZkClient(String zkServerAddress,
                    int zkClientTimeout,
                    ZkClientConnectionStrategy strat,
                    OnReconnect onReconnect,
                    int clientConnectTimeout)
             throws InterruptedException,
                    TimeoutException,
                    IOException
Parameters:
zkServerAddress -
zkClientTimeout -
strat -
onReconnect -
clientConnectTimeout -
Throws:
InterruptedException
TimeoutException
IOException
Method Detail

isConnected

public boolean isConnected()
Returns:
true if client is connected

delete

public void delete(String path,
                   int version,
                   boolean retryOnConnLoss)
            throws InterruptedException,
                   org.apache.zookeeper.KeeperException
Parameters:
path -
version -
retryOnConnLoss -
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

exists

public org.apache.zookeeper.data.Stat exists(String path,
                                             org.apache.zookeeper.Watcher watcher,
                                             boolean retryOnConnLoss)
                                      throws org.apache.zookeeper.KeeperException,
                                             InterruptedException
Return the stat of the node of the given path. Return null if no such a node exists.

If the watch is non-null and the call is successful (no exception is thrown), a watch will be left on the node with the given path. The watch will be triggered by a successful operation that creates/delete the node or sets the data on the node.

Parameters:
path - the node path
watcher - explicit watcher
retryOnConnLoss -
Returns:
the stat of the node of the given path; return null if no such a node exists.
Throws:
org.apache.zookeeper.KeeperException - If the server signals an error
InterruptedException - If the server transaction is interrupted.
IllegalArgumentException - if an invalid path is specified

exists

public Boolean exists(String path,
                      boolean retryOnConnLoss)
               throws org.apache.zookeeper.KeeperException,
                      InterruptedException
Parameters:
path -
retryOnConnLoss -
Returns:
true if path exists
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

create

public String create(String path,
                     byte[] data,
                     List<org.apache.zookeeper.data.ACL> acl,
                     org.apache.zookeeper.CreateMode createMode,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Parameters:
path -
data -
acl -
createMode -
retryOnConnLoss -
Returns:
path of created node
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getChildren

public List<String> getChildren(String path,
                                org.apache.zookeeper.Watcher watcher,
                                boolean retryOnConnLoss)
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException
Parameters:
path -
watcher -
retryOnConnLoss -
Returns:
children of the node at the path
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

getData

public byte[] getData(String path,
                      org.apache.zookeeper.Watcher watcher,
                      org.apache.zookeeper.data.Stat stat,
                      boolean retryOnConnLoss)
               throws org.apache.zookeeper.KeeperException,
                      InterruptedException
Parameters:
path -
watcher -
stat -
retryOnConnLoss -
Returns:
node's data
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

setData

public org.apache.zookeeper.data.Stat setData(String path,
                                              byte[] data,
                                              int version,
                                              boolean retryOnConnLoss)
                                       throws org.apache.zookeeper.KeeperException,
                                              InterruptedException
Parameters:
path -
data -
version -
retryOnConnLoss -
Returns:
node's state
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

create

public String create(String path,
                     byte[] data,
                     org.apache.zookeeper.CreateMode createMode,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Parameters:
path -
data -
createMode -
retryOnConnLoss -
Returns:
path of created node
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Creates the path in ZooKeeper, creating each node as necessary. e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, each will be created.

Parameters:
path -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     boolean failOnExists,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     File file,
                     boolean failOnExists,
                     boolean retryOnConnLoss)
              throws IOException,
                     org.apache.zookeeper.KeeperException,
                     InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     File file,
                     boolean retryOnConnLoss)
              throws IOException,
                     org.apache.zookeeper.KeeperException,
                     InterruptedException
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     org.apache.zookeeper.CreateMode createMode,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     byte[] data,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Creates the path in ZooKeeper, creating each node as necessary.

Parameters:
path -
data - to set on the last zkNode
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     byte[] data,
                     org.apache.zookeeper.CreateMode createMode,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Creates the path in ZooKeeper, creating each node as necessary. e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, each will be created.

Parameters:
path -
data - to set on the last zkNode
createMode -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     byte[] data,
                     org.apache.zookeeper.CreateMode createMode,
                     org.apache.zookeeper.Watcher watcher,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Creates the path in ZooKeeper, creating each node as necessary. e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, each will be created.

Parameters:
path -
data - to set on the last zkNode
createMode -
watcher -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String path,
                     byte[] data,
                     org.apache.zookeeper.CreateMode createMode,
                     org.apache.zookeeper.Watcher watcher,
                     boolean failOnExists,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Creates the path in ZooKeeper, creating each node as necessary. e.g. If path=/solr/group/node and none of the nodes, solr, group, node exist, each will be created. Note: retryOnConnLoss is only respected for the final node - nodes before that are always retried on connection loss.

Parameters:
path -
data -
createMode -
watcher -
failOnExists -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

makePath

public void makePath(String zkPath,
                     org.apache.zookeeper.CreateMode createMode,
                     org.apache.zookeeper.Watcher watcher,
                     boolean retryOnConnLoss)
              throws org.apache.zookeeper.KeeperException,
                     InterruptedException
Parameters:
zkPath -
createMode -
watcher -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

setData

public void setData(String path,
                    byte[] data,
                    boolean retryOnConnLoss)
             throws org.apache.zookeeper.KeeperException,
                    InterruptedException
Write data to ZooKeeper.

Parameters:
path -
data -
retryOnConnLoss -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

setData

public void setData(String path,
                    File file,
                    boolean retryOnConnLoss)
             throws IOException,
                    org.apache.zookeeper.KeeperException,
                    InterruptedException
Write file to ZooKeeper - default system encoding used.

Parameters:
path - path to upload file to e.g. /solr/conf/solrconfig.xml
file - path to file to be uploaded
retryOnConnLoss -
Throws:
IOException
org.apache.zookeeper.KeeperException
InterruptedException

printLayout

public void printLayout(String path,
                        int indent,
                        StringBuilder string)
                 throws org.apache.zookeeper.KeeperException,
                        InterruptedException
Fills string with printout of current ZooKeeper layout.

Parameters:
path -
indent -
Throws:
org.apache.zookeeper.KeeperException
InterruptedException

printLayoutToStdOut

public void printLayoutToStdOut()
                         throws org.apache.zookeeper.KeeperException,
                                InterruptedException
Prints current ZooKeeper layout to stdout.

Throws:
org.apache.zookeeper.KeeperException
InterruptedException

prettyPrint

public static String prettyPrint(String input,
                                 int indent)

close

public void close()
           throws InterruptedException
Throws:
InterruptedException

isClosed

public boolean isClosed()

getSolrZooKeeper

public SolrZooKeeper getSolrZooKeeper()


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