Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Use dynamic proxy (UB 1.1.2, RMI)

Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was thinking (in fact I kind of already implemented it) about using a proxy (java.lang.reflect.Proxy) for the remote invocations.
This will work as a kind of adapter, which will hide all RemoteExceptions and make the Remote interface look exactly like the Local one.

My DB interface does not throw IOException, so my remote interface cannot extend the local interface (I have a services layer which looks kind of similar to an EJB, that's why I'm talking about remote and local).

The idea is - if the client is running in standalone mode, it will use the local implementation. If it runs in remote mode, it will use this proxy that, through a custom InvocationHandler, will sort out any RemoteExceptions and make my remote object look as if it implemented the local interface.

My only problem is, what to do with RemoteExceptions which have a null cause (if there are any). If there's a cause, I throw it from the proxy's method invocation. If it has no cause - I throw a runtime exception (for now).
Do you have a better idea, what to do with them?
Or maybe it is impossible to get a RemoteException with null cause?

What do you think about this approach?
Are we allowed to use the java.lang.reflect.Proxy (I did not see it being banned in the instructions...)?
[ November 08, 2008: Message edited by: Alecsandru Cocarla ]
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My design was very similar to yours and I passed with maximum grade in all the sections (except GUI design). I did not use the proxy class but I constructed my own implementation to build this adapter. The adapter caught the RemoteExceptions and wrapped them into a not checked exception build by me which were launched if it had sense. This way the adapter could implement the same interface than the local implementation but the "remote" exceptions were not lost. I documented this solution in detail and the Sun examiners seemed to be happy about it.


Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Devious Experiments for a Truly Passive Greenhouse!
    Bookmark Topic Watch Topic
  • New Topic