Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor dinky class loader #2671

Merged
merged 3 commits into from
Dec 18, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,32 +42,34 @@ public class DinkyClassLoader extends URLClassLoader {
FlinkUdfPathContextHolder udfPathContextHolder = new FlinkUdfPathContextHolder();

public DinkyClassLoader(URL[] urls, ClassLoader parent) {
super(new URL[] {}, parent);
this(urls, parent, null);
}

public DinkyClassLoader(Collection<File> fileSet, ClassLoader parent) {
super(new URL[] {}, parent);
addURLs(fileSet);
this(convertFilesToUrls(fileSet), parent, null);
}

public DinkyClassLoader(URL[] urls) {
super(new URL[] {});
this(urls, Thread.currentThread().getContextClassLoader(), null);
}

public DinkyClassLoader(URL[] urls, ClassLoader parent, URLStreamHandlerFactory factory) {
super(new URL[] {}, parent, factory);
}

// this class factory method
public static DinkyClassLoader build() {
return new DinkyClassLoader(new URL[] {});
super(urls, parent, factory);
}

// class factory method with urls parameters
public static DinkyClassLoader build(URL... urls) {
return new DinkyClassLoader(urls);
}

public static DinkyClassLoader build(URL[] urls, ClassLoader parent) {
return new DinkyClassLoader(urls, parent);
}

public static DinkyClassLoader build(ClassLoader parent) {
return new DinkyClassLoader(new URL[] {}, parent);
}

// return udfPathContextHolder
public FlinkUdfPathContextHolder getUdfPathContextHolder() {
return udfPathContextHolder;
Expand All @@ -80,30 +82,23 @@ public void addURLs(URL... urls) {
}

public void addURLs(Collection<File> fileSet) {
URL[] urls = fileSet.stream()
.map(x -> {
try {
return x.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
})
.toArray(URL[]::new);
URL[] urls = convertFilesToUrls(fileSet);
addURLs(urls);
}

public void addURLs(List<File> files) {
files.stream()
private static URL[] convertFilesToUrls(Collection<File> fileSet) {
return fileSet.stream()
.map(x -> {
try {
return x.toURI().toURL();
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
})
.forEach(this::addURL);
.toArray(URL[]::new);
}

@Override
public void addURL(URL url) {
super.addURL(url);
}
Expand Down
Loading