This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I have read numerous previous posts concerning design strategies for local/remote mode. My design utilizes a connection Factory acting as the server and binded to the registry. Additionally, I have a singleton (yes, I know, singleton is over used, oh well) LockManager. Functionally, the remote client looks up the registry and obtains a remote reference to DataAccess, my extension to Data. The local client just creates a new DataAccess object. The problem rears its ugly head when the local client tries to lock(-1) and I realize (stupidly) that it isn't obtaining the same DataAccess object that the connection Factory is providing the remote client. Therefore, the local lock is not synchronizing with the remote lock. So my question is: How do I obtain the DataAccess object for the local client so it speaks with the same objects the remote does? I have read many posts, one of which says a local RMI lookup to the server will open ports, which it will. So, the local should not be dependent upon the server, but I don't see any other way to force local and remote to utilize the same objects and play nicely together. Any suggestions?
Real simple. In local mode there is no ports, and no RMI, it is a one to one relationship between the client and the data. Therefore you also do not need to implement any locking in local mode. SO that solves your problem because you don't have to implement it in local mode. Mark
... but I don't see any other way to force local and remote to utilize the same objects and play nicely together.
They don't have to be the same object or even the same class. They both just have to implement DataAccess. Like Mark says, your local implementation should not even implement locking. lock() and unlock() can just be empty methods on the local object. Hope this helps, Michael Morris
Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
Jordan Zaccardi
Greenhorn
Joined: Sep 03, 2002
Posts: 3
posted
0
Just for clarity... Does this mean that the local and remote client won't be running at the same time? I'm failing to see when a local client won't muck up the database when multiple remote clients are locking, reading, writing, unlocking. Thanks for your replies. I greatly appreciate it.
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Hi Jordan,
Does this mean that the local and remote client won't be running at the same time?
That's it! That's why the instructions say that no sockets should be opened when connected to a local file. Hope this helps, Michael Morris
Jordan Zaccardi
Greenhorn
Joined: Sep 03, 2002
Posts: 3
posted
0
Aaaaaaaahhh! I interpreted it wrong. You're a gentleman and a scholar
Padmaja Prasad
Ranch Hand
Joined: Nov 14, 2001
Posts: 76
posted
0
Hi Michael, Suppose the local client is asking for a local connection and if there are remote clients running at the same time, can you please tell me which of the following approaches is the best?? 1. popup a dialogue box with a message to the local client to try after some time or run in remote mode?? 2. Wait untill all remote connections close And..how can we find out there are remote clients running??? Thanks Padmaja
Nate Johnson
Ranch Hand
Joined: May 13, 2002
Posts: 301
posted
0
Originally posted by Padmaja P:
Suppose the local client is asking for a local connection and if there are remote clients running at the same time, can you please tell me which of the following approaches is the best?? 1. popup a dialogue box with a message to the local client to try after some time or run in remote mode??
Just give them the connection. It sounds like you are thinking in test-mode where you are using the same db to run local and remote tests for your assignment. For local mode there will be a local db that is only for that client. In remote mode, the db will most likely be on a different computer all together.
Originally posted by Padmaja P:
2. Wait untill all remote connections close And..how can we find out there are remote clients running???
A client will not be able to know how many remote clients are running... if you want your server to know that, you will probably have to keep a count running in the server... then decrement that count on unreferenced and close calls. I would not worry about this too much.
Suppose the local client is asking for a local connection and if there are remote clients running at the same time, can you please tell me which of the following approaches is the best??
Oh, i not michael sorry, but this explanation may help. The way I implemented / interpreted this is: You will have two applications, one server and one client. The client must be able to run if the server is not up. This means local mode The client application will connect to the local database. When the server application is started, server is up then the client application must be able to connect to it with either sockets or rmi. The way to do it is to have an interface on the client which has all functions of data. Then have a localconnection class and a remoteconnection class both implementing the interface. The local connection just calls the local copy of data/datainfo and fieldinfo. The remote connection creates the connection by sockets or rmi to the server. Now the trick is to instantiate a the right connection (localconnection or remoteconenction) when requested. This is called a factory, read a design patterns book for that. This factory returns a remote or local conenction object which can be parsed to the interface on which you can call all methods of the data class as you can see, simple and still easy. As for your other questions 1) ?? 2) The system is designed as a client server. So it is possible that multiple clients are connected to the same server. If one client application disconnects and connects to the local database, there is no problem. The server is still up and the other connected clients can still work. Yes, you do have two different databases in this scenario and they are obviously not synchronized. The point why we are doing this assignment is just to show you can do it, not that it is a real life application. 3 How can we find out there are remote clients running? After reading the above, this question does not need to be answered. Or should i say, i dont know, (but i thought it is not possible in a simple application) regards, friso
swimming certificate (A & B), shoelaces diploma, and some useless java ones.
Michael Morris
Ranch Hand
Joined: Jan 30, 2002
Posts: 3451
posted
0
Hi Padmaja,
Suppose the local client is asking for a local connection and if there are remote clients running at the same time ...
The question is, if you're in local mode why do you care what clients might be connected to some server? In local mode there isn't a server involved. Your connection to the database in local mode is thru a file on the local system. Should you be concerned that a server on the same machine as your locally connected client has opened the same db file? What are you going to do if this does happen? The answer to those questions is no to the first and what can you possibly do to the second. If that scenario does happen you should get a plethora of IOExceptions when both try to write the RandomAccessFile in Data. Hope this helps, Michael Morris
"Padmaja P"- Welcome to the JavaRanch! Please adjust your displayed name to meet the JavaRanch Naming Policy. You can change it here. Thanks! and welcome to the JavaRanch! Mark
"f Dejonge" You can also follow the above link to change your name. I know I have asked you before, so could you please give us your full first name. Thanks Mark
Padmaja Prasad
Ranch Hand
Joined: Nov 14, 2001
Posts: 76
posted
0
Thanks a lot guys.. I confused myself thinking that the local & remote clients will share the same db. (I am only a beginner) Thank you once again for clearing my doubt. Mark, Sorry for the dispaly name..I thought that I could use a non-empty last name which may be an initial. The instructions also does not clearly state that we should not use single letters. Thanks Padmaja
friso dejonge
Ranch Hand
Joined: Jul 11, 2002
Posts: 162
posted
0
sorry mark, i have not seen your message of changing my name before. But to be honest, i have been waiting for it for some time anyway, consider it done