• 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

ClassCast Exception with RMI

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still grappling with sorting out RMI and my lock/unlock. I hope that someone can point me in the right direction. I have seen plenty of posts from people who have had this problem but mine seems ever so slightly different.
I am implementing the RMI factory pattern.
I have two classes server side - RemoteData and RemoteDataFactory both of which extends UnicastRemoteObject and implement interfaces RemoteDataInterface and RemoteDataFactoryInterface respectively - both interfaces extends Remote.
So far so good.
I firstly start my server (the RemoteDataFactory ) which creates itself, starts the registry and registers itself thus
RemoteDataFactory rdf = new RemoteDataFactory();
LocateRegistry.createRegistry(1099);
Naming.rebind("RemoteDataFactory", rdf);
Later my client gets the factory object from the registry and calls it's getdata() method which returns a RemoteData object thus
Registry registry = LocateRegistry.getRegistry(1099);
RemoteDataFactoryInterface rdfi = (RemoteDataFactoryInterface)registry.lookup("RemoteDataFactory");
RemoteDataInterface data = (RemoteDataInterface)rdfi.getRemoteData();
but this last line always gives me a ClassCastException thus
Exception occurred during event dispatching:
java.lang.ClassCastException: suncertify.server.RemoteData_Stub etc
Even if I try and cast the result of my getRemoteData method to a plain old Object I still get the same error.
(I have copied my stubs to both the server and the client package and this doesn't seem to help)
I feel sure that this is all to do with the way I am using the rmiregistry but can't seem to quite get the combination correct.
Please can somebody help - I hope that I haven't made my explanation too confusing!
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


RemoteDataInterface data = (RemoteDataInterface)rdfi.getRemoteData();
but this last line always gives me a ClassCastException thus
Exception occurred during event dispatching:
java.lang.ClassCastException: suncertify.server.RemoteData_Stub etc


How does your getRemoteData() method look like?
 
Jo Fail
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It looks like this -
public RemoteData getRemoteData() throws RemoteException, IOException{
try{remoteData = new RemoteData(FILE_NAME);
}
catch(IOException ioe){
System.out.println("Unable to open specified file, please check path name and try again");
throw ioe;
}
return remoteData;
}
where variables are defined as
private RemoteData remoteData;
private static String FILE_NAME;
[ April 22, 2003: Message edited by: Jo Fail ]
 
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is because what you bind at server side don't conform with RemoteDataFactoryInterface:
 
Jo Fail
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm sorry I'm not quite sure what you mean Damu - could you elaborate?
 
Jo Fail
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have finally sorted it! I'm very happy. I'm not sure if it's what you meant Damu but thanks for your help.
I found an old posting. ClassCastException with RMI 3rd March 2002 by Derek Drever. Now I know why Eugene asked me what my getRemoteData() method looked like.
Basically my getRemoteData() method needed to return a RemoteDataInterface rather than it's implementation RemoteData.
All these interfaces and implementations don't half confuse me!!!
 
if you think brussel sprouts are yummy, you should try any other food. And this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic