Guide to Data Storage

Persistent storage is done using multiple ways. First and for-most is the file systems offered by NeuroKernel. Dynamic mode comes with a server side file system. For static mode on the other hand, cloud based or remote file systems can be used. It only takes to implement IFileSystem interface. When a file system application is plugged into another application, the file system will be mounted and automatically available.

1. File Systems

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");
        }
    }

1.1 Implementing File System

Implementing a file system is simple. If the main application class implements IFileSystem interface and is made pluggable, then it can be mounted and used as file system by any application.

2. Client Side Storage

Client storage is the persistent storage feature available from the browser client. NeuroKernel uses IndexDB for the persistent storage but fall backs to local storage if not supported. If remote applications fail to request persistent storage access, a memory based implementation is used to offset operational functionality but nothing will persist in this case. The existence of persistent storage can be checked using the ISystem interface. Client storage can also store images from a sub interface called IPixmapStorage available from IClientStorage.

import com.neurokernel.client.*;
import com.neurokernel.system.io.*;
 
public class StorageExample extends NApplication {
 
      @Override
      public void main(int argc, String[] argv) {
          NFrame mainFrame = getMainFrame();
 
          getClientStorage().add("Hello", "World", response -> {
              if(response.hasError()) {
                  NMessageDialog.showError(mainFrame, "Hello already exists");
              } else { 
                  new NLabel(mainFrame, "added " + response.getRequestData());
                  mainFrame.repaint();
              }
          });
 
          setVisible("Storage Interface);
      }
  }

3. Cloud Options

Cloud based storage can be used if a NeuroKernel file system is available to access to the storage content. This could be a vendor supplied application or third party application if CORS is allowed. There are plenty of cloud file storage options to choose from.