Fabienne Boyer
Laboratoire LIG (INRIA-UJF-INPG)
http://sardes.imag.fr/~boyer
Java Dynamic Proxies!
Details for Javanaise project (M2PGI)"
2"© F. Boyer, UJF"JAVANAISE Project, UE Etude et projet d’intergiciels, M2PGI"
!
Adressed Issue"
■ Interception"
◆ Intercept the invocations to some objects"
◆ Add instructions before / after / in place of the invocation (test, debug, transaction
management)"
"
■ Approaches"
◆ Source code manipulation, at compiling time (or before)"
◆ Bytecode manipulation, at loading time (or before)"
◆ Object manipulation, at execution time"
"
! Dynamic Proxies allow to perform interception at execution time"
"
"
interface"
Object"Dynamic"
Proxy"
interface"
Invocation!
3"© F. Boyer, UJF"JAVANAISE Project, UE Etude et projet d’intergiciels, M2PGI"
!
Principles"
■ Proxies are instances of classes implementing some target objects interfaces"
◆ Classes generation performed through java.lang.reflect.Proxy.getProxyClass ()"
◆ Instances generation performed through
java.lang.reflect.Proxy.newProxyInstance()"
"
■ Proxies are in fact composed of two parts"
◆ An interceptor, called the DynamicProxy, in charge of intercepting the actual
invocations"
◆ An invocation handler, in charge of performing the actual invocations"
4"© F. Boyer, UJF"JAVANAISE Project, UE Etude et projet d’intergiciels, M2PGI"
!
Principles"
■ Create a dynamic proxy class + instance for a target object"
Proxy.newProxyInstance(classLoader, interface, invocationHdler)"
■ Perform invocations on the target object as usual"
■ Invocations are managed through an InvocationHandler"
"
"
IFoo"
Dynamic"
Proxy"
Invocation"
Handler"
Invocations on O"
O.method(..)"
Object O"
IFoo"
5"© F. Boyer, UJF"JAVANAISE Project, UE Etude et projet d’intergiciels, M2PGI"
Dynamic Proxy"
■ A dynamic proxy is associated to"
◆ A class loader"
◆ An interface"
◆ An invocation handler"
■ Create a dynamic proxy"
◆ Through the static method newProxyInstance"
"
InvocationHandler invocationHandler = new IFooInvocationHandler();
IFoo proxy = Proxy.newProxyInstance(
IFoo.class.getClassLoader(),
new Class[] {IFoo.class},
invocationHdler);
1 / 11 100%
La catégorie de ce document est-elle correcte?
Merci pour votre participation!

Faire une suggestion

Avez-vous trouvé des erreurs dans l'interface ou les textes ? Ou savez-vous comment améliorer l'interface utilisateur de StudyLib ? N'hésitez pas à envoyer vos suggestions. C'est très important pour nous!