ready to launch

pull/1/head
Ivan Olexyn 4 years ago
parent d0f1f61378
commit 6942061f70

@ -1,13 +0,0 @@
package com.olexyn.ensync;
/**
* Hello world!
*
*/
public class App
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

@ -4,6 +4,9 @@ import com.olexyn.ensync.artifacts.SyncDirectory;
import com.olexyn.ensync.artifacts.SyncMap; import com.olexyn.ensync.artifacts.SyncMap;
import java.io.File; import java.io.File;
import java.util.Map;
import java.util.Map.Entry;
import static com.olexyn.ensync.Main.MAP_OF_SYNCMAPS; import static com.olexyn.ensync.Main.MAP_OF_SYNCMAPS;
public class Flow implements Runnable { public class Flow implements Runnable {
@ -17,20 +20,30 @@ public class Flow implements Runnable {
public void run() { public void run() {
while (true) { while (true) {
synchronized (MAP_OF_SYNCMAPS) { synchronized (MAP_OF_SYNCMAPS) {
readOrMakeStateFile(); readOrMakeStateFile();
for (var syncMapEntry : MAP_OF_SYNCMAPS.entrySet()) { for (Entry<String, SyncMap> syncMapEntry : MAP_OF_SYNCMAPS.entrySet()) {
for (Entry<String, SyncDirectory> SDEntry : syncMapEntry.getValue().syncDirectories.entrySet()) {
for (var SDEntry : syncMapEntry.getValue().syncDirectories.entrySet()) { doSyncDirectory(SDEntry.getValue());
}
}
}
try {
long pause = 2000;
System.out.println("Pausing... for " + pause + "ms.");
Thread.sleep(pause);
} catch (InterruptedException ignored) {}
}
}
SyncDirectory SD = SDEntry.getValue();
private void doSyncDirectory(SyncDirectory SD) {
state = "READ"; state = "READ";
SD.readFreshState(); SD.readFreshState();
@ -46,22 +59,6 @@ public class Flow implements Runnable {
} }
}
}
try {
long pause = 2000;
System.out.println("Pausing... for "+pause+ "ms.");
Thread.sleep(pause);
} catch (InterruptedException ignored) {
}
}
}
public String getState() { public String getState() {
return state == null ? "NONE" : state; return state == null ? "NONE" : state;
} }

@ -8,38 +8,13 @@ import java.util.HashMap;
public class Main{ public class Main{
final public static Thread UI_THREAD = new Thread(new UI(), "ui"); final public static Thread UI_THREAD = new Thread(new UI(), "ui");
final public static Thread FLOW_THREAD = new Thread(new Flow(), "flow"); final public static Thread FLOW_THREAD = new Thread(new Flow(), "flow");
final public static HashMap<String, SyncMap> MAP_OF_SYNCMAPS = new HashMap<>(); final public static HashMap<String, SyncMap> MAP_OF_SYNCMAPS = new HashMap<>();
public static void main(String[] args) { public static void main(String[] args) {
UI_THREAD.start(); UI_THREAD.start();
FLOW_THREAD.start(); FLOW_THREAD.start();
} }
} }

@ -10,7 +10,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
* A SyncDirectory is an occurrence of a particular directory somewhere across the filesystems. * A SyncDirectory is a singular occurrence of a directory in the filesystems.
*/ */
public class SyncDirectory { public class SyncDirectory {
@ -18,7 +18,7 @@ public class SyncDirectory {
private SyncDirectory thisSD = this; private SyncDirectory thisSD = this;
private SyncMap syncMap; private final SyncMap syncMap;
public String path = null; public String path = null;
public Map<String, SyncFile> listCreated = new HashMap<>(); public Map<String, SyncFile> listCreated = new HashMap<>();
@ -59,11 +59,7 @@ public class SyncDirectory {
filemap.put(filePath, file); filemap.put(filePath, file);
} }
return filemap; return filemap;
} }
@ -86,9 +82,7 @@ public class SyncDirectory {
filemap.put(sFilePath, sfile); filemap.put(sFilePath, sfile);
} }
return filemap; return filemap;
} }

@ -10,9 +10,7 @@ public class SyncFile extends File {
public long timeModifiedFromStateFile = 0; public long timeModifiedFromStateFile = 0;
public String relativePath; public String relativePath;
private SyncDirectory sd; private final SyncDirectory sd;
public SyncFile(SyncDirectory sd, String pathname) { public SyncFile(SyncDirectory sd, String pathname) {
@ -21,15 +19,10 @@ public class SyncFile extends File {
relativePath = this.getPath().replace(sd.path, ""); relativePath = this.getPath().replace(sd.path, "");
} }
public void setTimeModifiedFromStateFile(long value) { public void setTimeModifiedFromStateFile(long value) {
timeModifiedFromStateFile = value; timeModifiedFromStateFile = value;
} }
public long getTimeModifiedFromStateFile() { public long getTimeModifiedFromStateFile() {
SyncFile record = sd.readStateFile().get(this.getPath()); SyncFile record = sd.readStateFile().get(this.getPath());
@ -37,7 +30,6 @@ public class SyncFile extends File {
return record == null ? 0 : record.timeModifiedFromStateFile; return record == null ? 0 : record.timeModifiedFromStateFile;
} }
/** /**
* If File exists on Disk get the TimeModified from there. * If File exists on Disk get the TimeModified from there.
* Else try to read it from StateFile. * Else try to read it from StateFile.
@ -54,10 +46,6 @@ public class SyncFile extends File {
if (sd.readStateFile().get(this.getPath())!=null){ if (sd.readStateFile().get(this.getPath())!=null){
return getTimeModifiedFromStateFile(); return getTimeModifiedFromStateFile();
} }
return 0; return 0;
} }
} }

@ -8,7 +8,8 @@ import java.util.HashMap;
import java.util.Map; import java.util.Map;
/** /**
* A SyncMap is the set of such SyncDirectories. The purpose of the SyncMap is to help syncronize the SyncDirectories. * A SyncMap is a map of SyncDirectories. <br>
* It synchronizes the SyncDirectories it contains.
*/ */
public class SyncMap { public class SyncMap {

@ -9,27 +9,17 @@ import javafx.stage.Stage;
public class UI extends Application implements Runnable { public class UI extends Application implements Runnable {
@Override @Override
public void start(Stage primaryStage) throws Exception { public void start(Stage primaryStage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("layout.fxml")); // in IDEA add ";?.fxml;?.css" to File|Settings|Compiler settings
Parent root = FXMLLoader.load(getClass().getResource("/fxml/layout.fxml"));
Scene scene = new Scene(root, 500, 500); Scene scene = new Scene(root, 500, 500);
primaryStage.setTitle("EnSync"); primaryStage.setTitle("EnSync");
primaryStage.setScene(scene); primaryStage.setScene(scene);
primaryStage.show(); primaryStage.show();
} }
@Override @Override
public void run() { public void run() {
UI.launch(); UI.launch();

Loading…
Cancel
Save