org.alfresco.bm.config.zookeeper
Class ZkConfigService

java.lang.Object
  extended by org.alfresco.bm.config.zookeeper.ZkConfigService
All Implemented Interfaces:
EventListener, org.alfresco.bm.config.ConfigConstants, 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

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.alfresco.bm.config.ConfigConstants
org.alfresco.bm.config.ConfigConstants.RunState
 
Field Summary
 
Fields inherited from interface org.alfresco.bm.config.ConfigConstants
DEFAULT_RUNSTATE, DEFAULT_SERVER_ID, PATH_CLASSES, PATH_CLUSTERS, PATH_DEFINITION, PATH_JARS, PATH_LOADED, PATH_PROPERTIES, PATH_RUNS, PATH_SERVER, PATH_SERVERS, PATH_TESTS, PROP_CLUSTER, PROP_CONTROL_CLUSTER, PROP_CONTROL_RUN_STATE, PROP_EVENT_PROCESSOR_THREADS, PROP_MONGO_URI, PROP_SERVER_ID, PROP_TEST_NAME, PROP_TEST_RUN_FQN, PROP_TEST_RUN_NAME, SEPARATOR
 
Constructor Summary
ZkConfigService(org.I0Itec.zkclient.ZkClient zk, String zkPath)
          Construct the configuration loader.
 
Method Summary
 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 setProperties(ConfigDataListener listener, boolean ephemeral, boolean sequential, Properties properties, String... path)
          Set properties against a path
 void shutdown()
          Drop any stored configuration and discard any watchers
 
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

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

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

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.