title: Apache Curator LeaderSelector: How to avoid giving up leadership by not exiting from takeLeadership() method?
body: <p>I'm trying to implement a simple leader election based system where my main business logic of the application runs on the elected leader node. As part of acquiring leadership, the main business logic starts various other services. I'm using Apache Curator LeaderSelector recipe to implement the leader selection process.</p>
  
  <p>In my system, the node which gets selected as the leader keeps the leadership until failure forces another leader to be selected. In other words, once I get the leadership I don't want to relinquish it.</p>
  
  <p>According to Curator LeaderSelection documentation, leadership gets relinquished when the <code>takeLeadership()</code> method returns. I want to avoid it, and I'm right now just block the return by introducing a wait loop.</p>
  
  <p>My question is:</p>
  
  <ol>
  <li>Is this the right way to implement leadership?</li>
  <li><p>Is the wait loop (as shown in the code example below) the right way to block?</p>
  
  <pre><code>public class MainBusinessLogic extends LeaderSelectorListenerAdapter {      
    private static final String ZK_PATH_LEADER_ROOT = "/some-path";
    private final CuratorFramework client;
    private final LeaderSelector leaderSelector;
  
    public MainBusinessLogic() {
      client = CuratorService.getInstance().getCuratorFramework();
      leaderSelector = new LeaderSelector(client, ZK_PATH_LEADER_ROOT, this);
      leaderSelector.autoRequeue();
      leaderSelector.start();
    }
  
    @Override
    public void takeLeadership(CuratorFramework client) throws IOException {
      // Start various other internal services...
      ServiceA serviceA = new ServiceA(...);
      ServiceB serviceB = new ServiceB(...);
      ...
      ...
      serviceA.start();
      serviceB.start();
      ...
      ...
  
      // We are done but need to keep leadership to this instance, else all the business
      // logic and services will start on another node.
      // Is this the right way to prevent relinquishing leadership???
      while (true) {
        synchronized (this) {
          try {
            wait();
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    }
  }
  </code></pre></li>
  </ol>