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:
Some points to note in the above:
Different systems are laid out differently. In the example above we got access to /tmp. But if we were running on another system we might have had to ask for C:\Temp instead.
We chose our prefix to be /myhome and therefore had access to /myhome/profile.txt. If we had missed out the leading / then Jtrix would have added it for us. By contrast, only the leading character can be a /. Anything else will throw an exception. Similarly, the prefix may not contain a colon anywhere in it.
Once we've mounted our file system Jtrix insists we access it as if it were a Unix file system, using forward-slashes. This is regardless of what the underlying system is.
Of course, several mount points can exist simultaneously, and these can be based in different parts of the host system. However, they cannot be mounted on top of each other--which is actually a corollary of the last point.
The /proc hierarchy is given to us by default; we don't have to bind or mount anything to access it. It contains process-specific files which at the time of writing are: (a) the subdirectory runtime which contains the Java runtime JAR, rt.jar; (b) the subdirectory codebase which contains all other JARs currently in use by this netlet, each named with the label that was used to download it.
Steps 2 and 3 above are specific to Nodality. It is a Nodality feature to offer the option of local file system access (in this case /tmp). If this code is running on another kind of node then those two steps wouldn't work. And furthermore, the node has...
Access to /tmp or C:\Temp or whatever else we tried to use is at the complete discretion of the node. It has every right to refuse us. And that's why we have...
Step 4 above mounts a file system, but that second parameter to mountFileSystem() doesn't have to be a Nodality file system. It can be anything which implements the facet org.jtrix.facet.node.IFileSystem. So a netlet might well start up with a warrant for a file system service which provides an IFileSystem. If this is in variable myfs then the code is reduced to this:
String tf_name = ITrampolineFacet.class.getName(); ITrampolineFacet tf = (ITrampolineFacet) node.bindFacet(tf_name); tf.mountFileSystem("/myhome", myfs); ... tf.unmountFileSystem("/myhome");
Several different providers can be used simultaneously on different mount points.
Nik Silver 2002-03-09