Add some documentaton.
@@ -12,6 +12,13 @@ public class LocalStorage {
private final File storageFolder;
private final DigestUtils digestUtils = new DigestUtils(SHA_1);
+ /**
+ * Helper class to store a SHA-1 hash of a message in local storage of a plugin instance.
+ * This can be used to detect if a plugin crashed while working on a certain input, and appropriate action can be taken.
+ *
+ * The folder name will be suffixed by the $POD_INSTANCE_ID env. variable. Ensure this is unique per plugin instance.
+ * @param folder the folder to store in. A plugin instance should always have access to this folder (so preferable some sort of NFS mount).
+ */
public LocalStorage(String folder) {
if (System.getenv("POD_INSTANCE_ID") != null) {
instanceId = System.getenv("POD_INSTANCE_ID");
@@ -27,6 +34,12 @@ public class LocalStorage {
}
}
+ /**
+ * Verify if a message is already in the local storage.
+ *
+ * @param message the message to verify.
+ * @return true if local storage, otherwise false.
+ */
public boolean exists(String message) {
String hashedMessage = digestUtils.digestAsHex(message);
String[] filesInFolder = storageFolder.list();
@@ -39,6 +52,12 @@ public class LocalStorage {
return false;
}
+ /**
+ * Remove a message from local storage.
+ *
+ * @param message the message to remove.
+ * @return true if sucessfully deleted, otherwise false (for instance, when it doesn't exist).
+ */
public boolean delete(String message) {
if (!exists(message)) {
return false;
@@ -50,6 +69,13 @@ public class LocalStorage {
return fileToRemove.delete();
}
+ /**
+ * Stores a message in local storage.
+ *
+ * @param message the raw message to store. Will be hashed into SHA-1 format.
+ * @return if successfully stored.
+ * @throws IOException when file can't be created.
+ */
public boolean store(String message) throws IOException {
if (exists(message)) {
return false;
