File system access

This is achieved with a few more lines than the networking example:


import org.jtrix.facets1.node.ITrampolineFacet;
import org.jtrix.project.nodality.facet.INodeResourceFacet;
import org.jtrix.facets1.util.io.IFileSystem;

...

String tf_name = ITrampolineFacet.class.getName();
ITrampolineFacet tf = (ITrampolineFacet) node.bindFacet(tf_name);

String rf_name = INodeResourceFacet.class.getName();
INodeResourceFacet rf = (INodeResourceFacet) node.bindFacet(rf_name);

INodeResourceFacet.IAccountedFileSystem
	 tfs = rf.createFileSystem("/tmp", false);

tf.mountFileSystem("/myhome",tfs.getFileSystem());

...

tf.unmountFileSystem("/myhome");

After this, we can use all the usual Java file classes, such as java.io.File and java.io.FileInputStream, etc.

Following the imports, there are four steps in the code above:

  1. Bind to the node's trampoline facet. This is the same as we did with networking.
  2. Bind to Nodality's resource facet. This allows us to create resources.
  3. Create our own file system on the node. In this example we want it to live in the node's /tmp directory. We set the read-only flag to false.
  4. Mount the file system. In this example we mount it onto the prefix /myhome. Now we can write a file called, say, /myhome/profile.txt. It will really be written to the node's /tmp/profile.txt. All our file reading and writing is done with the usual Java classes and methods.
When we're done we can unmount the file system.

Some points to note in the above:

Nik Silver 2002-03-09