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!