@Override public RFile readFile(String filename) throws SystemException, TException { if (fileStoreMap.get(filename) != null) { String content = fileStoreMap.get(filename); RFileMetadata rFileMetadata = new RFileMetadata(); rFileMetadata.setFilename(filename); RFile rFile = new RFile(); rFile.setMeta(rFileMetadata); rFile.setContent(content); return rFile; } else { SystemException systemException = new SystemException(); systemException.setMessage("File does not exist"); throw systemException; } }
@Override public TwoPhaseCommitMessage deleteFile(String filename, TwoPhaseCommitMessage tpcm) throws SystemException, TException { if (tpcm.getMessage().equals("vote_request")) { File file = new File(filename); if (!file.exists()) { SystemException systemException = new SystemException(); systemException.setMessage("File does not exist"); throw systemException; } if (knowConcurrencyStatus(filename)) { tpcm.setMessage("vote_abort"); createLogEntry(tpcm, null, "delete"); return tpcm; } else { createLogEntry(tpcm, null, "delete"); } System.out.println("****deleteFile TEST CASES****"); System.out.println("1. reply vote_commit for " + filename); System.out.println("2. reply vote_commit for " + filename + " and crash"); System.out.println("3. reply vote_abort for " + filename); System.out.println("Enter choice: "); Scanner sc = new Scanner(System.in); int choice = sc.nextInt(); switch (choice) { case 1: tpcm.setMessage("vote_commit"); updateLogEntry(tpcm); return tpcm; case 2: tpcm.setMessage("vote_commit"); updateLogEntry(tpcm); tpcm.setMessage("vote_commit_and_crash"); Runnable crash = new Runnable() { @Override public void run() { crash(); } }; new Thread(crash).start(); return tpcm; case 3: tpcm.setMessage("vote_abort"); updateLogEntry(tpcm); return tpcm; default: System.out.println("Wrong choice! Transaction being aborted!"); tpcm.setMessage("vote_abort"); break; } } else if (tpcm.getMessage().equals("global_commit")) { File file = new File("FileStore/" + filename); if (file.exists()) { file.delete(); } fileStoreMap.remove(filename); updateLogEntry(tpcm); } else if (tpcm.getMessage().equals("global_abort")) { updateLogEntry(tpcm); } return tpcm; }