• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

local server

 
Carol Tsao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After I read the requirement, I found the startup got two mode: remote and local. If it is in local mode, do I need to implement a local server? Because it sounds strange to me.
Thank you
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Carol,
there are a number of ways to tackle this task.
First of all: the instructions say "no sockets must be opened" - that means, you don't have any server at all (not even a local one).
There issue of opening sockets or not is regularly discussed in this forum.
 
Carol Tsao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I chose to use RMI. If it is local model, do I need to run the RMI registry in localhost? If I don't use RMI for local model, it is meaningless to use a server. Is my understanding right?
 
friso dejonge
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I chose to use RMI. If it is local model, do I need to run the RMI registry in localhost? If I don't use RMI for local model, it is meaningless to use a server. Is my understanding right?

True, you only need the server if you are working in server mode.
If you use local mode, just call the data, datainfo and fieldinfo classes directly. It is true that in that case you need two databases and they are getting out of synch (one for local and one for remote), but that is the nature of the implementation. The requirement only asks to implement both so they can see you problem solving ability. (and to see use of design patterns)
In your case, for this problem, take a look at the factory pattern. One interface and two classes implementing this interface. One of the classes calls remote data methods via the server.
The other class calls local data class.
Since both of the classes implement the interface you can always call either of them through the interface methods. Please read the factory design pattern in a good book or search for it on this site.
hope this helps,
friso
 
Carol Tsao
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Friso
I got it.
 
Andrea Gazzarini
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Carol,
The instructions.html says : "The client and the server run in the same JVM"... It means there isn't a server (no networking, no "localhost", no server), but only a local database. The entire application run by typing one "java MyAppClient" command.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Gazzax"-
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
This is your second notice.
 
Mag Hoehme
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Carol Tsao:
I chose to use RMI. If it is local model, do I need to run the RMI registry in localhost? If I don't use RMI for local model, it is meaningless to use a server. Is my understanding right?


So in local mode you have to cirumvent RMI somehow.
I try to do this by not having my server extending UnicastRemoteObject, but doing the exporting explicitly (in remote mode only). In local mode I'm creating the object with a new operator.
 
Thomas Fly
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To implement RMI, you must have an interface that extends java.rmi.Remote (e.g., remoteDatabase), and then you must implement that interface (remoteDatabaseImpl).
All remoteDatabaseImpl has to do (at least if you're not yet worried about locking) is pass on the calls to Data; in other words, it follows the Adapter design pattern.
It may not be the best approach ultimately, but for the moment, I have an "Object db" that's either of type Data or type remoteDatabaseImpl, depending upon what mode is being used (I've made it dynamically switchable, using radioButtonMenuItem's, and have the RMI server running on a laptop on my LAN, just for fun).
Either way, db.criteriaFind searches the database.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic