Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Specifying local and network "mode"

 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Currently I have implemented the following for specifying the "mode" the application should run in:

If the user wants to run the server in network mode they start the server and specify the database file location and port. When the client is started the user is prompted for host and port to start the client.

If the user only wants to run the application in local mode they do not need to start the server, only the client need to be started and specify the database location. If the server is started seperately from the client then the two programs will need some way of "contacting" each other. It seemed easier to just have the client instantiate all the objects of the database to get the functionality that a "server" would provide.

Am I on the right track with the above approaches??

Thanks!

James
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I seems good to me, I'm unsure about your last sentence.

Originally posted by James Clarke:
It seemed easier to just have the client instantiate all the objects of the database to get the functionality that a "server" would provide.


I don't know if you meant that literally or not. The fact that you said it was easier led me to think you might have implemented it twice.

I think both client "alone" mode and "server" should be using the same piece of code accessing the database. The main difference being that the client would not use the "network" path, but direct local access.

Can you elaborate ?

Regards,
Alex
 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

No I have not implemented it twice. What I meant was:

In network mode:
RoomSocketClient is called which then interacts with RoomDatabase remotely to insert/edit/delete data.

In Local mode:
The client directly interacts with a RoomDatabase object.

Are there alternate ways to implement this?

thanks,

James
 
Vinicius Florentino
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. I'm doing exacly like you. mode=server start the server. mode=alone starts the client using a localdatabase. if mode=empty start the client to connect with a started server.

I'm using RMI, and with 1 doubt: I need to do a server gui? If not, How can I unexport the object?
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by James Clarke:
Hi,

No I have not implemented it twice. What I meant was:

In network mode:
RoomSocketClient is called which then interacts with RoomDatabase remotely to insert/edit/delete data.

In Local mode:
The client directly interacts with a RoomDatabase object.

Are there alternate ways to implement this?

thanks,

James


OK, that sounds very good to me! Can you tell me why you choose sockets ? Just helping you prepare for your essay exam
 
Alex Belisle Turcot
Ranch Hand
Posts: 516
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Vinicius Florentino:
Hi. I'm doing exacly like you. mode=server start the server. mode=alone starts the client using a localdatabase. if mode=empty start the client to connect with a started server.

I'm using RMI, and with 1 doubt: I need to do a server gui? If not, How can I unexport the object?


I used a GUI myself and I chose not to handle crashes. But without a GUI, I think you are right, you need to handle it, since the only way to exit will be CTR-C/Terminate.

Search on the forum for "Shutdown hook":
http://www.coderanch.com/t/187216/java-developer-SCJD/certification/do-you-handle-Exit-network

As I didn't do that, I can't say much about it, but the idea is that you'll be able to execute some logic before the application exits.

bye,
Alex
 
James Clarke
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

The main reason that I used sockets was to understand socket level programing, RMI is an abstracton of sockets so i reasoned that if i can program in sockets RMI would be easy to learn.

thanks,
J.C
 
Vinicius Florentino
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi. Thank you Alex. I forgoted about the "Hook solution". I will use it in my code.
Now, when I start server: Opens a GUI with port and url to edit; alone: User choise database file; without argument: specifie server url and port.

And all that configuration is saved in suncertify.properties file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic