• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Local Mode Considerations

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


... 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
 
Jordan Zaccardi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Aaaaaaaahhh! I interpreted it wrong.
You're a gentleman and a scholar
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys.
Mark
 
reply
    Bookmark Topic Watch Topic
  • New Topic