Interface ProxyService
-
- All Known Implementing Classes:
JavassistProxyService
,JdkProxyService
@Immutable public interface ProxyService
Method of producing proxies.There are multiple ways of creating proxy in Java, from simple
Proxy
, through support frameworks like javassist, to class generation libraries like cglib or bytebuddy. This class creates universal facade to potentially all these methods.Different frameworks supports different proxying features, for example, javassist can create proxy classes that extend specific non-final class, not only that implement specific interfaces. These features are represented by
ProxyService.Feature
and can be tested for support (usingsupportsAllFeatures(org.perfectable.introspection.proxy.ProxyService.Feature...)
orsupportsFeature(org.perfectable.introspection.proxy.ProxyService.Feature)
).Interface implementation can be registered to be used with
ServiceLoader
, and should be obtained usingINSTANCES
.This interface can be implemented externally, and registered with Service Loader to be usable in
ProxyBuilder
.- See Also:
ProxyBuilder
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
ProxyService.Container
Container that manages service-loaded instances ofProxyService
.static class
ProxyService.Feature
Features that service can support.static class
ProxyService.UnsupportedFeatureException
Thrown when factory cannot create a builder with requested features.
-
Field Summary
Fields Modifier and Type Field Description static ProxyService.Container
INSTANCES
Container managing all instances registered withServiceLoader
.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description <I> I
instantiate(ClassLoader classLoader, Class<?> baseClass, List<? extends Class<?>> interfaces, InvocationHandler<? super MethodInvocation<I>> handler)
Creates proxy instance.default boolean
supportsAllFeatures(ProxyService.Feature... features)
If the concrete service supports all of specified features.boolean
supportsFeature(ProxyService.Feature feature)
If the concrete service supports specified feature.
-
-
-
Field Detail
-
INSTANCES
static final ProxyService.Container INSTANCES
Container managing all instances registered withServiceLoader
.
-
-
Method Detail
-
supportsFeature
boolean supportsFeature(ProxyService.Feature feature)
If the concrete service supports specified feature.- Parameters:
feature
- feature to test- Returns:
- if service supports feature
-
supportsAllFeatures
default boolean supportsAllFeatures(ProxyService.Feature... features)
If the concrete service supports all of specified features.- Parameters:
features
- feature set to test- Returns:
- if service supports features
-
instantiate
<I> I instantiate(ClassLoader classLoader, Class<?> baseClass, List<? extends Class<?>> interfaces, InvocationHandler<? super MethodInvocation<I>> handler) throws ProxyService.UnsupportedFeatureException
Creates proxy instance.This method either creates new proxy class, or reuses one that matches. This proxy class extends
baseClass
and implementsinterfaces
, and is created inclassLoader
. After creating this class, its object is instantiated. The object will delegate every call that it receives to specifiedInvocationHandler
. The only exception isObject.finalize()
, which must be ignored.This method assumes that the arguments were correctly prepared:
baseClass
is not finalbaseClass
is actually a class (not an interface)baseClass
and each element ofinterfaces
has classloader exactlyclassLoader
- Each element in
interfaces
is an interface (not a class)
- Type Parameters:
I
- type of proxy- Parameters:
classLoader
- classloader used to create proxy classbaseClass
- proxy superclass, cannot be final, must be a classinterfaces
- additional interfaces that proxy class should implementhandler
- invocation handler to pass method execution for this proxy instance- Returns:
- proxy instance
- Throws:
ProxyService.UnsupportedFeatureException
- when this service cannot create proxy with requested parameters, because it doesn't support some feature required to do so
-
-