Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions extensions-core/kafka-extraction-namespace/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<groupId>org.apache.druid.extensions</groupId>
<artifactId>druid-lookups-cached-global</artifactId>
<version>${project.parent.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.druid</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dependsOnDruidExtensions": ["druid-lookups-cached-global"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.apache.druid.guice;

import com.fasterxml.jackson.annotation.JsonProperty;

import javax.annotation.Nonnull;

import java.util.ArrayList;
import java.util.List;

public class DruidExtensionDependencies
{

@JsonProperty("dependsOnDruidExtensions")
private List<String> dependsOnDruidExtensions;

public DruidExtensionDependencies()
{
this.dependsOnDruidExtensions = new ArrayList<>();
}

public DruidExtensionDependencies(@Nonnull final List<String> dependsOnDruidExtensions)
{
this.dependsOnDruidExtensions = dependsOnDruidExtensions;
}

public List<String> getDependsOnDruidExtensions()
{
return dependsOnDruidExtensions;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,20 @@

import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;

/**
* The ClassLoader that gets used when druid.extensions.useExtensionClassloaderFirst = true.
*/
public class ExtensionFirstClassLoader extends URLClassLoader
public class ExtensionFirstClassLoader extends StandardURLClassLoader
{
private final ClassLoader druidLoader;

public ExtensionFirstClassLoader(final URL[] urls, final ClassLoader druidLoader)
public ExtensionFirstClassLoader(final URL[] urls, final ClassLoader druidLoader, final List<ClassLoader> extensionDependencyClassLoaders)
{
super(urls, null);
super(urls, null, extensionDependencyClassLoaders);
this.druidLoader = Preconditions.checkNotNull(druidLoader, "druidLoader");
}

Expand All @@ -60,8 +59,13 @@ protected Class<?> loadClass(final String name, final boolean resolve) throws Cl
clazz = findClass(name);
}
catch (ClassNotFoundException e) {
// Try the Druid classloader. Will throw ClassNotFoundException if the class can't be loaded.
return druidLoader.loadClass(name);
try {
clazz = loadClassFromExtensionDependencies(name);
}
catch (ClassNotFoundException e2) {
// Try the Druid classloader. Will throw ClassNotFoundException if the class can't be loaded.
clazz = druidLoader.loadClass(name);
}
}
}

Expand All @@ -76,20 +80,26 @@ protected Class<?> loadClass(final String name, final boolean resolve) throws Cl
@Override
public URL getResource(final String name)
{
final URL resourceFromExtension = super.getResource(name);
URL resourceFromExtension = super.getResource(name);

if (resourceFromExtension != null) {
return resourceFromExtension;
} else {
return druidLoader.getResource(name);
}

resourceFromExtension = getResourceFromExtensionsDependencies(name);
if (resourceFromExtension != null) {
return resourceFromExtension;
}

return druidLoader.getResource(name);
}

@Override
public Enumeration<URL> getResources(final String name) throws IOException
{
final List<URL> urls = new ArrayList<>();
Iterators.addAll(urls, Iterators.forEnumeration(super.getResources(name)));
addExtensionResources(name, urls);
Iterators.addAll(urls, Iterators.forEnumeration(druidLoader.getResources(name)));
return Iterators.asEnumeration(urls.iterator());
}
Expand Down
Loading