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.client.io.*;
import com.neurokernel.adapter.NActionListener;
 
public class FileSystemExample extends NApplication {
      @Override
      public void main(int argc, String[] argv) {
          final NFrame mainFrame = getMainFrame();
 
          new NButton(mainFrame,"Get Date").addListener(new NActionListener() {
              @Override
              public void onAction(NEvent e) {
                  NFile myFile = new NFile("/myfile.txt");
                  IFileSystem fileSystem=myFile.getFileSystem(getSystem());
                  fileSystem.exists(myFile, new IDataListener() {
                      @Override
                      public void onSuccess(IResponse connection) {
                          NMessageDialog.showInfo(mainFrame,"File exists");
                      }
 
                      @Override
                      public void onFailure( IResponse connection) {
                          NMessageDialog.showError(mainFrame,"File does not exist");
                      }
                  });
              }
          });
 
          mainFrame.setTitle("File System Interface");
          mainFrame.setBounds(20,20,200,200);
          mainFrame.setVisible(true);
      }
}

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.adapter.NDataListener;
 
public class StorageExample extends NApplication {
      @Override
      public void main(int argc, String[] argv) {
          final NFrame mainFrame=getMainFrame();
 
          getSystem().getClientStorage().load(new NDataListener() {
             @Override
             public void onSuccess(IResponse connection) {
                  getSystem().getClientStorage().add("Hello", "World", new NDataListener() {
                      @Override
                      public void onSuccess(IResponse connection) {
                            new NLabel(mainFrame,"added "+connection.getRequestData());
                            mainFrame.repaint();
                      }
 
                      @Override
                      public void onFailure(IResponse connection) {
                           NMessageDialog.showError(mainFrame,"Hello already exists");
                      }
                  });
              }
 
              @Override
              public void onFailure(IResponse connection) {
                   NMessageDialog.showError(mainFrame,"Failed to load Storage");
              }
          });
 
          mainFrame.setTitle("Storage Interface");
          mainFrame.setBounds(20,20,200,200);
          mainFrame.setVisible(true);
      }
}

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.

4. Decentralized Options

Decentralized file systems such as IPFS can also be used if they have https based gateways to access. Some browsers have native IPFS support such as Brave browser. All it takes to write a file system for the IPFS and deploy it to your IPFS space. It could be a remote application deployed elsewhere. NeuroKernel Research has no plans to officially support any cloud or decentralized file systems for now; however, our GitHub pages will have examples on to implement one. It may even be a reference implementation to be improved by the community.