Experimental Thread pausing.

TODO: test.
pull/1/head
Ivan Olexyn 5 years ago
parent d5530fbe09
commit eef0b2981f

@ -10,7 +10,7 @@ public class Flow implements Runnable{
private String state;
public void run() {
@ -20,14 +20,16 @@ public class Flow implements Runnable{
for (Map.Entry<String, SyncMap> mapEntry : Main.sync.syncMaps.entrySet()) {
SyncMap syncMap = mapEntry.getValue();
state = syncMap.toString();
for (Map.Entry<String, SyncDirectory> entry : mapEntry.getValue().syncDirectories.entrySet()) {
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);
@ -43,6 +45,7 @@ public class Flow implements Runnable{
String path = syncDirectory.path;
state = "READ";
syncDirectory.readState();
syncDirectory.makeListCreated();
@ -57,11 +60,13 @@ public class Flow implements Runnable{
syncDirectory.writeStateFile(path);
}
try {
System.out.println("Pausing...");
Thread.sleep(1000);
Main.flowThread.sleep(2000);
} catch (InterruptedException e) {
}
@ -69,4 +74,8 @@ public class Flow implements Runnable{
}
}
public String getState() {
return state==null ? "NONE" : state;
}
}

@ -22,11 +22,11 @@ public class Main{
final public static Sync sync = new Sync();
final private static Flow flow = new Flow();
final private static UI ui = new UI();
final public static Thread uiThread = new Thread(new UI(), "ui");
final public static Thread flowThread = new Thread(new Flow(), "flow");
@ -37,11 +37,9 @@ public class Main{
sync.syncMaps.put("test", new SyncMap("test"));
Thread uiThread = new Thread(ui, "ui");
uiThread.start();
uiThread.start();
Thread flowThread = new Thread(flow, "flow");
flowThread.start();

@ -33,7 +33,7 @@ public class Controller implements Initializable {
Button addDirButton = new Button("Add");
addDirButton.setId("addDirButton");
addDirButton.setOnAction(event -> { this.addDir();});
addDirButton.setOnAction(event -> { this.addDirectory();});
gridPane.add(directoryField, 0, 0);
gridPane.add(new Text(""), 1, 0);
@ -49,7 +49,7 @@ public class Controller implements Initializable {
protected GridPane gridPane;
protected void addDir() {
protected void addDirectory() {
Window stage = gridPane.getScene().getWindow();
final DirectoryChooser directoryChooser = new DirectoryChooser();
@ -73,7 +73,7 @@ public class Controller implements Initializable {
Button removeButton = new Button("Remove");
removeButton.setId("removeButton" + dir.getAbsolutePath());
removeButton.setOnAction(event -> { this.rmDir(removeButton.getId());});
removeButton.setOnAction(event -> { this.removeDirectory(removeButton.getId());});
List<Node> nodeList = new ArrayList<>();
@ -118,10 +118,8 @@ public class Controller implements Initializable {
}
private void rmDir(String id) {
String path = id.replace("removeButton", "");
private void removeDirectory(String id) {
Main.sync.syncMaps.get("test").removeDirectory(path);
List<Node> nodeList = new ArrayList<>();
@ -156,6 +154,21 @@ public class Controller implements Initializable {
}
String path = id.replace("removeButton", "");
while(true){
if (Main.flowThread.getState().equals(Thread.State.TIMED_WAITING)){
try {
Main.flowThread.wait();
} catch (InterruptedException e){
Main.sync.syncMaps.get("test").removeDirectory(path);
Main.flowThread.notify();
break;
}
}
}
}

Loading…
Cancel
Save