• 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 server

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Friso
I got it.
 
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
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
"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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic