Hi - I am doing Boggit and Scrapper - quick question..the instructions say that the Data class must implement the DBAccess interface. However, the DBAccess interface does not extend ..rmi. I can use an adapter pattern...but then the Data class is not implementing DBAccess.
where the proxy is the thing your client application is calling methods on, with the proxy being responsible for forwarding those calls to the network enabled RemoteData instance you got back when opening the RMI connection.
Not ideal I admit. In an ideal world you'd have a single superinterface for both DB and RemoteDB but such is life.
Joined: Nov 25, 2004
Hi - thanks for yr help. However, can I ask for some clarification.
interface DBAccess (extends java.rmi.Remote, but this needs to be changed, as not allowed to alter this interface)
class Data (implements DBAccess, extends java.rmi.server.UnicastRemoteObject)
//server DBAcess dba = new DBAccess(); Data r = (Data)dba; r.loadData(); //create and bind registry LocateRegistry.createRegistry(port); Registry registry = LocateRegistry.getRegistry(port); registry.rebind("Data", r);
//client Data d = (Data)Naming.lookup("Data"); System.out.println("Running as client"); Gui g = new Gui (d); g.createAndShowGui(d);
The Gui constructor parameter is of type DBAccess.
I can remove all rmi from the DBAccess interface and Data class and create a new package suncertify.db.net to include the following:
But is that not (unnecessary) duplication of code?
I'm not quite sure about this proxy...
"the proxy is the thing your client application is calling methods on, with the proxy being responsible for forwarding those calls to the network enabled RemoteData instance you got back when opening the RMI connection."
I can have a DataProxy class that implements DB but not sure what should go in there...Or maybe I am confused about what should go in the RemoteData class..
Can you pse provide a little more info...
Jeroen T Wenting
Joined: Apr 21, 2006
The proxy is needed to allow the client to not have to know about IOExceptions when doing calls on a DB (and to allow the client to not have to know whether it's calling on a DB or RemoteDB).
It takes any IOExceptions (and thus RemoteExceptions) generated by the RemoteData and transforms them into a RuntimeException (which aren't declared in the throws clause), so it can implement DB instead of RemoteDB while doing network calls through a contained RemoteData.
And yes, there is some duplication of code. Because of the requirement that the DB interface can't be modified that's unavoidable if you want to present a uniform view of the data to the client irrespective of how that data is retrieved. Were you to be able to change the DB interface you could build a master interface which throws IOExceptions and inherit both DB and RemoteDB from that to respectively remove that IOException from the throws clause and change that IOException to a RemoteException. That's the pretty solution, and one you would likely choose if you didn't get that DB interface supplied to you, but that option isn't open so you have to resort to a less pretty solution that gets the job done.