aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Use dynamic proxy (UB 1.1.2, RMI) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Use dynamic proxy (UB 1.1.2, RMI)" Watch "Use dynamic proxy (UB 1.1.2, RMI)" New topic
Author

Use dynamic proxy (UB 1.1.2, RMI)

Alecsandru Cocarla
Ranch Hand

Joined: Feb 29, 2008
Posts: 158
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 ]

SCJP 1.4 100%
SCJD 99.5%
Iván Párraga
Ranch Hand

Joined: Dec 02, 2007
Posts: 54
Hi,

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.

Cheers,

Iv�n


Iván Párraga García
SCWCD 5, SCJD, SCJP 5, MySQL 5 DBA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Use dynamic proxy (UB 1.1.2, RMI)
 
Similar Threads
Exception stratigy in scjd???
Interface to Data
Comments on design please !!!
Stand alone criteria [B&S]
Implementaion of the interface provided by Sun to handle local and remote connections