Assert state of code.

- somewhat broken.
- next task: make SYNC a user defined parameter.
pull/1/head
Ivan Olexyn 5 years ago
parent eebcabe911
commit 8ebc2a2e9a

@ -17,31 +17,18 @@ public class Flow implements Runnable{
initialize();
for (Map.Entry<String, SyncMap> mapEntry : Main.sync.syncMaps.entrySet()) {
SyncMap syncMap = mapEntry.getValue();
state = syncMap.toString();
for (Map.Entry<String, SyncDirectory> entry : syncMap.syncDirectories.entrySet()) {
SyncDirectory syncDirectory = entry.getValue();
String path = syncDirectory.path;
String stateFilePath = syncDirectory.stateFilePath(path);
if (new File(stateFilePath).exists()) { for (var syncMapEntry : Main.SYNC.entrySet()) {
state = "READ-STATE-FILE-"+
syncDirectory.readStateFile();
} else {
syncDirectory.writeStateFile(path);
}
}
while (true) { while (true) {
for (Map.Entry<String, SyncDirectory> entry : mapEntry.getValue().syncDirectories.entrySet()) { for (var syncDirectoryEntry : syncMapEntry.getValue().syncDirectories.entrySet()) {
SyncDirectory syncDirectory = entry.getValue(); SyncDirectory syncDirectory = syncDirectoryEntry.getValue();
String path = syncDirectory.path; String path = syncDirectory.path;
@ -56,18 +43,14 @@ public class Flow implements Runnable{
syncDirectory.doDelete(); syncDirectory.doDelete();
syncDirectory.doModify(); syncDirectory.doModify();
syncDirectory.writeStateFile(path); syncDirectory.writeStateFile(path);
} }
try { try {
System.out.println("Pausing..."); System.out.println("Pausing...");
Main.flowThread.sleep(2000); Thread.sleep(2000);
} catch (InterruptedException e) { } catch (InterruptedException ignored) {
} }
} }
@ -78,4 +61,29 @@ public class Flow implements Runnable{
public String getState() { public String getState() {
return state==null ? "NONE" : state; return state==null ? "NONE" : state;
} }
/**
* For every single SyncDirectory try to read it's StateFile. <p>
* If the StateFile is missing, then create a StateFile.
*/
private void initialize(){
for (var syncMapEntry : Main.SYNC.entrySet()) {
SyncMap syncMap = syncMapEntry.getValue();
state = syncMap.toString();
for (var stringSyncDirectoryEntry : syncMap.syncDirectories.entrySet()) {
SyncDirectory syncDirectory = stringSyncDirectoryEntry.getValue();
String path = syncDirectory.path;
String stateFilePath = syncDirectory.stateFilePath(path);
if (new File(stateFilePath).exists()) {
state = "READ-STATE-FILE-" + syncDirectory.readStateFile();
} else {
syncDirectory.writeStateFile(path);
}
}
}
}
} }

@ -1,26 +1,16 @@
package com.olexyn.ensync; package com.olexyn.ensync;
import com.olexyn.ensync.artifacts.Sync;
import com.olexyn.ensync.artifacts.SyncMap; import com.olexyn.ensync.artifacts.SyncMap;
import com.olexyn.ensync.ui.UI; import com.olexyn.ensync.ui.UI;
import javafx.application.Application;
import javafx.collections.ObservableList; import java.util.HashMap;
import javafx.fxml.FXMLLoader; import java.util.Map;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.stage.Window;
public class Main{ public class Main{
final public static Sync sync = new Sync();
@ -28,13 +18,13 @@ public class Main{
final public static Thread flowThread = new Thread(new Flow(), "flow"); final public static Thread flowThread = new Thread(new Flow(), "flow");
final public static Map<String, SyncMap> SYNC = new HashMap<>();
public static void main(String[] args) { public static void main(String[] args) {
sync.syncMaps.put("test", new SyncMap("test")); SYNC.put("test", new SyncMap("test"));

@ -1,11 +0,0 @@
package com.olexyn.ensync.artifacts;
import java.util.HashMap;
import java.util.Map;
public class Sync {
public Map<String, SyncMap> syncMaps = new HashMap<>();
}

@ -111,7 +111,6 @@ public class SyncDirectory {
* Compare the OLD and NEW pools. * Compare the OLD and NEW pools.
* List is cleared and created each time. * List is cleared and created each time.
* *
* @return
*/ */
public void makeListDeleted() { public void makeListDeleted() {
listDeleted = new ArrayList<>(); listDeleted = new ArrayList<>();
@ -127,7 +126,6 @@ public class SyncDirectory {
* Compare the OLD and NEW pools. * Compare the OLD and NEW pools.
* List is cleared and created each time. * List is cleared and created each time.
* *
* @return
*/ */
public void makeListModified() { public void makeListModified() {

@ -8,8 +8,9 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* A SyncMap is a collection of SyncDirectories, * What is a SyncMap?
* that are supposed to be kept in sync. * A SyncDirectory is an occurrence of a particular directory somewhere across the filesystems.
* A SyncMap is the set of such SyncDirectories. The purpose of the SyncMap is to help syncronize the SyncDirectories.
*/ */
public class SyncMap { public class SyncMap {
@ -27,11 +28,10 @@ public class SyncMap {
} }
/** /**
* Creates a new Syncdirectory. * Creates a new Syncdirectory. <p>
* <p>
* Adds the created SyncDirectory to this SyncMap. * Adds the created SyncDirectory to this SyncMap.
* *
* @param realPath the path from which the Syncdirectory is created. * @param realPath the path from which the SyncDirectory is created.
* @see SyncDirectory * @see SyncDirectory
*/ */
public void addDirectory(String realPath) { public void addDirectory(String realPath) {
@ -45,8 +45,4 @@ public class SyncMap {
} }
} }

@ -64,7 +64,7 @@ public class Controller implements Initializable {
pathTextField.setDisable(true); pathTextField.setDisable(true);
// TODO for now there is only one SyncMap "test". // TODO for now there is only one SyncMap "test".
Main.sync.syncMaps.get("test").addDirectory(dir.getAbsolutePath()); Main.SYNC.get("test").addDirectory(dir.getAbsolutePath());
TextField stateTextField = new TextField(); TextField stateTextField = new TextField();
stateTextField.setText("STATE"); stateTextField.setText("STATE");
@ -161,7 +161,7 @@ public class Controller implements Initializable {
try { try {
Main.flowThread.wait(); Main.flowThread.wait();
} catch (InterruptedException e){ } catch (InterruptedException e){
Main.sync.syncMaps.get("test").removeDirectory(path); Main.SYNC.get("test").removeDirectory(path);
Main.flowThread.notify(); Main.flowThread.notify();
break; break;
} }

Loading…
Cancel
Save