changed proxy creation for local apps to subclass proxies to avoid instanceof errors (like in the tests)
This commit is contained in:
@@ -22,9 +22,6 @@ import com.google.common.collect.ImmutableMap;
|
||||
import com.sun.tools.attach.VirtualMachine;
|
||||
import com.sun.tools.attach.VirtualMachineDescriptor;
|
||||
|
||||
import net.sf.cglib.proxy.Enhancer;
|
||||
import net.sf.cglib.proxy.MethodInterceptor;
|
||||
|
||||
public class LocalSpringBootAppCache {
|
||||
|
||||
private static final Duration EXPIRE_AFTER = Duration.ofMillis(500); //Limits rate at which we refresh list of apps
|
||||
@@ -48,10 +45,8 @@ public class LocalSpringBootAppCache {
|
||||
newAppsBuilder.put(vm, existingApp);
|
||||
} else {
|
||||
try {
|
||||
LocalSpringBootApp localApp = new LocalSpringBootApp(vm);
|
||||
MethodInterceptor handler = new MemoizingProxy.MemoizingProxyHandler(localApp, Duration.ofMillis(4500));
|
||||
SpringBootApp proxiedLocalApp = (SpringBootApp) Enhancer.create(SpringBootApp.class, handler);
|
||||
newAppsBuilder.put(vm, proxiedLocalApp);
|
||||
LocalSpringBootApp localApp = MemoizingProxy.create(LocalSpringBootApp.class, Duration.ofMillis(4500), new Class[] {VirtualMachineDescriptor.class}, vm);
|
||||
newAppsBuilder.put(vm, localApp);
|
||||
} catch (Exception e) {
|
||||
//Ignore problems attaching to a VM. We will try again on next polling loop, if vm still exists.
|
||||
//The most likely cause is that the VM already died since we obtained a reference to it.
|
||||
|
||||
@@ -99,7 +99,7 @@ public class RemoteSpringBootApp extends AbstractSpringBootApp {
|
||||
}
|
||||
|
||||
public static SpringBootApp create(String jmxUrl, String host) {
|
||||
return MemoizingProxy.create(RemoteSpringBootApp.class, Duration.ofMillis(4900), jmxUrl, host);
|
||||
return MemoizingProxy.create(RemoteSpringBootApp.class, Duration.ofMillis(4900), new Class[] {String.class, String.class}, jmxUrl, host);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class MemoizingProxy {
|
||||
* Memoizes all zero-argument public methods for a given duration.
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T create(Class<T> klass, Duration duration, Object... args) {
|
||||
public static <T> T create(Class<T> klass, Duration duration, Class<?>[] argTypes, Object... args) {
|
||||
Enhancer enhancer = new Enhancer();
|
||||
enhancer.setSuperclass(klass);
|
||||
enhancer.setCallback(new MethodInterceptor() {
|
||||
@@ -82,11 +82,8 @@ public class MemoizingProxy {
|
||||
}
|
||||
}
|
||||
});
|
||||
Class<?>[] argumentTypes = new Class<?>[args.length];
|
||||
for (int i = 0; i < argumentTypes.length; i++) {
|
||||
argumentTypes[i] = args[i].getClass();
|
||||
}
|
||||
return (T) enhancer.create(argumentTypes, args);
|
||||
|
||||
return (T) enhancer.create(argTypes, args);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user