So we pass a reference of the dataRemote to the locking class, which we then make a new weak reference, this is used to store the record number that is locked (this is the id)
The problem is that Alain's code uses the instance of DatabaseRMIImpl to identify who owns the lock, however there is only ever one instance of DatabaseRMIImpl. So although Alain doesn't go into details, he needs a connection Factory to create multiple instances of DatabaseRMIImpl. And both the DatabaseRMIImpl and the Factory would have to be Remote objects.
...but the course and book I have used dont have 2 remote objects
So at the end of all this, you will only have the DataRemote instance bound - the rebind will have replaced the AdapterConnector instance.
what I am trying to do is from the server call the AdapterConnection class
Naming.rebind("//:60000/DatabaseService", new AdapterConnection(db))
This then in the AdapterConnection do this
Registry registry = LocateRegistry.createRegistry(60000);
registry.rebind("DatabaseService", new DataRemote(databaseFileName));
Then we exit the server.
Which means you are trying to cast the DataRemote instance to an AdapterConnector instance.
hence the line (excuse the poor name for the look up)
AdapterConnection connection =(AdapterConnection) Naming.lookup("//:60000///:60000/DatabaseService");
then I return the DBMain interface type fro the dataRemote using the get
getMyServer() method in the AdapterConnection
but I am getting classCastExecptions (one of my favorite )
Hmmm. If you look at my code above, at line 10 of the ConnectionFactoryImpl I create a new instance of MyServer for every client who connects. You can verify this in the outputs of both the clients and server.
I suspect that this is where the problem may be. First I would like to confirm that each connected client does have it's own instance of MyServer (or UrlyBirdServer in your case).
You can have static objects for items such as your cache (your 2D array), your file descriptors, your collection of locks, and so on.
Originally posted by Lee Sunter:
Laura, hos does the data stay in sync with the rest of the other users, do we not need to have only 1 data class and so that when updates have been made then other users will see the changes, ie a booking.
Everyone is a villain in someone else's story. Especially this devious tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koophttps://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton