Skip to content

Temporary Framework

Randgalt edited this page Dec 21, 2012 · 4 revisions

Temporary CuratorFramework instances are meant for single requests to ZooKeeper ensembles over a failure prone network such as a WAN. The APIs available from CuratorTempFramework are limited. Further, the connection will be closed after a period of inactivity.

This is based on an idea mentioned in a post by Camille Fournier: http://whilefalse.blogspot.com/2012/12/building-global-highly-available.html

Creating a CuratorTempFramework

CuratorTempFramework instances are created via the CuratorFrameworkFactory just like normal CuratorFramework instances. However, instead of calling the build() method, call buildTemp(). buildTemp() creates a CuratorTempFramework instance that closes itself after 3 minutes of inactivity. There is an alternate version of buildTemp() that allows you to specify the inactivity period.

Limited API

CuratorTempFramework instances provide the following methods:

  /**
   * Stop the client
   */
  public void     close();

  /**
   * Start a transaction builder
   *
   * @return builder object
   * @throws Exception errors
   */
  public CuratorTransaction inTransaction() throws Exception;

  /**
   * Start a get data builder
   *
   * @return builder object
   * @throws Exception errors
   */
  public TempGetDataBuilder getData() throws Exception;
Clone this wiki locally