public final class ConcurrentProxy extends Object
java.lang.reflect.Proxy provides static methods for creating dynamic proxy
classes and instances, and it is also the superclass of all
dynamic proxy classes created by those methods.
This class provides faster concurrent caching of Proxies through ConcurrentHashMaps,
It delegates back to java.lang.reflect.Proxy for
the construction of new Proxies and the required synchronisation surrounding it.Proxy| Modifier and Type | Method and Description |
|---|---|
static Class<?> |
getProxyClass(ClassLoader loader,
Class<?>... interfaces)
Returns the
java.lang.Class object for a proxy class
given a class loader and an array of interfaces. |
static Object |
newProxyInstance(ClassLoader loader,
Class<?>[] interfaces,
InvocationHandler h)
Returns an instance of a proxy class for the specified interfaces
that dispatches method invocations to the specified invocation
handler.
|
public static Class<?> getProxyClass(ClassLoader loader, Class<?>... interfaces) throws IllegalArgumentException
java.lang.Class object for a proxy class
given a class loader and an array of interfaces. The proxy class
will be defined by the specified class loader and will implement
all of the supplied interfaces. If a proxy class for the same
permutation of interfaces has already been defined by the class
loader, then the existing proxy class will be returned; otherwise,
a proxy class for those interfaces will be generated dynamically
and defined by the class loader.
There are several restrictions on the parameters that may be
passed to Proxy.getProxyClass:
Class objects in the
interfaces array must represent interfaces, not
classes or primitive types.
interfaces array may
refer to identical Class objects.
cl and every interface i, the following
expression must be true:
Class.forName(i.getName(), false, cl) == i
interfaces array must not
exceed 65535.
If any of these restrictions are violated,
Proxy.getProxyClass will throw an
IllegalArgumentException. If the interfaces
array argument or any of its elements are null, a
NullPointerException will be thrown.
Note that the order of the specified proxy interfaces is significant: two requests for a proxy class with the same combination of interfaces but in a different order will result in two distinct proxy classes.
loader - the class loader to define the proxy classinterfaces - the list of interfaces for the proxy class
to implementIllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedNullPointerException - if the interfaces array
argument or any of its elements are nullpublic static Object newProxyInstance(ClassLoader loader, Class<?>[] interfaces, InvocationHandler h) throws IllegalArgumentException
Proxy.getProxyClass(loader, interfaces).
getConstructor(new Class[] { InvocationHandler.class }).
newInstance(new Object[] { handler });
Proxy.newProxyInstance throws
IllegalArgumentException for the same reasons that
Proxy.getProxyClass does.
loader - the class loader to define the proxy classinterfaces - the list of interfaces for the proxy class
to implementh - the invocation handler to dispatch method invocations toIllegalArgumentException - if any of the restrictions on the
parameters that may be passed to getProxyClass
are violatedNullPointerException - if the interfaces array
argument or any of its elements are null, or
if the invocation handler, h, is
nullCopyright © 2011 FINN AS. All Rights Reserved.