Skip to content

Commit

Permalink
Refactor dinky class loader (#2671)
Browse files Browse the repository at this point in the history
* refactor: DinkyClassLoader

Signed-off-by: licho <[email protected]>

* Spotless Apply

---------

Signed-off-by: licho <[email protected]>
Co-authored-by: leechor <[email protected]>
  • Loading branch information
leechor and leechor authored Dec 18, 2023
1 parent 6c73913 commit 3781a72
Showing 1 changed file with 17 additions and 22 deletions.
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

0 comments on commit 3781a72

Please sign in to comment.