In your case, since the connection object has an instance of Data
what you get is a copy of Data and not the reference
Whenever you need a reference to the shared Data instance in the connection object, you call a synchronized method in a Factory class to return you the shared Data instance.
Why your connection object has to know about the connection factory instance?
* you cannot hold anything as a member, that you do not want to serialize
* and pass over the wire. therefore, i use this private method within
* each of my public methods to get a handle to the shared database.
private DataAccess getSharedDatabase() throws DataAccessException
String operatingMode = "S";
String databaseFileName = "db.db";
DataAccessFactory factory = DataAccessFactory.getFactory();
i think now that my connection extends the unicastremoteobject, and is therefore being properly recoginsed and treated as a remote object, i can pass the shared data object to the connection objects constructor's ?
You can pass the shared Data instance to the Connection object constructor. But remember, that your Data instance has to be Serialized and RMI has to marshal the Data instance as well to the client which I think is unnecessay. During the marshaling only the copy of Data is transfered to the client. The real instance of Data resides on the server.
marshalling in rmi uses regular serialization to a great extent, but there is one exception, namely how remote objects are handled.
For example, if a method parameter or result value of a method invocation in RMI is a remote object, that is, it implements a remote interface and is exported by the RMI implementation, you would not want it to be serialized.
What you really want to do is send the stub instead of the remote object, which can be used at the otherend to call methods on your remote object.
Coming to your question, your connection object lives only in the server which holds an instance of the Data. This Data instance is neither a copy nor _Stub but the real reference. When you invoke a method on the remote connectino object (actually the _Stub), it communicates with the server and makes the call on the remote object running on ther server. In that case, the Data instance residing in the server is used and not the local Data instance.