public class ZkConfigService extends Object implements ConfigService, org.springframework.context.ApplicationListener<org.springframework.context.event.ApplicationContextEvent>, org.springframework.context.ApplicationContextAware
SEPARATOR| Constructor and Description |
|---|
ZkConfigService(org.I0Itec.zkclient.ZkClient zk,
String zkPath)
Construct the configuration loader.
|
| Modifier and Type | Method and Description |
|---|---|
void |
delete(String... path)
Recursive delete of a path without any option to recover.
|
boolean |
exists(String... path)
Check if a given path exists
|
Set<String> |
getChildren(ConfigChildListener listener,
String... path)
Retrieve the children of a given path
|
ClassLoader |
getClassLoader(ConfigClassesListener listener,
ClassLoader parent,
String... path)
Retrieve a
ClassLoader rooted at the given location |
ClassLoader |
getJarLoader(ConfigClassesListener listener,
ClassLoader parent,
String... path)
Retrieve a
URLClassLoader rooted at the given location. |
Properties |
getProperties(ConfigDataListener listener,
String... path)
Retrieve the properties from a given path
|
String |
getString(ConfigDataListener listener,
String... path)
Retrieve string data from a given path
|
void |
onApplicationEvent(org.springframework.context.event.ApplicationContextEvent event)
Handles start and stop by checking configuration and cleaning caches respectively.
|
void |
setApplicationContext(org.springframework.context.ApplicationContext ctx)
Record the context that started this instance.
|
String |
setData(ConfigDataListener listener,
boolean ephemeral,
boolean sequential,
byte[] bytes,
String... path)
Set binary data
|
String |
setProperties(ConfigDataListener listener,
boolean ephemeral,
boolean sequential,
Properties properties,
String... path)
Set properties against a path
|
String |
setString(ConfigDataListener listener,
boolean ephemeral,
boolean sequential,
String value,
String... path)
Retrieve string data from a given path
|
void |
shutdown()
Drop any stored configuration and discard any watchers
|
boolean |
updateData(byte[] bytes,
String... path)
Update data at a given path
|
boolean |
updateProperties(Properties properties,
String... path)
Update properties at a given path
|
boolean |
updateString(String value,
String... path)
Update a specific string value
|
public ZkConfigService(org.I0Itec.zkclient.ZkClient zk,
String zkPath)
zk - the ZooKeeper clientzkPath - the root path to use in ZKpublic void setApplicationContext(org.springframework.context.ApplicationContext ctx)
throws org.springframework.beans.BeansException
setApplicationContext in interface org.springframework.context.ApplicationContextAwareorg.springframework.beans.BeansExceptionpublic void onApplicationEvent(org.springframework.context.event.ApplicationContextEvent event)
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ApplicationContextEvent>public void shutdown()
public boolean exists(String... path)
exists in interface ConfigServicepath - the path (over and above any root path) to checkpublic void delete(String... path)
delete in interface ConfigServicepath - the path (over and above any root path)public String getString(ConfigDataListener listener, String... path)
getString in interface ConfigServicelistener - a listener to call if the data changes (null allowed)path - the path to the datapublic String setData(ConfigDataListener listener, boolean ephemeral, boolean sequential, byte[] bytes, String... path)
ConfigServicesetData in interface ConfigServicelistener - a listener to call if the properties change (null allowed)ephemeral - true if the path should be removed when the server stopssequential - true if the last path element must have an auto-incrementing
value attached i.e. if the final path element is always newbytes - the data to setpath - the path to the propertiespublic boolean updateData(byte[] bytes,
String... path)
ConfigServiceupdateData in interface ConfigServicebytes - the properties to setpath - the path to the propertiespublic String setString(ConfigDataListener listener, boolean ephemeral, boolean sequential, String value, String... path)
ConfigServicesetString in interface ConfigServicelistener - a listener to call if the data changes (null allowed)ephemeral - true if the path should be removed when the server stopssequential - true if the last path element must have an auto-incrementing
value attached i.e. if the final path element is always newvalue - the value to setpath - the path to the propertiespublic boolean updateString(String value, String... path)
ConfigServiceupdateString in interface ConfigServicevalue - the value to setpath - the path to the propertiespublic Properties getProperties(ConfigDataListener listener, String... path)
getProperties in interface ConfigServicelistener - a listener to call if the properties change (null allowed)path - the path to the propertiespublic String setProperties(ConfigDataListener listener, boolean ephemeral, boolean sequential, Properties properties, String... path)
ConfigServicesetProperties in interface ConfigServicelistener - a listener to call if the properties change (null allowed)ephemeral - true if the path should be removed when the server stopssequential - true if the last path element must have an auto-incrementing
value attached i.e. if the final path element is always newproperties - the properties to setpath - the path to the propertiespublic boolean updateProperties(Properties properties, String... path)
ConfigServiceupdateProperties in interface ConfigServiceproperties - the properties to setpath - the path to the propertiespublic Set<String> getChildren(ConfigChildListener listener, String... path)
ConfigServicegetChildren in interface ConfigServicelistener - a listener to call if the the children change (null allowed)path - the path to the parentpublic ClassLoader getClassLoader(ConfigClassesListener listener, ClassLoader parent, String... path)
ConfigServiceClassLoader rooted at the given locationgetClassLoader in interface ConfigServicelistener - a listener to call if the classes change (null allowed)parent - the parent ClassLoaderpath - the path to the classes root (akin to a classpath)ClassLoaderpublic ClassLoader getJarLoader(ConfigClassesListener listener, ClassLoader parent, String... path)
ConfigServiceURLClassLoader rooted at the given location. The children of the given
path are found and each is treated as a separate jar file.getJarLoader in interface ConfigServicelistener - a listener to call if the classes change (null allowed)parent - the parent ClassLoaderpath - the path to the jarClassLoaderCopyright © 2013. All Rights Reserved.