org.alfresco.bm.classloader.zookeeper
Class ZooKeeperClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by org.alfresco.bm.classloader.zookeeper.ZooKeeperClassLoader
All Implemented Interfaces:
CallbackClassLoader, org.I0Itec.zkclient.IZkChildListener, org.I0Itec.zkclient.IZkDataListener

public class ZooKeeperClassLoader
extends ClassLoader
implements CallbackClassLoader, org.I0Itec.zkclient.IZkDataListener, org.I0Itec.zkclient.IZkChildListener

A Java ClassLoader pulling classes from ZooKeeper.

This class loader allows listeners to be registered to receive callbacks when the ZooKeeper data changes.

Since:
1.0
Author:
Derek Hulley

Constructor Summary
ZooKeeperClassLoader(ClassLoader parentClassloader, org.I0Itec.zkclient.ZkClient zk, String rootPath)
           
 
Method Summary
 void addListener(ClassLoaderListener listener)
          Add a change listener
 void handleChildChange(String parentPath, List<String> currentChilds)
          Calls any listeners.
 void handleDataChange(String dataPath, Object data)
          Calls any listeners.
 void handleDataDeleted(String dataPath)
          Calls any listeners.
 Class<?> loadClass(String name)
          Takes the rootPath variable and finds (using '/' in place of '.') the class in ZooKeeper.
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findResources, findSystemClass, getPackage, getPackages, getParent, getResource, getResourceAsStream, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, loadClass, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZooKeeperClassLoader

public ZooKeeperClassLoader(ClassLoader parentClassloader,
                            org.I0Itec.zkclient.ZkClient zk,
                            String rootPath)
Parameters:
parentClassloader - the (required) parent class loader
zk - the ZK client to run against
rootPath - the ZK root path (akin to a classpath entry)
Method Detail

handleChildChange

public void handleChildChange(String parentPath,
                              List<String> currentChilds)
                       throws Exception
Calls any listeners.

Specified by:
handleChildChange in interface org.I0Itec.zkclient.IZkChildListener
Throws:
Exception

handleDataChange

public void handleDataChange(String dataPath,
                             Object data)
                      throws Exception
Calls any listeners.

Specified by:
handleDataChange in interface org.I0Itec.zkclient.IZkDataListener
Throws:
Exception

handleDataDeleted

public void handleDataDeleted(String dataPath)
                       throws Exception
Calls any listeners.

Specified by:
handleDataDeleted in interface org.I0Itec.zkclient.IZkDataListener
Throws:
Exception

addListener

public void addListener(ClassLoaderListener listener)
Add a change listener

Specified by:
addListener in interface CallbackClassLoader
Parameters:
listener - the listener that will be called if there are any changes to classes already loaded

loadClass

public Class<?> loadClass(String name)
                   throws ClassNotFoundException
Takes the rootPath variable and finds (using '/' in place of '.') the class in ZooKeeper.

Overrides:
loadClass in class ClassLoader
Throws:
ClassNotFoundException


Copyright © 2012. All Rights Reserved.