org.apache.camel.component.zookeeper.policy
Class ZooKeeperElection

java.lang.Object
  extended by org.apache.camel.component.zookeeper.policy.ZooKeeperElection

public class ZooKeeperElection
extends Object

ZooKeeperElection uses the leader election capabilities of a ZooKeeper cluster to control which nodes are enabled. It is typically used in fail-over scenarios controlling identical instances of an application across a cluster of Camel based servers.

The election is configured with a 'top n' number of servers that should be marked as master, for a simple master/slave scenario this would be 1. Each instance will execute the election algorithm to obtain its position in the hierarchy of servers, if it is within the 'top n' servers then the node is enabled and isMaster() will return 'true'. If not it waits for a change in the leader hierarchy and then reruns this scenario to see if it is now in the top n.

All instances of the election must also be configured with the same path on the ZooKeeper cluster where the election will be carried out. It is good practice for this to indicate the application e.g. /someapplication/someroute/ note that these nodes should exist before using the election.

See for more on how Leader election is archived with ZooKeeper.


Constructor Summary
ZooKeeperElection(org.apache.camel.CamelContext camelContext, String uri, int enabledCount)
           
ZooKeeperElection(org.apache.camel.ProducerTemplate producerTemplate, org.apache.camel.CamelContext camelContext, String uri, int enabledCount)
           
 
Method Summary
 boolean addElectionWatcher(ElectionWatcher e)
           
 boolean isMaster()
           
 boolean removeElectionWatcher(ElectionWatcher o)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZooKeeperElection

public ZooKeeperElection(org.apache.camel.CamelContext camelContext,
                         String uri,
                         int enabledCount)

ZooKeeperElection

public ZooKeeperElection(org.apache.camel.ProducerTemplate producerTemplate,
                         org.apache.camel.CamelContext camelContext,
                         String uri,
                         int enabledCount)
Method Detail

isMaster

public boolean isMaster()

addElectionWatcher

public boolean addElectionWatcher(ElectionWatcher e)

removeElectionWatcher

public boolean removeElectionWatcher(ElectionWatcher o)


Apache Camel