• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Dynamic Proxy... Examples?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reading through the description of what a Dynamic Proxy is, i'm still having trouble wrapping my brain around where this would be useful.
Does anyone have a simple yet applicable example of a Dynamic Proxy? I've seen all of the foo/bar examples I can stomach. I'm just looking for how this is used in the "real world".
Thanks in advance....
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is somewhat simplified example from the project I am currently working on:
Let's suppose we have an rmi handle on an object. As the communication channel is a little bit brittle, every method call on that object might fail. Based on the circumstances, we can retry the call, though. The retrying should be handled by a proxy.
There are several possibilities to code this proxy:
- Duplicate the error handling logic in every method. I hope we all agree that this is a bad idea.
- Extract the error handling into its own method and pass it a Strategy calling the correct method. That is actually how we did it until yesterday. Drawback is that you still have to touch the proxy every time the interface changes.
- Use a dynamic proxy. The InvocationHandler contains the error handling and uses reflection to call the method on the original object:

Did that help?
[ October 02, 2003: Message edited by: Ilja Preuss ]
 
Brian Kapellusch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Between your example and a couple of other articles i've read, I now have a pretty good idea of where and why it's useful.
Thanks much!
 
Hey, check out my mega multi devastator cannon. It's wicked. It makes this tiny ad look weak:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic