Search in sources :

Example 16 with Proxy

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.
}
Also used : Proxy(java.lang.reflect.Proxy) OpenDataException(javax.management.openmbean.OpenDataException) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) ObjectName(javax.management.ObjectName)

Example 17 with Proxy

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;
}
Also used : Proxy(java.lang.reflect.Proxy) NotificationEmitter(javax.management.NotificationEmitter) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) MBeanServerInvocationHandler(javax.management.MBeanServerInvocationHandler) InvocationHandler(java.lang.reflect.InvocationHandler) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Example 18 with Proxy

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;
}
Also used : Proxy(java.lang.reflect.Proxy) MarshalledObject(java.rmi.MarshalledObject) URLClassLoader(java.net.URLClassLoader) RMIClassLoader(java.rmi.server.RMIClassLoader)

Example 19 with 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;
}
Also used : Proxy(java.lang.reflect.Proxy) Constructor(java.lang.reflect.Constructor)

Aggregations

Proxy (java.lang.reflect.Proxy)19 InvocationHandler (java.lang.reflect.InvocationHandler)10 Method (java.lang.reflect.Method)3 IOException (java.io.IOException)2 Constructor (java.lang.reflect.Constructor)2 URLClassLoader (java.net.URLClassLoader)2 RMIClassLoader (java.rmi.server.RMIClassLoader)2 MBeanServerInvocationHandler (javax.management.MBeanServerInvocationHandler)2 ObjectName (javax.management.ObjectName)2 IInterface (android.os.IInterface)1 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetFactory (com.facebook.buck.model.BuildTargetFactory)1 TestCellBuilder.createCellRoots (com.facebook.buck.rules.TestCellBuilder.createCellRoots)1 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)1 Preconditions (com.google.common.base.Preconditions)1 MXBeanProxy (com.sun.jmx.mbeanserver.MXBeanProxy)1 DATE (com.sun.jna.platform.win32.OaIdl.DATE)1 SAFEARRAY (com.sun.jna.platform.win32.OaIdl.SAFEARRAY)1 VARIANT_BOOL (com.sun.jna.platform.win32.OaIdl.VARIANT_BOOL)1