org.kairosdb.util.PluginClassLoader Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kairosdb Show documentation
Show all versions of kairosdb Show documentation
KairosDB is a time series database that stores numeric values along
with key/value tags to a nosql data store. Currently supported
backends are Cassandra and H2. An H2 implementation is provided
for development work.
package org.kairosdb.util;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.net.URLStreamHandlerFactory;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
/**
Created by bhawkins on 3/13/15.
*/
public class PluginClassLoader extends URLClassLoader
{
ClassLoader m_parentLoader;
public PluginClassLoader(URL[] urls, ClassLoader parent)
{
super(urls, parent);
m_parentLoader = parent;
}
@Override
protected Class> loadClass(String name, boolean resolve)
throws ClassNotFoundException
{
synchronized (getClassLoadingLock(name))
{
// First, check if the class has already been loaded
Class c = findLoadedClass(name);
if (c == null)
{
// If still not found, then invoke findClass in order
// to find the class.
try
{
c = findClass(name);
}
catch (ClassNotFoundException e)
{
//pass to the parent to throw exception
}
}
if (c == null)
{
c = m_parentLoader.loadClass(name);
}
if (resolve)
{
resolveClass(c);
}
return c;
}
}
@Override
public URL getResource(String name)
{
URL url;
url = findResource(name);
if (url == null)
url = m_parentLoader.getResource(name);
return url;
}
@Override
public Enumeration getResources(String name) throws IOException
{
Enumeration[] tmp = new Enumeration[2];
tmp[0] = findResources(name);
tmp[1] = m_parentLoader.getResources(name);
return new CompoundEnumeration(tmp);
}
}