List of usage examples for java.lang.reflect Proxy getProxyClass
@Deprecated @CallerSensitive public static Class<?> getProxyClass(ClassLoader loader, Class<?>... interfaces) throws IllegalArgumentException
From source file:org.apache.hadoop.hbase.ipc.HBaseRPC.java
private static synchronized RpcEngine getProtocolEngine(Class protocol, Configuration conf) { RpcEngine engine = PROTOCOL_ENGINES.get(protocol); if (engine == null) { // check for a configured default engine Class<?> defaultEngine = conf.getClass(RPC_ENGINE_PROP, WritableRpcEngine.class); // check for a per interface override Class<?> impl = conf.getClass(RPC_ENGINE_PROP + "." + protocol.getName(), defaultEngine); LOG.debug("Using " + impl.getName() + " for " + protocol.getName()); engine = (RpcEngine) ReflectionUtils.newInstance(impl, conf); if (protocol.isInterface()) PROXY_ENGINES.put(Proxy.getProxyClass(protocol.getClassLoader(), protocol), engine); PROTOCOL_ENGINES.put(protocol, engine); }//from w ww . j a v a 2 s .c om return engine; }
From source file:org.apache.bval.jsr.xml.AnnotationProxyBuilder.java
/** * Create the annotation represented by this builder. * * @return {@link Annotation}/*from ww w . j av a 2 s .c o m*/ */ public A createAnnotation() { final ClassLoader classLoader = Reflection.getClassLoader(getType()); @SuppressWarnings("unchecked") final Class<A> proxyClass = (Class<A>) Proxy.getProxyClass(classLoader, getType()); final InvocationHandler handler = new AnnotationProxy(this); return doCreateAnnotation(proxyClass, handler); }
From source file:org.nebularis.defproxy.AnnotationDrivenProxyFactoryTestCase.java
private <T> T wrap(final Object delegateObject, final Class<T> clazz) { InvocationHandler handler = new InvocationHandler() { private final Object delegate = delegateObject; @Override//from ww w. j a v a 2 s . com public Object invoke(Object o, Method method, Object[] objects) throws Throwable { // handlerConfiguration.getMethodInvoker(method).handleInvocation(delegate, objects); return ((MyDelegate) delegate).getName(); } }; final Class proxyClass = Proxy.getProxyClass(clazz.getClassLoader(), new Class[] { clazz }); final Object obj = createProxyInstance(handler, proxyClass); final T casted = (T) obj; return casted; }
From source file:dk.netarkivet.monitor.jmx.HostForwarding.java
/** * Register all remote Mbeans on the given MBeanServer. The username, and * password are the same for all JMX-connections. For hosts which cannot be * connected to, an mbean is registered in the same domain, which tries to * reconnect on any invocation, and returns the status of the attempt as a * string./*from www. j a v a2 s . com*/ * * @param hosts the list of remote Hosts. */ private void registerRemoteMbeans(List<HostEntry> hosts) { for (HostEntry hostEntry : hosts) { log.debug("Forwarding mbeans '" + this.mBeanQuery + "' for host: " + hostEntry); try { createProxyMBeansForHost(hostEntry); } catch (Exception e) { log.warn("Failure connecting to remote JMX MBeanserver (" + hostEntry + ")", e); try { // This creates a proxy object that calls the handler on any // invocation of any method on the object. NoHostInvocationHandler handler = new NoHostInvocationHandler(hostEntry); Class<T> proxyClass = (Class<T>) Proxy.getProxyClass(asInterface.getClassLoader(), new Class[] { asInterface }); T noHostMBean = proxyClass.getConstructor(InvocationHandler.class).newInstance(handler); SingleMBeanObject<T> singleMBeanObject = new SingleMBeanObject<T>(queryToDomain(mBeanQuery), noHostMBean, asInterface, mBeanServer); Hashtable<String, String> names = singleMBeanObject.getNameProperties(); names.put("name", "error_host_" + hostEntry.getName() + "_" + hostEntry.getJmxPort()); names.put("index", Integer.toString(0)); names.put("hostname", hostEntry.getName()); handler.setSingleMBeanObject(singleMBeanObject); singleMBeanObject.register(); } catch (Exception e1) { log.warn("Failure registering error mbean for hostentry: " + hostEntry, e1); } } } }
From source file:dk.netarkivet.monitor.jmx.HostForwarding.java
/** * Connects to the given host, and lists all mbeans matching the query. For * each of these mbeans, registers a proxymbean, that on any invocation will * connect to the remote host, and return the result of invoking the method * on the remote object.//from www. j av a 2 s . c o m * * @param hostEntry The host to connect to. * * @throws IOFailure if remote host cannot be connected to. */ private synchronized void createProxyMBeansForHost(HostEntry hostEntry) { Set<ObjectName> remoteObjectNames; JMXProxyConnection connection = connectionFactory.getConnection(hostEntry.getName(), hostEntry.getJmxPort(), hostEntry.getRmiPort(), getJmxUsername(), getJmxPassword()); remoteObjectNames = connection.query(mBeanQuery); for (ObjectName name : remoteObjectNames) { try { // This creates a proxy object that calls the handler on any // invocation of any method on the object. ProxyMBeanInvocationHandler handler = new ProxyMBeanInvocationHandler(name, hostEntry); Class<T> proxyClass = (Class<T>) Proxy.getProxyClass(asInterface.getClassLoader(), new Class[] { asInterface }); T mbean = proxyClass.getConstructor(InvocationHandler.class).newInstance(handler); SingleMBeanObject<T> singleMBeanObject = new SingleMBeanObject<T>(name, mbean, asInterface, mBeanServer); singleMBeanObject.register(); } catch (Exception e) { log.warn("Error registering mbean", e); } } }
From source file:org.chromium.sdk.internal.protocolparser.dynamicimpl.TypeHandler.java
@SuppressWarnings("unchecked") private T createProxy(InvocationHandler invocationHandler) { if (proxyClassConstructor == null) { Class<?>[] interfaces = new Class<?>[] { typeClass }; Class<?> proxyClass = Proxy.getProxyClass(typeClass.getClassLoader(), interfaces); Constructor<?> c;//w w w .ja va 2 s . c o m try { c = proxyClass.getConstructor(InvocationHandler.class); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } proxyClassConstructor = (Constructor<? extends T>) c; } try { return proxyClassConstructor.newInstance(invocationHandler); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } }
From source file:com.jeeframework.util.classes.ClassUtils.java
/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @see java.lang.reflect.Proxy#getProxyClass *//* ww w . ja v a 2s . co m*/ public static Class createCompositeInterface(Class[] interfaces, ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); }
From source file:com.dianping.resource.io.util.ClassUtils.java
/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @see java.lang.reflect.Proxy#getProxyClass *///from w w w. j a v a 2 s.co m public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); }
From source file:com.freetmp.common.util.ClassUtils.java
public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) { Assert.notEmpty(interfaces, "Interfaces must not be empty"); Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); }
From source file:org.crazydog.util.spring.ClassUtils.java
/** * Create a composite interface Class for the given interfaces, * implementing the given interfaces in one single Class. * <p>This implementation builds a JDK proxy class for the given interfaces. * @param interfaces the interfaces to merge * @param classLoader the ClassLoader to create the composite Class in * @return the merged interface as Class * @see Proxy#getProxyClass/*from w w w. j ava 2 s . c o m*/ */ public static Class<?> createCompositeInterface(Class<?>[] interfaces, ClassLoader classLoader) { org.springframework.util.Assert.notEmpty(interfaces, "Interfaces must not be empty"); org.springframework.util.Assert.notNull(classLoader, "ClassLoader must not be null"); return Proxy.getProxyClass(classLoader, interfaces); }