Skip to content

Commit e161d83

Browse files
author
notefox
committed
added /maps download
1 parent 7aa2b9f commit e161d83

File tree

6 files changed

+237
-47
lines changed

6 files changed

+237
-47
lines changed

maps/map/map.map

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
that is a map

src/java/Server/CustomObjects/Coords.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ public Coords(double x, double y) {
1313

1414
@Override
1515
public String toString() {
16-
return String.valueOf(x + ' ' + y);
16+
return String.valueOf(x.toString() + ' ' + y.toString());
1717
}
1818
}

src/java/Server/CustomObjects/QueryRequest.java

Lines changed: 127 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,36 +6,36 @@
66

77
import java.io.*;
88
import java.time.LocalDateTime;
9+
import java.util.ArrayList;
910
import java.util.List;
10-
import java.util.Vector;
1111

1212
public class QueryRequest extends Thread {
1313

14-
private final List<Coords> coordinates;
15-
private final String date;
14+
private List<Coords> coordinates;
15+
private String date;
1616
private String mapName;
17-
private final String requestedByID;
17+
private String requestedByID;
1818

19-
private final LocalDateTime startTime = LocalDateTime.now();
19+
private LocalDateTime startTime = LocalDateTime.now();
2020
private LocalDateTime runtimeStart;
2121
private LocalDateTime endTime;
2222

2323
private QueryRequestStatus status = QueryRequestStatus.REQUESTED;
2424

2525
private String errorMessage = "";
2626

27-
private final String TAG;
27+
private String TAG;
2828
private String LOG = "";
2929

30-
private final String osmDir;
31-
private final String mapDir;
32-
private final String sLogDir;
30+
private String osmDir;
31+
private String mapDir;
32+
private String sLogDir;
3333

34-
private final String renderingParameter;
35-
private final String ohdmConverter;
34+
private String renderingParameter;
35+
private String ohdmConverter;
3636

37-
private final String javaJdkPath;
38-
private final String jdbcDriverPath;
37+
private String javaJdkPath;
38+
private String jdbcDriverPath;
3939

4040
private String individualLogFile;
4141

@@ -62,6 +62,23 @@ public QueryRequest(List<Coords> coordinates, String date, String mapName, Strin
6262
TAG = mapName + "_" + getRequestedByID() + "-Thread";
6363
}
6464

65+
public QueryRequest() {
66+
67+
}
68+
69+
public QueryRequest QueryRequest(String sLogDir, String mapName) {
70+
this.individualLogFile = sLogDir + "/" + mapName + ".req";
71+
try {
72+
if (readIndivLogFile())
73+
return this;
74+
else {
75+
return new QueryRequest(null, null, null, null, null, null, null, null, null, null, null);
76+
}
77+
} catch (IOException e) {
78+
return new QueryRequest(null, null, null, null, null, null, null, null, null, null, null);
79+
}
80+
}
81+
6582
public Coords[] getCoordinates() {
6683
return coordinates.toArray(new Coords[coordinates.size() - 1]);
6784
}
@@ -366,25 +383,27 @@ private void refreshIndivLogFile() throws IOException {
366383

367384
// indiv write
368385
output += "name : " + mapName + "\n";
369-
output += "coords : " + getPrintableCoordsString(" | ");
386+
output += "coords : " + new Gson().toJson(coordinates) + "\n";
370387
output += "date : " + date + "\n";
371388
output += "id : " + requestedByID + "\n";
372-
output += "status : " + status + "\n";
389+
output += "status : " + new Gson().toJson(status) + "\n";
373390
output += "-----------------------------------------------------------------------------------------------\n";
374-
output += "startTime : " + startTime.toString() + "\n";
375-
output += "runTimeStart : " + runtimeStart.toString() + "\n";
376-
if (endTime != null) { output += "endTime : " + endTime.toString() + "\n"; }
391+
output += "startTime : " + new Gson().toJson(startTime) + "\n";
392+
if (endTime != null) { output += "runTimeStart : " + new Gson().toJson(runtimeStart) + "\n"; }
393+
if (endTime != null) { output += "endTime : " + new Gson().toJson(endTime) + "\n"; }
377394
output += "-----------------------------------------------------------------------------------------------\n";
378395
output += "tagInLog : " + TAG + "\n";
379396
output += "-----------------------------------------------------------------------------------------------\n";
397+
output += "osmDir : " + osmDir + "\n";
398+
output += "mapDir : " + mapDir + "\n";
380399
output += "osmFile : " + osmDir + "/" + mapName + ".osm" + "\n";
381400
output += "mapFile : " + mapDir + "/" + mapName + ".map" + "\n";
382401
output += "renderParamFile : " + renderingParameter + "\n";
383402
output += "OHDMConverterFile : " + ohdmConverter + "\n";
384403
output += "javaPath : " + javaJdkPath + "\n";
385404
output += "jdbcPath : " + jdbcDriverPath + "\n\n";
386405
output += "-----------------------------------------------------------------------------------------------\n";
387-
output += "current log : \n" + LOG;
406+
output += "current log:\n " + LOG;
388407
// end indiv write
389408

390409
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(individualLogFile))));
@@ -393,6 +412,95 @@ private void refreshIndivLogFile() throws IOException {
393412
bw.close();
394413
}
395414

415+
private boolean readIndivLogFile() throws IOException {
416+
File read = new File(individualLogFile);
417+
if (!read.exists())
418+
return false;
419+
420+
String fileContent = "";
421+
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(read)));
422+
while (br.ready())
423+
fileContent += br.readLine() + "\n";
424+
425+
for (String s:fileContent.split("\n")) {
426+
try {
427+
String[] split = s.split(": ");
428+
switch (split[0].trim()) {
429+
case "name":
430+
mapName = split[1].trim();
431+
break;
432+
433+
case "coords":
434+
// Reverse the convertion from List to Json String---
435+
ArrayList listRecovered = new Gson().fromJson(split[1], ArrayList.class);
436+
ArrayList<Coords> realListRec = new ArrayList<>();
437+
for (int i = 0; i < listRecovered.size(); i++) {
438+
realListRec.add(new Gson().fromJson(listRecovered.get(i).toString(), Coords.class));
439+
}
440+
// -------------------------------------------------
441+
coordinates = realListRec;
442+
break;
443+
444+
case "date":
445+
date = split[1].trim();
446+
break;
447+
448+
case "id":
449+
requestedByID = split[1].trim();
450+
break;
451+
452+
case "status":
453+
status = new Gson().fromJson(split[1], QueryRequestStatus.class);
454+
break;
455+
456+
case "startTime":
457+
startTime = new Gson().fromJson(split[1], LocalDateTime.class);
458+
break;
459+
460+
case "runTimeStart":
461+
runtimeStart = new Gson().fromJson(split[1], LocalDateTime.class);
462+
break;
463+
464+
case "endTime":
465+
endTime = new Gson().fromJson(split[1], LocalDateTime.class);
466+
break;
467+
468+
case "tagInLog":
469+
TAG = split[1].trim();
470+
break;
471+
472+
case "osmDir":
473+
osmDir = split[1].trim();
474+
break;
475+
476+
case "mapDir":
477+
mapDir = split[1].trim();
478+
break;
479+
480+
case "renderParamFile":
481+
renderingParameter = split[1].trim();
482+
break;
483+
484+
case "OHDMConverterFile":
485+
ohdmConverter = split[1].trim();
486+
break;
487+
488+
case "javaPath":
489+
javaJdkPath = split[1].trim();
490+
break;
491+
492+
case "jdbcPath":
493+
jdbcDriverPath = split[1].trim();
494+
break;
495+
496+
}
497+
} catch (Exception e) {
498+
Logger.instance.addLogEntry(LogType.ERROR, "init QueryFile", "failed to read a specific value ... \n" + e.getStackTrace()[0]);
499+
}
500+
}
501+
return true;
502+
}
503+
396504
@Override
397505
public String toString() {
398506
return mapName + " " + status.toString() + " " + StaticVariables.formatDateTimeDif(startTime, LocalDateTime.now());

src/java/Server/Playground.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package Server;
22

3+
import Server.CustomObjects.Coords;
34
import Server.CustomObjects.QueryRequest;
45
import com.google.gson.Gson;
56

@@ -11,23 +12,11 @@
1112
import java.time.format.DateTimeFormatter;
1213
import java.time.temporal.ChronoUnit;
1314
import java.util.ArrayList;
15+
import java.util.List;
1416

1517
public class Playground {
1618

17-
static String file = "request.txt";
18-
19-
String testInput = "test";
20-
21-
public synchronized static void main(String[] args) {
22-
23-
}
24-
25-
private static void updateRequestFile() throws FileNotFoundException {
26-
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(file))));
27-
System.currentTimeMillis();
28-
}
29-
30-
private static void readRequestFile() {
19+
public static void main(String[] args) {
3120

3221
}
3322
}

src/java/Server/RequestService/RequestService.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import Server.CustomObjects.LogType;
44
import Server.CustomObjects.QueryRequest;
5+
import Server.CustomObjects.QueryRequestStatus;
56
import Server.LogService.Logger;
67

8+
import java.io.File;
9+
import java.nio.file.Path;
710
import java.util.ArrayList;
811
import java.util.List;
912

@@ -88,18 +91,36 @@ public void stopThread() {
8891
* @param request
8992
*/
9093
public void add(QueryRequest request) {
91-
// if there is space in the WORKER_LIST, it actually will directly put it in the WORKER_LIST and activate it
92-
if (WORKER_LIST.size() < maxInWorkerList) {
93-
WORKER_LIST.add(request);
94-
request.start();
95-
Logger.instance.addLogEntry(INFO, TAG, "added request : " + request.getMapName() + " and started it");
96-
} else {
97-
// if there is no space in the WORKER_LIST, it just adds it to the BUFFER_LIST
98-
BUFFER_LIST.add(request);
99-
Logger.instance.addLogEntry(INFO, TAG,"added request : " + request.getMapName());
94+
// if the Request was an null object
95+
// then it will just stop here
96+
if (request == null)
97+
return;
10098

101-
if (!active)
102-
this.interrupt();
99+
// since it can happen, that Requests with different kind of States are added
100+
// if want to check first, hẃhere I should add them
101+
// if they where stopped on the last File update, then they will be added to the Error List
102+
if (request.getStatus() == QueryRequestStatus.DONE) {
103+
DONE_LIST.add(request);
104+
return;
105+
} else if(request.getStatus() == QueryRequestStatus.ERROR) {
106+
ERROR_LIST.add(request);
107+
return;
108+
} else if (request.getStatus() == QueryRequestStatus.REQUESTED) {
109+
// if there is space in the WORKER_LIST, it actually will directly put it in the WORKER_LIST and activate it
110+
if (WORKER_LIST.size() < maxInWorkerList) {
111+
WORKER_LIST.add(request);
112+
request.start();
113+
Logger.instance.addLogEntry(INFO, TAG, "added request : " + request.getMapName() + " and started it");
114+
} else {
115+
// if there is no space in the WORKER_LIST, it just adds it to the BUFFER_LIST
116+
BUFFER_LIST.add(request);
117+
Logger.instance.addLogEntry(INFO, TAG, "added request : " + request.getMapName());
118+
119+
if (!active)
120+
this.interrupt();
121+
}
122+
} else {
123+
ERROR_LIST.add(request);
103124
}
104125
}
105126

0 commit comments

Comments
 (0)