Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RemoteStub class and ClassCastException

 
Aruna Raghavan
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am having a small problem and I think I know why. I need someone to verify this.
I originally coded my LockManager to use a Connection object reference as clientId. My Connection object extends a UnicastRemoteObject class. Its stub extends a RemoteStub class.
On the client side, I tried to access the connection after looking up my ConnectionFactoryImpl by just doing a
connectionFactoryImpl.getConnection(). This resulted in a ClassCastException. I think it's because the Connection and Stub extend differnet Remote classes as stated above. I did not use a ConnectionInterface as it seemed unnecessary. Connection implements RemoteDataInterface which inturn extends DataInterface (as Peter suggested in one of his recent answers). As long as I access the Connection itself as DataInterface on the client side, every thing works cool.
I also had to put the getLockManager() method on my ConnectionFactoryImpl because my client no longer knows the Connection, it only knows it as a DataInterface. LockManager now takes DataInterface as clientID (under the covers it is still Connection, client just does not know it as such.)
Please let me know if you aee any problems with this. Thanks,
Aruna.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you trying to cast the stub to Connection? That will throw a ClassCastException alright. The stub implements your interface, but is rooted off a completely different class.
- Peter
 
Aruna Raghavan
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peter,
Yes, that was precisely what I was doing.
Aruna.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic