Class ZooKeeperGroup<T extends NodeState>
java.lang.Object
org.apache.camel.component.zookeepermaster.group.internal.ZooKeeperGroup<T>
- All Implemented Interfaces:
Closeable
,AutoCloseable
,Group<T>
- Direct Known Subclasses:
ZooKeeperMultiGroup
A utility that attempts to keep all data from all children of a ZK path locally cached. This class will watch the ZK path, respond to update/create/delete events, pull down the data, etc. You can register a listener that will get notified when changes occur.
IMPORTANT - it's not possible to stay transactionally in sync. Users of this class must be prepared for false-positives and false-negatives. Additionally, always use the version number when updating data to avoid overwriting another process' change.
-
Constructor Summary
ConstructorDescriptionZooKeeperGroup
(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz) ZooKeeperGroup
(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz, ExecutorService executorService) ZooKeeperGroup
(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz, ThreadFactory threadFactory) -
Method Summary
Modifier and TypeMethodDescriptionvoid
add
(GroupListener<T> listener) Registers a listener which will be called when the cluster membership changes or the group is connected or disconnected.void
clear()
Clears the current data without beginning a new query and without generating any events for listeners.void
Clear out current data and begin a new query on the pathvoid
clearAndRefresh
(boolean force, boolean sync) Clear out current data and begin a new query on the pathvoid
close()
Close/end the cacheprotected void
Filter stale nodes and return only active children from the current data.Return the current data.getCurrentData
(String fullPath) Return the current data for the given path.getId()
Gets the last state.org.apache.curator.framework.listen.StandardListenerManager
<GroupListener<T>> Return the cache listenableprotected void
Default behavior is just to log the exceptionboolean
Are we connected with the cluster?boolean
isMaster()
Check if we are the master.boolean
Returns an indication that the sequential, ephemeral node may be registered more than once for this groupmaster()
Retrieve the master node.members()
Get the list of members connected to this group.members
(com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.curator.framework.CuratorFramework curator, String path, Class<T> clazz) protected void
void
remove
(GroupListener<T> listener) Removes a previously added listener.slaves()
Retrieve the list of slaves.void
start()
Start the cache.void
Update the state of this group member.
-
Constructor Details
-
ZooKeeperGroup
public ZooKeeperGroup(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz) - Parameters:
client
- the clientpath
- path to watch
-
ZooKeeperGroup
public ZooKeeperGroup(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz, ThreadFactory threadFactory) - Parameters:
client
- the clientpath
- path to watchthreadFactory
- factory to use when creating internal threads
-
ZooKeeperGroup
public ZooKeeperGroup(org.apache.curator.framework.CuratorFramework client, String path, Class<T> clazz, ExecutorService executorService) - Parameters:
client
- the clientpath
- path to watchexecutorService
- ExecutorService to use for the ZooKeeperGroup's background thread
-
-
Method Details
-
start
public void start()Start the cache. The cache is not started automatically. You must call this method. -
close
Close/end the cache- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceGroup<T extends NodeState>
- Throws:
IOException
- errors
-
isConnected
public boolean isConnected()Description copied from interface:Group
Are we connected with the cluster?- Specified by:
isConnected
in interfaceGroup<T extends NodeState>
-
add
Description copied from interface:Group
Registers a listener which will be called when the cluster membership changes or the group is connected or disconnected. -
remove
Description copied from interface:Group
Removes a previously added listener. -
update
Description copied from interface:Group
Update the state of this group member. If the state is null, the member will leave the group. This method can be called even if the group is not started, in which case the state will be stored and updated when the group becomes started. -
doUpdate
- Throws:
Exception
-
members
Description copied from interface:Group
Get the list of members connected to this group. -
isMaster
public boolean isMaster()Description copied from interface:Group
Check if we are the master. -
master
Description copied from interface:Group
Retrieve the master node. -
slaves
Description copied from interface:Group
Retrieve the list of slaves. -
getActiveChildren
Filter stale nodes and return only active children from the current data.- Returns:
- list of active children and data
-
getLastState
Description copied from interface:Group
Gets the last state. This can be used by clients to access that last state, such as when the clients is being added as alistener
but wants to retrieve the last state to be up to date when the client is added.- Specified by:
getLastState
in interfaceGroup<T extends NodeState>
- Returns:
- the state, or null if no last state yet.
-
getSequenceComparator
-
getListenable
public org.apache.curator.framework.listen.StandardListenerManager<GroupListener<T>> getListenable()Return the cache listenable- Returns:
- listenable
-
getCurrentData
Return the current data. There are no guarantees of accuracy. This is merely the most recent view of the data. The data is returned in sorted order.- Returns:
- list of children and data
-
getCurrentData
Return the current data for the given path. There are no guarantees of accuracy. This is merely the most recent view of the data. If there is no child with that path,null
is returned.- Parameters:
fullPath
- full path to the node to check- Returns:
- data or null
-
clearAndRefresh
Clear out current data and begin a new query on the path- Throws:
Exception
- errors
-
clearAndRefresh
Clear out current data and begin a new query on the path- Parameters:
force
- - whether to force clear and refresh to trigger updatessync
- - whether to run this synchronously (block current thread) or asynchronously- Throws:
Exception
- errors
-
clear
public void clear()Clears the current data without beginning a new query and without generating any events for listeners. -
handleException
Default behavior is just to log the exception- Parameters:
e
- the exception
-
remove
-
members
public static <T> Map<String,T> members(com.fasterxml.jackson.databind.ObjectMapper mapper, org.apache.curator.framework.CuratorFramework curator, String path, Class<T> clazz) throws Exception - Throws:
Exception
-
getId
-
isUnstable
public boolean isUnstable()Returns an indication that the sequential, ephemeral node may be registered more than once for this group
-