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()) {
state = "READ-STATE-FILE-"+
syncDirectory.readStateFile();
} else {
syncDirectory.writeStateFile(path);
}
}
for (var syncMapEntry : Main.SYNC.entrySet()) {
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;
@ -56,18 +43,14 @@ public class Flow implements Runnable{
syncDirectory.doDelete();
syncDirectory.doModify();
syncDirectory.writeStateFile(path);
}
try {
System.out.println("Pausing...");
Main.flowThread.sleep(2000);
} catch (InterruptedException e) {
Thread.sleep(2000);
} catch (InterruptedException ignored) {
}
}
@ -78,4 +61,29 @@ public class Flow implements Runnable{
public String getState() {
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;
import com.olexyn.ensync.artifacts.Sync;
import com.olexyn.ensync.artifacts.SyncMap;
import com.olexyn.ensync.ui.UI;
import javafx.application.Application;
import javafx.collections.ObservableList;
import javafx.fxml.FXMLLoader;
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;
import java.util.HashMap;
import java.util.Map;
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 Map<String, SyncMap> SYNC = new HashMap<>();
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.
* List is cleared and created each time.
*
* @return
*/
public void makeListDeleted() {
listDeleted = new ArrayList<>();
@ -127,7 +126,6 @@ public class SyncDirectory {
* Compare the OLD and NEW pools.
* List is cleared and created each time.
*
* @return
*/
public void makeListModified() {

@ -8,8 +8,9 @@ import java.util.HashMap;
import java.util.Map;
/**
* A SyncMap is a collection of SyncDirectories,
* that are supposed to be kept in sync.
* What is a SyncMap?
* 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 {
@ -27,11 +28,10 @@ public class SyncMap {
}
/**
* Creates a new Syncdirectory.
* <p>
* Creates a new Syncdirectory. <p>
* 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
*/
public void addDirectory(String realPath) {
@ -45,8 +45,4 @@ public class SyncMap {
}
}

@ -64,7 +64,7 @@ public class Controller implements Initializable {
pathTextField.setDisable(true);
// 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();
stateTextField.setText("STATE");
@ -161,7 +161,7 @@ public class Controller implements Initializable {
try {
Main.flowThread.wait();
} catch (InterruptedException e){
Main.sync.syncMaps.get("test").removeDirectory(path);
Main.SYNC.get("test").removeDirectory(path);
Main.flowThread.notify();
break;
}

Loading…
Cancel
Save