13
0
geforkt von Mirrors/Velocity

Merge branch 'dev/1.1.0' into decode-multiple

Dieser Commit ist enthalten in:
Andrew Steinborn 2019-12-06 03:10:25 -05:00
Commit 97da6753b5
3 geänderte Dateien mit 26 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -13,6 +13,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
public class Natives { public class Natives {
@ -24,12 +25,12 @@ public class Natives {
private static Runnable copyAndLoadNative(String path) { private static Runnable copyAndLoadNative(String path) {
return () -> { return () -> {
try { try {
Path tempFile = Files.createTempFile("native-", path.substring(path.lastIndexOf('.')));
InputStream nativeLib = Natives.class.getResourceAsStream(path); InputStream nativeLib = Natives.class.getResourceAsStream(path);
if (nativeLib == null) { if (nativeLib == null) {
throw new IllegalStateException("Native library " + path + " not found."); throw new IllegalStateException("Native library " + path + " not found.");
} }
Path tempFile = createTemporaryNativeFilename(path.substring(path.lastIndexOf('.')));
Files.copy(nativeLib, tempFile, StandardCopyOption.REPLACE_EXISTING); Files.copy(nativeLib, tempFile, StandardCopyOption.REPLACE_EXISTING);
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { try {
@ -38,13 +39,27 @@ public class Natives {
// Well, it doesn't matter... // Well, it doesn't matter...
} }
})); }));
try {
System.load(tempFile.toAbsolutePath().toString()); System.load(tempFile.toAbsolutePath().toString());
} catch (UnsatisfiedLinkError e) {
throw new NativeSetupException("Unable to load native " + tempFile.toAbsolutePath(), e);
}
} catch (IOException e) { } catch (IOException e) {
throw new NativeSetupException("Unable to copy natives", e); throw new NativeSetupException("Unable to copy natives", e);
} }
}; };
} }
private static Path createTemporaryNativeFilename(String ext) throws IOException {
String temporaryFolderPath = System.getProperty("velocity.natives-tmpdir");
if (temporaryFolderPath != null) {
return Files.createTempFile(Paths.get(temporaryFolderPath), "native-", ext);
} else {
return Files.createTempFile("native-", ext);
}
}
public static final NativeCodeLoader<VelocityCompressorFactory> compress = new NativeCodeLoader<>( public static final NativeCodeLoader<VelocityCompressorFactory> compress = new NativeCodeLoader<>(
ImmutableList.of( ImmutableList.of(
new NativeCodeLoader.Variant<>(NativeConstraints.MACOS, new NativeCodeLoader.Variant<>(NativeConstraints.MACOS,

Datei anzeigen

@ -23,6 +23,12 @@ public class Velocity {
if (System.getProperty("io.netty.allocator.maxOrder") == null) { if (System.getProperty("io.netty.allocator.maxOrder") == null) {
System.setProperty("io.netty.allocator.maxOrder", "9"); System.setProperty("io.netty.allocator.maxOrder", "9");
} }
// If Velocity's natives are being extracted to a different temporary directory, make sure the
// Netty natives are extracted there as well
if (System.getProperty("velocity.natives-tmpdir") != null) {
System.setProperty("io.netty.native.workdir", System.getProperty("velocity.natives-tmpdir"));
}
} }
/** /**

Datei anzeigen

@ -7,6 +7,7 @@ import io.netty.util.concurrent.EventExecutor;
import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.FutureListener;
import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateEventExecutor;
import io.netty.util.concurrent.Promise; import io.netty.util.concurrent.Promise;
import io.netty.util.internal.ThreadExecutorMap;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
@ -61,13 +62,7 @@ public class DnsAddressResolverGroupNameResolverAdapter extends InetNameResolver
} }
private EventExecutor findExecutor() { private EventExecutor findExecutor() {
for (EventExecutor executor : group) { EventExecutor current = ThreadExecutorMap.currentExecutor();
if (executor.inEventLoop()) { return current == null ? group.next() : current;
return executor;
}
}
// otherwise, pick one
return group.next();
} }
} }