Package leader
Class ExampleClient
java.lang.Object
org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter
leader.ExampleClient
- All Implemented Interfaces:
Closeable
,AutoCloseable
,LeaderSelectorListener
,ConnectionStateListener
An example leader selector client. Note that
LeaderSelectorListenerAdapter
which
has the recommended handling for connection state issues-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
start()
void
takeLeadership
(CuratorFramework client) Called when your instance has been granted leadership.Methods inherited from class org.apache.curator.framework.recipes.leader.LeaderSelectorListenerAdapter
stateChanged
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.apache.curator.framework.state.ConnectionStateListener
doNotProxy
-
Constructor Details
-
ExampleClient
-
-
Method Details
-
start
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
takeLeadership
Description copied from interface:LeaderSelectorListener
Called when your instance has been granted leadership. This method should not return until you wish to release leadership.It is guaranteed that there is no concurrent executions of this method.
It is guaranteed that this method will be interrupted if
ConnectionStateListener.stateChanged(CuratorFramework, ConnectionState)
throwsCancelLeadershipException
. After interrupted, this method should exit(either return or throw) promptly, otherwise it will block following elections.- Specified by:
takeLeadership
in interfaceLeaderSelectorListener
- Parameters:
client
- the client- Throws:
Exception
- any errors
-