*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Accessing remote file? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Accessing remote file?" Watch "Accessing remote file?" New topic
Author

Accessing remote file?

Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
My implementation for now is:
java FlightServer [filename]
java FlightClient [-f filename] [hostname]
If the client starts without specifying hostname, it is considered local mode, and the database to be used is either the default one, or the one specified on starting the client, but the one in starting server (even if specified) is ignored.
If the client starts with hostname, it is considered remote mode, the filename specified in starting server, or default filename is the file to be used.
The client starts the GUI which accesses the database in initialization and in event handling (search, book).
So I have to read and write a file on a remote host in remote mode.
My question is: how to specify the file location in the GUI and thus implement the read or write function? Or is this approach wrong (or bad) at all? If so, any suggestions for alternative solution?
Thanks a lot!
Cathy
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Cathy,

So I have to read and write a file on a remote host in remote mode.

You don't have to read or write to a file in either mode, that's Data's job. Once Data is initialized, you should just make calls on an interface and Data will take care of persistence (reading and writing to the backing file).
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
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Originally posted by Michael Morris:
Hi Cathy,

You don't have to read or write to a file in either mode, that's Data's job. Once Data is initialized, you should just make calls on an interface and Data will take care of persistence (reading and writing to the backing file).
Michael Morris

What is the "backing file" you are talking about? Thanks!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Cathy,
That's the file that Data opens in it's constructor:

Hope this helps,
Michael Morris
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Originally posted by Michael Morris:
Hi Cathy,
That's the file that Data opens in it's constructor:

Isn't it the file we will be working on? How can we tell the constructor which file to open?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Cathy

How can we tell the constructor which file to open?

You pass it the path to the db file as a String like: "C:\databases\db.db" or "/databases/db/db" or (a platform independant version) System.getProperty("user.dir") + File.separator + "db.db".
Hope this helps,
Michael Morris
parthiban subramaniam
Ranch Hand

Joined: May 15, 2002
Posts: 116
Hi
well we will assume that you start your server like this
"java FlightServer [filename]"
now you have the file name .. this is the file the administrator of fbn wants to use for this service .. you can pass this file to the Data class constructor ..
if he has passed none .. like you said use the default file

now the client when the mode is rmi
java FlightClient [hostname] [portnumber]
well he is connected to the server now and the server knows which file it has to use ..
when it is local mode
java FlightClient [fileName]
you can pass this to the constructor of data and if he has not provided anything,pass the default filename.
hope this helps,
cheers,
parthi.


Even crazy and silly looking problems are sometimes real.
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Originally posted by parthiban subramaniam:
Hi
well we will assume that you start your server like this
"java FlightServer [filename]"
now you have the file name .. this is the file the administrator of fbn wants to use for this service .. you can pass this file to the Data class constructor ..
if he has passed none .. like you said use the default file

Thanks, Michael and Parthiban!
I understand what you mean and I am following this approach, in fact. But how the data object (constructed based on the filename in server) is passed to the GUI in remote mode? The client does not care which data to use in remote mode, but it is the client that starts the GUI. I think the GUI needs to know which data to use to handle the events. Am I lost somewhere?
Thanks a lot for all your help!
Cathy
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Cathy,

But how the data object (constructed based on the filename in server) is passed to the GUI in remote mode?

That's where your network approach comes in. If you are using RMI then you will need to create an interface that extends Remote and exposes all the public methods of Data. You will then need to provide a class the implements that interface and extends UnicastRemoteObject or Activatable. It is thru that class's remote stub that you will access the Data object on the server.
Now if you're using Sockets, you'll have to develop a communication protocol for client and server to communicate using serializable objects.

The client does not care which data to use in remote mode, but it is the client that starts the GUI. I think the GUI needs to know which data to use to handle the events.

The server should already be running in order for the client to connect. For this assignment there need only be one Data object, using the provided db.db file, on the server. Therefore the client only needs to know the server and port and in the case of RMI the name of the service that is bound to the RMI registry on the server host.
Hope this clears it up,
Michael Morris
Cathy Young
Ranch Hand

Joined: Mar 02, 2002
Posts: 126
Thanks a lot, Michael! I feel clearer, but still have a couple of questions if you do not mind.
Originally posted by Michael Morris:
That's where your network approach comes in.

Is this the only place network comes in?

If you are using RMI then you will need to create an interface that extends Remote and exposes all the public methods of Data. You will then need to provide a class the implements that interface and extends UnicastRemoteObject or Activatable. It is thru that class's remote stub that you will access the Data object on the server.

Yes, I am using RMI. What is the relationship between this class which implements the interface and the provided Data.java class?
Thanks!
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Hi Cathy,

Is this the only place network comes in?

Yes. Since you are using RMI, you will connect to the remote server and receive a stub of the Remote object on which to make calls.

What is the relationship between this class which implements the interface and the provided Data.java class?

Well that depends on how you design it. In my case the Remote object was a composite that held a reference to a Data object. So when I made a call like data.modify() on the client, then the Remote object in turn called db.modify() on its Data reference.
Hope this helps,
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing remote file?
 
Similar Threads
server/alone command line
URLy Bird: database location
B&S: Command Line
The mode flag
Platform Independent Command Line