• Post Reply Bookmark Topic Watch Topic
  • New Topic

toString and equals as remote methods...  RSS feed

 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys,

I have been doing some JUnit testing of my Remote Objects and have tried to compaire them with the toString() and equals() methods, these methods seem to apply to their stubs rather then the objects on the server.

Is there a way of getting a toString() call to the remote object to be that of the remote object and not it's stub?

Thanx for your help.

James.
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I realised that you cannot add a RemoteException to the toString and equals signatures.

Is there anyway of doing it?

I.e. create a custom isEquals() and toStringRepresentation() methods that are remote and they call the equals and toString methods locally.

is this the only way?

Thanx for your help.

James
 
James Turner
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know how it is possible to make a call to toString and equals and have them be from the Remote Object and not it's stub?

Any help is greatly appreciated.

Thanx..
James
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your custom remoteEquals() and remoteToString() methods are probably the best way. If you look at all the RMI documentation, you should find information explaining that these methods (well, equals and hashCode anyway) are carefully and deliberately implemented in the stub so that two stubs that refer to the same remote object are equal, and RMI itself probably depends on that behavior.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way I've usually done this before is make a class that wraps the stub and implements toString() and equals() by making whatever remote calls are needed.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!