org.alfresco.config.zookeeper
Class ZkConfigService

java.lang.Object
  extended by org.alfresco.config.zookeeper.ZkConfigService
All Implemented Interfaces:
EventListener, ConfigService, org.springframework.beans.factory.Aware, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationListener<org.springframework.context.event.ApplicationContextEvent>

public class ZkConfigService
extends Object
implements ConfigService, org.springframework.context.ApplicationListener<org.springframework.context.event.ApplicationContextEvent>, org.springframework.context.ApplicationContextAware

ZooKeeper-based configuration loader that, starting from a root path, loads benchmark-related configurations.

Since:
1.0
Author:
Derek Hulley

Field Summary
 
Fields inherited from interface org.alfresco.config.ConfigService
SEPARATOR
 
Constructor Summary
ZkConfigService(org.I0Itec.zkclient.ZkClient zk, String zkPath)
          Construct the configuration loader.
 
Method Summary
 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZkConfigService

public ZkConfigService(org.I0Itec.zkclient.ZkClient zk,
                       String zkPath)
Construct the configuration loader.

Parameters:
zk - the ZooKeeper client
zkPath - the root path to use in ZK
Method Detail

setApplicationContext

public void setApplicationContext(org.springframework.context.ApplicationContext ctx)
                           throws org.springframework.beans.BeansException
Record the context that started this instance.

Specified by:
setApplicationContext in interface org.springframework.context.ApplicationContextAware
Throws:
org.springframework.beans.BeansException

onApplicationEvent

public void onApplicationEvent(org.springframework.context.event.ApplicationContextEvent event)
Handles start and stop by checking configuration and cleaning caches respectively.

Specified by:
onApplicationEvent in interface org.springframework.context.ApplicationListener<org.springframework.context.event.ApplicationContextEvent>

shutdown

public void shutdown()
Drop any stored configuration and discard any watchers


exists

public boolean exists(String... path)
Check if a given path exists

Specified by:
exists in interface ConfigService
Parameters:
path - the path (over and above any root path) to check
Returns:
true if the path exists

delete

public void delete(String... path)
Recursive delete of a path without any option to recover.

Specified by:
delete in interface ConfigService
Parameters:
path - the path (over and above any root path)

getString

public String getString(ConfigDataListener listener,
                        String... path)
Retrieve string data from a given path

Specified by:
getString in interface ConfigService
Parameters:
listener - a listener to call if the data changes (null allowed)
path - the path to the data
Returns:
Returns the data or null if not found

setData

public String setData(ConfigDataListener listener,
                      boolean ephemeral,
                      boolean sequential,
                      byte[] bytes,
                      String... path)
Description copied from interface: ConfigService
Set binary data

Specified by:
setData in interface ConfigService
Parameters:
listener - a listener to call if the properties change (null allowed)
ephemeral - true if the path should be removed when the server stops
sequential - true if the last path element must have an auto-incrementing value attached i.e. if the final path element is always new
bytes - the data to set
path - the path to the properties
Returns:
the final path element, which will be different from the one supplied if it is auto-incrementing

updateData

public boolean updateData(byte[] bytes,
                          String... path)
Description copied from interface: ConfigService
Update data at a given path

Specified by:
updateData in interface ConfigService
Parameters:
bytes - the properties to set
path - the path to the properties
Returns:
true if the properties were updated otherwise false

setString

public String setString(ConfigDataListener listener,
                        boolean ephemeral,
                        boolean sequential,
                        String value,
                        String... path)
Description copied from interface: ConfigService
Retrieve string data from a given path

Specified by:
setString in interface ConfigService
Parameters:
listener - a listener to call if the data changes (null allowed)
ephemeral - true if the path should be removed when the server stops
sequential - true if the last path element must have an auto-incrementing value attached i.e. if the final path element is always new
value - the value to set
path - the path to the properties
Returns:
the final path element, which will be different from the one supplied if it is auto-incrementing

updateString

public boolean updateString(String value,
                            String... path)
Description copied from interface: ConfigService
Update a specific string value

Specified by:
updateString in interface ConfigService
Parameters:
value - the value to set
path - the path to the properties
Returns:
true if a value was updated otherwise false

getProperties

public Properties getProperties(ConfigDataListener listener,
                                String... path)
Retrieve the properties from a given path

Specified by:
getProperties in interface ConfigService
Parameters:
listener - a listener to call if the properties change (null allowed)
path - the path to the properties
Returns:
Java properties from the location (never null)

setProperties

public String setProperties(ConfigDataListener listener,
                            boolean ephemeral,
                            boolean sequential,
                            Properties properties,
                            String... path)
Description copied from interface: ConfigService
Set properties against a path

Specified by:
setProperties in interface ConfigService
Parameters:
listener - a listener to call if the properties change (null allowed)
ephemeral - true if the path should be removed when the server stops
sequential - true if the last path element must have an auto-incrementing value attached i.e. if the final path element is always new
properties - the properties to set
path - the path to the properties
Returns:
the final path element, which will be different from the one supplied if it is auto-incrementing

updateProperties

public boolean updateProperties(Properties properties,
                                String... path)
Description copied from interface: ConfigService
Update properties at a given path

Specified by:
updateProperties in interface ConfigService
Parameters:
properties - the properties to set
path - the path to the properties
Returns:
true if the properties were updated otherwise false

getChildren

public Set<String> getChildren(ConfigChildListener listener,
                               String... path)
Description copied from interface: ConfigService
Retrieve the children of a given path

Specified by:
getChildren in interface ConfigService
Parameters:
listener - a listener to call if the the children change (null allowed)
path - the path to the parent
Returns:
Returns the current children of the provided path (never null)

getClassLoader

public ClassLoader getClassLoader(ConfigClassesListener listener,
                                  ClassLoader parent,
                                  String... path)
Description copied from interface: ConfigService
Retrieve a ClassLoader rooted at the given location

Specified by:
getClassLoader in interface ConfigService
Parameters:
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)
Returns:
Returns the new ClassLoader

getJarLoader

public ClassLoader getJarLoader(ConfigClassesListener listener,
                                ClassLoader parent,
                                String... path)
Description copied from interface: ConfigService
Retrieve a URLClassLoader rooted at the given location. The children of the given path are found and each is treated as a separate jar file.

Specified by:
getJarLoader in interface ConfigService
Parameters:
listener - a listener to call if the classes change (null allowed)
parent - the parent ClassLoader
path - the path to the jar
Returns:
Returns the new ClassLoader


Copyright © 2012. All Rights Reserved.