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 |
create(String... path)
Recursive creation of a path, allowing for the existence of any or all of the path.
|
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.ApplicationContextAware
org.springframework.beans.BeansException
public 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 ConfigService
path
- the path (over and above any root path) to checkpublic void delete(String... path)
delete
in interface ConfigService
path
- the path (over and above any root path)public void create(String... path)
exists
must always return
truecreate
in interface ConfigService
path
- the path to ensurepublic String getString(ConfigDataListener listener, String... path)
getString
in interface ConfigService
listener
- 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)
ConfigService
setData
in interface ConfigService
listener
- 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)
ConfigService
updateData
in interface ConfigService
bytes
- the properties to setpath
- the path to the propertiespublic String setString(ConfigDataListener listener, boolean ephemeral, boolean sequential, String value, String... path)
ConfigService
setString
in interface ConfigService
listener
- 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)
ConfigService
updateString
in interface ConfigService
value
- the value to setpath
- the path to the propertiespublic Properties getProperties(ConfigDataListener listener, String... path)
getProperties
in interface ConfigService
listener
- 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)
ConfigService
setProperties
in interface ConfigService
listener
- 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)
ConfigService
updateProperties
in interface ConfigService
properties
- the properties to setpath
- the path to the propertiespublic Set<String> getChildren(ConfigChildListener listener, String... path)
ConfigService
getChildren
in interface ConfigService
listener
- 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)
ConfigService
ClassLoader
rooted at the given locationgetClassLoader
in interface ConfigService
listener
- a listener to call if the classes change (null allowed)parent
- the parent ClassLoader
path
- the path to the classes root (akin to a classpath)ClassLoader
public ClassLoader getJarLoader(ConfigClassesListener listener, ClassLoader parent, String... path)
ConfigService
URLClassLoader
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 ConfigService
listener
- a listener to call if the classes change (null allowed)parent
- the parent ClassLoader
path
- the path to the jarClassLoader
Copyright © 2014. All rights reserved.