package automately.core.file;
import io.jsync.AsyncResult;
import io.jsync.Handler;
import io.jsync.app.core.Cluster;
import io.jsync.buffer.Buffer;
import java.io.File;
/**
* The VirtualFileStore interface is a very important interface that is used by
* the VirtualFileService to store your data in a central location within the cluster.
* It acts as a central point of storage so all of your data can be persistent instead of
* inconsistent.
*/
public interface VirtualFileStore {
/**
* This is called when the VirtualFileStore is first initialized. This is used so
* you can access the Cluster object.
* @param cluster
*/
void initialize(Cluster cluster);
void stop();
File toFile(VirtualFile file);
/**
* This is used to retrieve the data for the VirtualFile
*
* @return data for the VirtualFile
*/
Buffer readRawData(VirtualFile file);
/**
* This allows you to retrieve data for a VirtualFile asynchronously.
*
* @param file the VirtualFile you wish to retrieve data for
* @param asyncResultHandler the handler with the file data
*/
void readRawData(VirtualFile file, Handler<AsyncResult<Buffer>> asyncResultHandler);
/**
* This is used to write the data for the VirtualFile.
*
* @param file the file you wish to write the data to
* @param data the data you wish to write
*/
void writeRawData(VirtualFile file, Buffer data);
/**
* This is used to write the data for the VirtualFile asynchronously.
*
* @param file the file you wish to write the data to
* @param data the data you wish to write
* @param asyncResultHandler the handle which tells you if the write succeeded or not
*/
void writeRawData(VirtualFile file, Buffer data, Handler<AsyncResult<Void>> asyncResultHandler);
/**
* This is used to effectively delete a file from the file system. This is
* called only by the VirtualFileSystem when a file is no longer referenced.
*
* @param file the file you wish to delete
*/
void deleteFile(VirtualFile file);
/**
* This is used to asynchronously delete a file from the file system.
* @param file the file you wish to delete
* @param asyncResultHandler a handler that is triggered when the file is deleted
*/
void deleteFile(VirtualFile file, Handler<AsyncResult<Void>> asyncResultHandler);
/**
* This method is used by the VirtualFileService to help ensure that all the nodes are synced up
* and reading the same data for a specified file. The VirtualFileService will randomly attempt to verify data. At the initial startup
* of a node it'll attempt to verify a specific file.
*
* @param file The file that is being validated
* @param hash The hash of the contents
* @return returns true or false on success
*/
boolean verifyNode(VirtualFile file, String hash);
}