Skip to content

Commit bca2340

Browse files
authored
Optimize jar discovery (#350)
* optimize jar discovery * remove lambda implementation * return of no jars are found * use static final annon class instead * use static reference for consistency
1 parent 65169c1 commit bca2340

File tree

1 file changed

+17
-5
lines changed
  • aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client

1 file changed

+17
-5
lines changed

aws-lambda-java-runtime-interface-client/src/main/java/com/amazonaws/services/lambda/runtime/api/client/CustomerClassLoader.java

+17-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.amazonaws.services.lambda.runtime.api.client;
44

55
import java.io.File;
6+
import java.io.FilenameFilter;
67
import java.io.IOException;
78
import java.net.MalformedURLException;
89
import java.net.URL;
@@ -18,6 +19,18 @@ class CustomerClassLoader extends URLClassLoader {
1819
* does not depend on the underlying filesystem.
1920
*/
2021
private final static Comparator<String> LEXICAL_SORT_ORDER = Comparator.comparing(String::toString);
22+
private final static FilenameFilter JAR_FILE_NAME_FILTER = new FilenameFilter() {
23+
24+
@Override
25+
public boolean accept(File dir, String name) {
26+
int offset = name.length() - 4;
27+
if (offset <= 0) { /* must be at least A.jar */
28+
return false;
29+
} else {
30+
return name.startsWith(".jar", offset);
31+
}
32+
}
33+
};
2134

2235
CustomerClassLoader(String taskRoot, String optRoot, ClassLoader parent) throws IOException {
2336
super(getUrls(taskRoot, optRoot), parent);
@@ -36,15 +49,14 @@ private static void appendJars(File dir, List<URL> result) throws MalformedURLEx
3649
if (!dir.isDirectory()) {
3750
return;
3851
}
39-
String[] names = dir.list();
52+
String[] names = dir.list(CustomerClassLoader.JAR_FILE_NAME_FILTER);
4053
if (names == null) {
4154
return;
4255
}
4356
Arrays.sort(names, CustomerClassLoader.LEXICAL_SORT_ORDER);
44-
for(String path : names) {
45-
if(path.endsWith(".jar")) {
46-
result.add(newURL(dir, path));
47-
}
57+
58+
for (String path : names) {
59+
result.add(newURL(dir, path));
4860
}
4961
}
5062

0 commit comments

Comments
 (0)