This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes Java remote paths Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java remote paths" Watch "Java remote paths" New topic
Author

Java remote paths

Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
Hi to all, this is the background:
In my program I have to monitor a directory for changes and then propagate these changes on remote machines. I refer to every file on the local Server using a Path object.

this is the question:
when I want to refer to a remote Path should I use a simple String object or a Path?
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
I am thinking this is going to depend some on how you are accessing these remote machines and how much effort you want to make maintaining what machines are to be kept in sync. Are you able to directly access the remote machines with a file object from your program (i.e. is there some sort of network drive you operate via)?

How many machines are you working with (just one vs many/unknown number)? If many/unknown, you may want to be looking at an approach where the remote machines are "subscribing" to a file change notification and then you "publish" the files that change for them to read.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18712
    
    8

Marco Zanini wrote:this is the question:
when I want to refer to a remote Path should I use a simple String object or a Path?


You can't refer to a remote path using just a String. That is to say, you yourself can certainly look at the string and understand that it refers to a path on a computer somewhere, but if you want to actually access that path using Java code, you can't do that with just a String. You're going to need a File or a Path or some such object. So I don't see the point of this question.
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
I'm adding every machine manually specifying IP address and port number and estabilishing with them a ssh connection using JSch framework.

To propagate the changes, the object that watches the directories calls the server when a file changes and the server propagates the change to all the remote machines. Do you think this is a good approach? There will be around 30 remote machines or something like that.

When I send or cancel files using ssh I refer to the remote Path using a String, also because Jsch requires me this type of object. Also, I don't see the point to use a Path because I can't use it except from my local server.
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
I guess where you head depends in part on why you are doing this and what your goals are. You have provided a little more detail in your second post (indicating around 30 machines are involved). To me this sounds a little more like a business/real work application vs something you are doing for a class? I am not saying you should "slack off" on a class assignment, more that a real world solution needs to address a number of issues else you may end up with some headaches.

Some points to consider:
1) How often will you be adding/removing servers from the list?
2) How will you address failures (mainly thinking the remote server is off line when you try to push an update)?
3) How many files are you monitoring and what is the complexity (1 directory, many directories, etc)?
4) Is file update your only concern, or do you need to trigger other activities like a cache refresh (reload files); bounce web servers; etc?
5) What is the implication of partial updates/updates in progress - i.e. if 15 machines have a new file and 15 have the old, does this create problems?
6) Is there a certain amount of time you are required to have the updates pushed?
7) Are you considering "re-send" or "re-synch" options for when a machine is offline and does not get an update? (Could be from the perspective of synching all files or just re-sending the one that updated).


With 30 machines, I think you do want to look a little more into some sort of publish/subscribe concept. Not trying to push this approach (no pun intended), but publish subscribe approach allows the remote to manage getting it and can resolve some of the above issues but also adds a different angle of complexity.

If this is a real-world application, I'll also ask if it is an option to look at solutions that already exist which may do this for you.

Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
It seems have to explain more deeply what this application is about.
It's an application, running on the server, intended to execute many instances of another application (a commercial one) on some remote machines. All these machines must be kept updated with the commercial application running on the server. I wan to use ssh to transfer files and keep track of the machines that are added (their state, host and port).
Until now so I have these objects (related to this aspect):
-A server that keeps an array of M objects.
-A M object refers to a remote machine. It has methods to transfer files and execute programs on the remote machine.
-A watchDog Thread that watches the directory (containing many directories and files, let's say 1000) for changes using watchService provided in Java7. Every time a change occurs, this object calls the server for notifying the change.

For now let's consider file update my only concern. If a remote machine is not updated there are no problems but I should be aware of it. No time constraints.

Do you think that there should be an object or a Thread pool taking care of machine update? I'm thinking about that. So the server can remain active even if there's an update in progress.
Brian Burress
Ranch Hand

Joined: Jun 30, 2003
Posts: 122
More info about the problem always helps

Threading will add a level of complexity to your solution. While I would not advise intential coding of "unsafe" applications with respect to threading, you do need to decide whether you intend to run multiple threads so you can ensure the solution is designed to be thread safe.

With that said, I really can't tell you which one to do. Ask yourself what the advantages of working with multiple Threads for this solution. A big one I can think of is that you'd be able to have more than one push in process at a time (within resource limitations such as your local CPU and network). Is this needed for your solution?

If not and you think it never will be, stick with something simple.

If so, or if you'd like the challenge of a multi-Threaded application then go for it. If push comes to shove, make the threading configurable so you can always set it to a single Thread if needed in the short run.
Marco Zanini
Ranch Hand

Joined: Oct 31, 2011
Posts: 43
I need to build a multi-threaded application because I don't want it to block waiting for a file to transfer or something like that.
Some of the objects of my application are Runnable but Objects like the Server are a simple class.
 
jQuery in Action, 2nd edition
 
subject: Java remote paths