This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HostResolutionRequestInterceptor.INSTANCE.install( | |
new DNSClientHostResolver("208.67.222.222"), //Open DNS server | |
new DNSClientHostResolver("208.67.222.220"), //Open DNS server | |
new DNSClientHostResolver("8.8.8.8"), //Google DNS server | |
new DNSClientHostResolver("8.8.4.4"), //Google DNS server | |
DefaultHostResolver.INSTANCE | |
); | |
InetAddress inetAddress = InetAddress.getByName("github.com"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
HostResolutionRequestInterceptor.INSTANCE.install( | |
new HostResolver() { | |
@Override | |
public Collection<InetAddress> getAllAddressesForHostName(Map<String, Object> argumentMap) { | |
String hostName = (String)super.getMethodArguments(argumentMap)[0] | |
//Do the stuff... | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Map<String, String> hostAliases = new LinkedHashMap<>(); | |
hostAliases.put("my.hostname.one", "123.123.123.123"); | |
//Installing the host resolvers | |
HostResolutionRequestInterceptor.INSTANCE.install( | |
new MappedHostResolver(hostAliases), | |
//This is the system default resolving wrapper | |
DefaultHostResolver.INSTANCE | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hostAliases: | |
- ip: 123.123.123.123 | |
hostnames: | |
- my.hostname.one | |
- my.hostname.two | |
- ip: 12.21.34.43 | |
hostnames: | |
- my.hostname.three | |
- my.hostname.four | |
dns: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void installHostResolutionRequestInterceptor() throws UnknownHostException { | |
Map<String, Object> configuration = loadConfiguration("config.yml"); | |
List<HostResolver> resolvers = new ArrayList<>(); | |
resolvers.add( | |
new MappedHostResolver(() -> (List<Map<String, Object>>)configuration.get("hostAliases")) | |
); | |
resolvers.addAll( | |
DNSClientHostResolver.newInstances(() -> | |
(List<Map<String, Object>>)((Map<String, Object>)configuration.get("dns")).get("servers") | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Installing the host resolvers | |
HostResolverService.INSTANCE.install( | |
new HostResolverService.Resolver() { | |
@Override | |
public Collection<InetAddress> getAllAddressesForHostName(Map<String, Object> arguments) { | |
... | |
} | |
@Override |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.burningwave.core.assembler.StaticComponentContainer.Modules.exportAllToAll(); | |
//Now that we have called exportAllToAll () we can use any class of any module | |
Method method = URLClassLoader.class.getDeclaredMethod("addURL", URL.class); | |
method.setAccessible(true); | |
ClassLoader classLoader = new URLClassLoader(new URL[] {}, null); | |
method.invoke( | |
classLoader, | |
org.burningwave.core.assembler.StaticComponentContainer.Resources.getClassPath(AllModulesToAllModulesExporter.class).getURL() | |
); | |
Class<?> fieldsHandlerClass = classLoader.loadClass(FieldsHandler.class.getName()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Filtering and obtaining a MethodHandle reference | |
MethodHandle defineClassMethodHandle = org.burningwave.core.assembler.StaticComponentContainer.Methods.findFirstDirectHandle( | |
MethodCriteria.byScanUpTo((cls) -> | |
//We only analyze the ClassLoader class and not all of its hierarchy (default behavior) | |
cls.getName().equals(ClassLoader.class.getName()) | |
).name( | |
"defineClass"::equals | |
).and().parameterTypes(params -> | |
params.length == 5 | |
).and().parameterTypesAreAssignableFrom( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
org.burningwave.core.classes.Methods methods = | |
org.burningwave.core.assembler.StaticComponentContainer.Methods; | |
//Filtering and obtaining a Method reference | |
Method method = methods.findFirst( | |
MethodCriteria.byScanUpTo((cls) -> | |
//We only analyze the ClassLoader class and not all of its hierarchy (default behavior) | |
cls.getName().equals(ClassLoader.class.getName()) | |
).name( | |
"defineClass"::equals | |
).and().parameterTypes(params -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//loading the byte code | |
org.burningwave.core.io.FileSystemItem fileSystemItem = | |
org.burningwave.core.io.FileSystemItem.ofPath( | |
"C:/my/pckg/MyClass.class" | |
); | |
byte[] byteCode = fileSystemItem.toByteArray(); | |
//invoking defineClass method handle | |
Class<?> cls = org.burningwave.core.assembler.StaticComponentContainer.Methods.invokeDirect( | |
Thread.currentThread().getContextClassLoader(), |
NewerOlder