use of java.lang.reflect.Proxy in project jdk8u_jdk by JetBrains.
the class MXBeanLookup method mxbeanToObjectName.
synchronized ObjectName mxbeanToObjectName(Object mxbean) throws OpenDataException {
String wrong;
if (mxbean instanceof Proxy) {
InvocationHandler ih = Proxy.getInvocationHandler(mxbean);
if (ih instanceof MBeanServerInvocationHandler) {
MBeanServerInvocationHandler mbsih = (MBeanServerInvocationHandler) ih;
if (mbsih.getMBeanServerConnection().equals(mbsc))
return mbsih.getObjectName();
else
wrong = "proxy for a different MBeanServer";
} else
wrong = "not a JMX proxy";
} else {
ObjectName name = mxbeanToObjectName.get(mxbean);
if (name != null)
return name;
wrong = "not an MXBean registered in this MBeanServer";
}
String s = (mxbean == null) ? "null" : "object of type " + mxbean.getClass().getName();
throw new OpenDataException("Could not convert " + s + " to an ObjectName: " + wrong);
// Message will be strange if mxbean is null but it is not
// supposed to be.
}
use of java.lang.reflect.Proxy in project jdk8u_jdk by JetBrains.
the class TestUtils method makeNotificationEmitter.
/**
* Transfroms a proxy implementing T in a proxy implementing T plus
* NotificationEmitter
*
**/
public static <T> T makeNotificationEmitter(T proxy, Class<T> mbeanInterface) {
if (proxy instanceof NotificationEmitter)
return proxy;
if (proxy == null)
return null;
if (!(proxy instanceof Proxy))
throw new IllegalArgumentException("not a " + Proxy.class.getName());
final Proxy p = (Proxy) proxy;
final InvocationHandler handler = Proxy.getInvocationHandler(proxy);
if (!(handler instanceof MBeanServerInvocationHandler))
throw new IllegalArgumentException("not a JMX Proxy");
final MBeanServerInvocationHandler h = (MBeanServerInvocationHandler) handler;
final ObjectName name = h.getObjectName();
final MBeanServerConnection mbs = h.getMBeanServerConnection();
final boolean isMXBean = h.isMXBean();
final T newProxy;
if (isMXBean)
newProxy = JMX.newMXBeanProxy(mbs, name, mbeanInterface, true);
else
newProxy = JMX.newMBeanProxy(mbs, name, mbeanInterface, true);
return newProxy;
}
use of java.lang.reflect.Proxy in project jdk8u_jdk by JetBrains.
the class LoadProxyClasses method unmarshalProxyClass.
private static Proxy unmarshalProxyClass(Proxy proxy, ClassLoader fnnLoader, ClassLoader expectedLoader, int n, LoadChecker checker) throws ClassNotFoundException, IOException, InstantiationException, IllegalAccessException {
FnnUnmarshal fnnUnmarshal = (FnnUnmarshal) fnnLoader.loadClass("FnnClass").newInstance();
Proxy unmarshalled = (Proxy) fnnUnmarshal.unmarshal(new MarshalledObject(proxy));
ClassLoader unmarshalledLoader = unmarshalled.getClass().getClassLoader();
if (checker != null) {
checker.checkLoad(unmarshalled, expectedLoader);
} else {
if (unmarshalledLoader != expectedLoader) {
TestLibrary.bomb("case" + n + ": proxy class not " + "placed into incorrect loader: " + unmarshalledLoader);
} else {
System.err.println("\ncase" + n + ": proxy class correctly" + " placed into expected loader: " + expectedLoader);
}
}
return proxy;
}
use of java.lang.reflect.Proxy in project jdk8u_jdk by JetBrains.
the class ProxyArrays method genArrays.
/**
* Generate proxy arrays.
*/
Proxy[][] genArrays(int size, int narrays) throws Exception {
Class proxyClass = Proxy.getProxyClass(DummyInterface.class.getClassLoader(), new Class[] { DummyInterface.class });
Constructor proxyCons = proxyClass.getConstructor(new Class[] { InvocationHandler.class });
Object[] consArgs = new Object[] { new DummyHandler() };
Proxy[][] arrays = new Proxy[narrays][size];
for (int i = 0; i < narrays; i++) {
for (int j = 0; j < size; j++) {
arrays[i][j] = (Proxy) proxyCons.newInstance(consArgs);
}
}
return arrays;
}
Aggregations