Comments
Richard Davies wrote: The UK has a good crop of technology pioneers in cloud computing - for example ElasticHosts, FlexiScale, Flexiant, OnApp - and also some strong government initiatives such as G-Cloud. We will have to see whether this kind of technical leadership converts into swift mass-market adoption or not.
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Java Technology for NFS: Using an Internet File Access Protocol
Java Technology for NFS: Using an Internet File Access Protocol

Do your Java applets and servlets need to read and write files stored on a server elsewhere in the network? If so, you need NFS, a fast file-access protocol that is destined to become a standard for file access over local area networks (LANS) and the Internet.

Much of your data may already be stored on NFS servers, and now you can use NFS technology to read or write remote files directly from your Java program.

Naming Files on a Network and Getting to Files with NFS
Let's start at the beginning. The NFS protocol has been used for network file access since the advent of LANs in the early 1980s. Although the protocol is normally associated with Unix clients and servers, there are implementations available for almost every computing platform.

The NFS protocol is normally built into the operating system on either the client or server side. This leads to solid performance and enables programs to get to remote file systems as if they were local.

To access files on a network server, you need to be able to name the files using a network filename that will identify the file and its server from any computer in the network. We are already familiar with network names in the form of a URL. The URL Connection classes provide URL naming to identify Web pages.

You don't have to rewrite or recompile programs to use NFS, plus NFS files are commonly named through an automounter service that creates network names such as "/net/servername/dir/file." There is also an NFS URL, "nfs://servername/path."

Getting to NFS from Java
The Java JDK provides good support for Java as a network programming language. It's easy to connect to an HTTP server via the URL Connection to read Web pages or use the JDBC classes to access database servers. RMI provides a wonderful framework for network communication between Java objects.

However, the java.io classes provide no support for URL-style naming, for example, to read a file using a FileInputStream:

InputStream in = new FileInputStream("D:\DATA\FILE");

The path name for the file must use the syntax for the underlying operating system. The OS may provide its own form of remote file access via CIFS or NFS protocols, but there is no consistent naming model that a user or programmer can rely upon. For example, the file "D:\DATA\FILE" may indeed be a remotefile since the "D" disk may be assigned to an NFS mount, but there is no reliable way to name files on other network servers as we can do with URLs and Web pages:

InputStream in = new URLConnection("http://server/page").getInputStream();

Furthermore, the JDK provides no support for remote file access. When you write a Java program that reads or writes a file, you will use the classes in java.io. With these classes you can read and write files either sequentially or randomly. You can also list directories and create, delete and rename files. The java.io classes work well until you need access to files across the network - java.io provides no support for network file access.

The NFS team at Sun Microsystems created a set of classes that enhance thej ava.io classes to allow URL naming. The XFile classes are almost identical to the java.io classes. They take the same arguments, return the same results and throw the same exceptions. Only the class names are different: an "X" is prepended to each class name. In addition to taking the same "native" file names asjava.io, the XFile classes will handle URL names. For instance, to test if a file exists:

XFile xf = new XFile("nfs://server/a/b/c.txt");
if (xf.exists())
System.out.println("file exists");

Listing 1 demonstrates a simple program that uses the XFile classes to copy afile. It's identical to a java.io equivalent except for the "X" in front of the class name. The XFile classes provide this file copy program with a unique capability: rather than copy a file from one place to another on a local disk, the source and destination files can be named with URLs. For instance:

java xcopy nfs://server/a/b/c /tmp/x,

will copy a file from a remote NFS server to local storage, and

java xcopy nfs://server1/a/b/c nfs://server2/a/b/c

will copy a file from one NFS server to another. The XFile classes support an XFile Accessor interface that allows handlers to be written for any URL type. The NFS classes are just one type of handler for URLs that have the scheme name, "nfs:". Handlers can be written for other protocols, such as HTTP, FTP or CIFS. Handlers can also support other file system types. For instance, a "zip:" URL handler could be written that provides access to files within a zip archive.

Listing 2 is an example of an HTTP handler that implements the XFile Accessor interface for XFile handlers. This handler provides access to Web pages as if they were files. Due to the limitations of the HTTP protocol, the handler cannot provide directory listings or random access to files. HTTP servers don't normally allow clients to create files or directories without the assistance of a customized CGI script.

Listing 3 is an enhanced copy program that will copy an entire tree of files from source to destination. Since the program needs to list directories, it can be used with local files and NFS, but not HTTP or FTP.

Getting Java NFS
You can download a zip file containing the XFile package and a handler for NFSURLs from www.sun.com/webnfs. The download contains documentation, javadocs for the classes and the classes themselves. The NFS handler needs only 70 KB of bytecode, yet it implements a capable NFS client. The classes achieve good read and write performance through the use of Java threads to implement read-ahead and write-behind techniques. In addition, the handler caches file attributes, directory listings and file data. This NFS client will interoperate with many different NFS server configurations: TCP or UDP connection, NFSversions 2.0 or 3.0 and the use of fast WebNFS connection or the MOUNTprotocol.

The XFile classes provide equivalent java.io access to a variety of file system types using URL naming. The bundled NFS handler provides convenient, run-anywhere access to files on your NFS servers, which are already widely deployed on TCP/IP intranets.

The NFS protocol is destined to become a standard for file access on the Internet. The WebNFS extensions to the NFS protocol have already made Internet NFSservers accessible from Web browsers and through corporate firewalls (see www.sun.com/webnfs).

About Brent Callaghan
Brent has been with Sun for 12 years in the Solaris NetworkingTechnology Group working mostly on NFS. He participated in the development of theNFS version 3.0 protocol and the design andimplementation of the Java NFS classes. He's currently co-chair of the NFS version 4.0 working group in the IETF.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

i came to some understanding after reading this.thanks


Your Feedback
pradeep wrote: i came to some understanding after reading this.thanks
Enterprise Open Source Magazine Latest Stories . . .
With Cloud Expo 2012 New York (10th Cloud Expo) just four months away, what better time to start introducing you in greater detail to the distinguished individuals in our incredible Speaker Faculty for the technical and strategy sessions at the conference... We have technical and st...
AMD said late Tuesday that its chief sales officer Emilio Ghilardi had left the company and that CEO and president Rory Read is going to do his job while a replacement is sought. AMD didn’t say why Ghilardi left but it’s assumed Read wants his own people. Read is relatively new to th...
During the lifespan of M3 (Monitis Monitor Manager) there has always been something lacking – timers. M3 execution procedure was outlined in this previous article. The execution mentioned in the latter was a one-time-execution, whereas server monitoring requires periodic invocati...
Red Hat is putting its bought-in Gluster scale-out NAS storage technology, acquired in October, on the Amazon cloud. It’s styled Red Hat Virtual Storage Appliance for Amazon Web Services and other clouds are supposed to follow in short order.
A new episode of the screencast series is now available at the OpenNebula YouTube Channel. This screencast demonstrates the new easily-customizable self-service portal for cloud consumers. Its aim is to offer a simplified access to shared infrastructure for non-IT end users. The scree...
C12G Labs has just announced an update release of OpenNebulaPro, the enterprise edition of the OpenNebula Toolkit. OpenNebula 3.2, released two weeks ago, brings important benefits to cloud providers with a new easily-customizable self-service portal for cloud consumers, and builders w...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE