Using AOP to implement dynamic proxies

  • Thread starter Michael N. Christoff
  • Start date
M

Michael N. Christoff

First, a definition of dynamic proxies:

A dynamic proxy class is a class that implements a list of interfaces
specified at runtime such that a method invocation through one of the
interfaces on an instance of the class will be encoded and dispatched to
another object through a uniform interface. Thus, a dynamic proxy class can
be used to create a type-safe proxy object for a list of interfaces without
requiring pre-generation of the proxy class, such as with compile-time
tools.

---

How would one use AOP (aspect oriented programming) to implement dynamic
proxies? The closest I have seen is by way of 'introductions', but don't
most frameworks require you to specify the interfaces you can implement in
an introduction at compile time? What if you wanted to implement an
interface loaded dynamically at runtime?

I'm more interested in how this is done theoretically, but specific
solutions (like a solution using jboss aop) would also be of help. I
presume AspectJ cannot do this at all since it uses a purely build-time
aspect weaver.



l8r, Mike N. Christoff
 
C

Chris Smith

Michael said:
First, a definition of dynamic proxies:

A dynamic proxy class is a class that implements a list of interfaces
specified at runtime such that a method invocation through one of the
interfaces on an instance of the class will be encoded and dispatched to
another object through a uniform interface. Thus, a dynamic proxy class can
be used to create a type-safe proxy object for a list of interfaces without
requiring pre-generation of the proxy class, such as with compile-time
tools.

I've never gotten into the aspect stuff myself, so I can't answer your
immediate question. However, you do realize that this is already
available in the core Java API in the class java.lang.reflect.Proxy,
right?

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
M

Michael N. Christoff

Chris Smith said:
I've never gotten into the aspect stuff myself, so I can't answer your
immediate question. However, you do realize that this is already
available in the core Java API in the class java.lang.reflect.Proxy,
right?

Yes I am. In fact I use JDK dynamic proxies extensively in the software I'm
developing. Aspects are cool, but most runtime AOP frameworks require
control of the system classloader, which you don't have if your code is
running in an application server and you want portable code.

But thanks for pointing that out, as I'm sure you're not the only one who
has thought that.



l8r, Mike N. Christoff
 
D

Deepak Nayal

Hi Michael

If I am correct in understanding your problem, then the "around" advice
will help you out. You can check out the AspectJ Programming Guide for
more info on it.

Hope this helps.
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top