Guide to File System
NeuroKernel has a very flexible file system interface which is able to mount a plugin application as a file system. There is a default file system available from kernel which is basically implemented by the system manager used. Developers can write their own system manager that implements a file system as well. The default file system will not be available to unregistered remote applications trusted or not. A memory file system is also available from kernel that is also accessible by the remote applications but file size restrictions may apply. Users can copy and paste file to the memory file system to make it available to a remote application they trust. The files written to memory file system will not persist to next user session.
1. Accessing File System
Accessing file systems is very straight forward with NeuroKernel /OS. System can recognize which file system a file belongs to by its prefix. If the file starts with slash /, the it is the default file system used by the system. If it starts with nfs:[name]/, it is a mounted file system that may be living on a remote location. The default file system is just a memory mapped file system when an application is a remote application. Trusted remote applications will have access to system temporary file system. This file system is also available for all registered and trusted applications. Users may copy and paste from default file system to temporary file system so that remote application may access it if desired.
import com.neurokernel.client.*; import com.neurokernel.system.io.*; import com.neurokernel.client.adapter.IActionListener; public class FileSystemExample extends NApplication { @Override public void main(int argc, String[] argv) { NFrame mainFrame = getMainFrame(); new NButton(mainFrame,"Get Date").addListener((IActionListener) e -> { NFile myFile = new NFile("/myfile.txt"); IFileSystem fileSystem=myFile.getFileSystem(getSystem()); fileSystem.exists(myFile, connection -> { if(connection.hasError())NMessageDialog.showError(mainFrame,"File does not exist"); else NMessageDialog.showInfo(mainFrame,"File exists"); }); }); setVisible("File System Interface"); } }
2. Reading Client File
public class MyApplication extends NApplication { NFileButton loader; @Override public void main(int argc, String[] argv) { NFrame mainFrame = getMainFrame(); NFileButton loader = new NFileButton(mainFrame, "Upload File"); loader.addListener(new NFileReaderListener() { @Override public void onComplete() { //upload read data loader.write(new NFile("/"), false, (IResponse connection) -> { if (!connection.hasError()) { NMessageDialog.showInfo(getMainFrame(), "Upload Success"); } }); } }); mainFrame.setTitle("File Button Example"); mainFrame.setBounds(20, 20, 200, 200); mainFrame.setVisible(true); } }
3. Managing File Systems
Managing mounted file system is done via ISystem
interface object. The default file system supplied by the kernel module will always be present. New file systems may be added or removed to the task container. The task container can also load the registered file systems if requested.
4. Implementing a File System
Implementing a file system is simple. If the main application class implements IFileSystem
interface, and the application is made pluggable, then it can be mounted and used as file system by any application.