Skip to content

Commit 459d3ed

Browse files
author
notefox
committed
update ControllerEndpoint.java
1 parent f005435 commit 459d3ed

14 files changed

Lines changed: 1069 additions & 532 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ based on the Application, and not on the Linked Version.
3737
The "Corresponding Application Code" for a Combined Work means the
3838
object code and/or source code for the Application, including any data
3939
and utility programs needed for reproducing the Combined Work from the
40-
Application, but excluding the System Libraries of the Combined Work.
40+
Application, but excluding the Server.LogService.System Libraries of the Combined Work.
4141

4242
1. Exception to Section 3 of the GNU GPL.
4343

db_render.txt

Lines changed: 0 additions & 8 deletions
This file was deleted.

db_rendering.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
servername:ohm.f4.htw-berlin.de
2+
portnumber:5432
3+
username:geoserver
4+
pwd:ohdm4ever!
5+
dbname:ohdm_public
6+
schema:public
7+
maxThreads:5
8+
renderoutput=all

pom.xml

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919

2020
<properties>
2121
<java.version>11</java.version>
22-
</properties>
22+
<kotlin.version>1.3.72</kotlin.version>
23+
</properties>
2324

2425
<dependencies>
2526
<dependency>
@@ -77,8 +78,19 @@
7778
<artifactId>gson</artifactId>
7879
<version>2.8.6</version>
7980
</dependency>
81+
<dependency>
82+
<groupId>org.jetbrains.kotlin</groupId>
83+
<artifactId>kotlin-stdlib-jdk8</artifactId>
84+
<version>${kotlin.version}</version>
85+
</dependency>
86+
<dependency>
87+
<groupId>org.jetbrains.kotlin</groupId>
88+
<artifactId>kotlin-test</artifactId>
89+
<version>${kotlin.version}</version>
90+
<scope>test</scope>
91+
</dependency>
8092

81-
</dependencies>
93+
</dependencies>
8294

8395
<build>
8496
<sourceDirectory>src/java</sourceDirectory>
@@ -96,7 +108,51 @@
96108
<groupId>org.springframework.boot</groupId>
97109
<artifactId>spring-boot-maven-plugin</artifactId>
98110
</plugin>
99-
</plugins>
111+
<plugin>
112+
<groupId>org.jetbrains.kotlin</groupId>
113+
<artifactId>kotlin-maven-plugin</artifactId>
114+
<version>${kotlin.version}</version>
115+
<executions>
116+
<execution>
117+
<id>compile</id>
118+
<phase>compile</phase>
119+
<goals>
120+
<goal>compile</goal>
121+
</goals>
122+
</execution>
123+
<execution>
124+
<id>test-compile</id>
125+
<phase>test-compile</phase>
126+
<goals>
127+
<goal>test-compile</goal>
128+
</goals>
129+
</execution>
130+
</executions>
131+
<configuration>
132+
<jvmTarget>1.8</jvmTarget>
133+
</configuration>
134+
</plugin>
135+
<plugin>
136+
<groupId>org.apache.maven.plugins</groupId>
137+
<artifactId>maven-compiler-plugin</artifactId>
138+
<executions>
139+
<execution>
140+
<id>compile</id>
141+
<phase>compile</phase>
142+
<goals>
143+
<goal>compile</goal>
144+
</goals>
145+
</execution>
146+
<execution>
147+
<id>testCompile</id>
148+
<phase>test-compile</phase>
149+
<goals>
150+
<goal>testCompile</goal>
151+
</goals>
152+
</execution>
153+
</executions>
154+
</plugin>
155+
</plugins>
100156
</build>
101157

102158
</project>

src/java/Server/ControllerEndpoint/ControllerEndpoint.java

Lines changed: 114 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
package Server.ControllerEndpoint;
22

33
import Server.CustomObjects.QueryRequest;
4+
import Server.IDService.IDSystem;
45
import Server.LogService.Logger;
56
import Server.SpringClass;
7+
import Server.StaticVariables;
68

9+
import javax.swing.*;
710
import java.io.*;
811
import java.text.SimpleDateFormat;
12+
import java.time.LocalDateTime;
913

1014
import static Server.CustomObjects.LogType.INFO;
1115

@@ -14,10 +18,25 @@ public class ControllerEndpoint extends Thread {
1418
private String msgPath;
1519
private String LOG_TAG = "ControllerAccessEndpoint";
1620

21+
private static final String STATUS_KEY = "status";
22+
private static final String STATUS_DONE_KEY = "done";
23+
private static final String STATUS_ERROR_KEY = "error";
24+
private static final String STATUS_BUFFER_KEY = "buffer";
25+
private static final String ID_KEY = "id";
26+
private static final String LOG_KEY = "current log";
27+
private static final String DAEMON_KEY = "daemon log";
28+
private static final String RELOAD_S_KEY = "reload requestService";
29+
private static final String RELOAD_LOG_KEY = "reload log";
30+
private static final String RELOAD_ID_KEY = "reload id";
31+
private static final String CLEAR_BUFFER_LIST = "clear buffer";
32+
private static final String STOP_WORKER_LIST = "stop worker";
33+
private static final String CLEAN_ERROR_LIST = "clean error";
34+
private static final String CLEAN_DONE_LIST = "clean done";
35+
private static final String RESTART_KEY = "restart";
36+
1737
public ControllerEndpoint(String msgPath) {
1838
this.msgPath = msgPath;
1939
}
20-
2140
private synchronized File fetchNewFile() throws InterruptedException {
2241
File msgDir = new File(msgPath);
2342
if (!msgDir.exists()) {
@@ -46,7 +65,6 @@ private synchronized File fetchNewFile() throws InterruptedException {
4665
}
4766
}
4867
}
49-
5068
private ControllerRequest readContent(File file) throws IOException {
5169
String id = file.getName().replace(".req", "");
5270
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
@@ -59,79 +77,150 @@ private ControllerRequest readContent(File file) throws IOException {
5977
Logger.instance.addLogEntry(INFO, LOG_TAG, "read new request | ID : " + id + " | Request : " + value);
6078
return new ControllerRequest(id, value);
6179
}
62-
6380
private BufferedWriter writeResponse(File file, ControllerRequest r) throws IOException {
6481
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file)));
6582
bw.write(r.returnValue);
6683
bw.flush();
6784
Logger.instance.addLogEntry(INFO, LOG_TAG, "response send : " + r.returnValue + " | \nID: " + r.id);
6885
return bw;
6986
}
70-
7187
private String processRequest(String request) throws IOException {
7288
String answer = "";
7389
BufferedReader br;
7490
switch (request) {
7591
case "help" :
7692
answer += "currently implemented : " + "\n";
77-
answer += " status - giving back the status the service is currently in \n";
78-
answer += " current log - gives back the current log entries\n";
79-
answer += " daemon log - gives back the daemon log entries\n";
80-
answer += " reload requestService - restarts the service with new read init values (all buffered requests will be saved)\n";
81-
answer += " reload log - restarts log with new read init values\n";
82-
answer += " restart - restarts the whole Service with new read init values\n";
93+
answer += STATUS_KEY + "\t - giving back the status the service is currently in\n";
94+
answer += STATUS_DONE_KEY + "\t - showing all the finished requests\n";
95+
answer += STATUS_ERROR_KEY + "\t - shows all the Requests with an error\n";
96+
answer += STATUS_BUFFER_KEY + "\t - shows all the Requests in the Buffer\n";
97+
answer += ID_KEY + "\t - gives all currently saved ids\n";
98+
answer += LOG_TAG + "\t - gives back the current log entries\n";
99+
answer += DAEMON_KEY + "\t - gives back the daemon log entries\n";
100+
answer += RELOAD_S_KEY + "\t - restarts the service with new read init values (all buffered requests will be saved)\n";
101+
answer += RELOAD_LOG_KEY + "\t - restarts log with new read init values\n";
102+
answer += RELOAD_ID_KEY + "\t - restarts id with new read init values\n";
103+
answer += CLEAR_BUFFER_LIST + "\t - clears all requests in the buffer\n";
104+
answer += CLEAN_DONE_LIST + "\t - cleans all requests in the \"Done List\"\n";
105+
answer += CLEAN_ERROR_LIST + "\t - cleans all requests in the \"Error list\"\n";
106+
answer += STOP_WORKER_LIST + "\t - stops a specific or all currently running Requests\n\t nr <1-5>\n";
107+
answer += RESTART_KEY + "\t - restarts the whole Service with new read init values\n";
108+
answer += "testRequest \t- makes a testRequest of default values\n";
83109
return answer;
84110

85111

86-
case "status" :
112+
case STATUS_KEY :
87113
answer += "Service running : " + SpringClass.serviceInstance.isRunning() + "\n";
88114
answer += "Service currently working : " + SpringClass.serviceInstance.isActive() + "\n";
89115
answer += "Requests currently waiting : " + SpringClass.serviceInstance.getBUFFER_LIST().size() + "\n";
90-
answer += "Logger active : " + Logger.instance.isRunning + "\n";
116+
answer += "Logger active : " + Logger.instance.isRunning() + "\n";
91117
answer += "-----------------------------------------------------------------------------\n";
118+
answer += "current Requests in Error : " + SpringClass.serviceInstance.getERROR_LIST().size() + "\n";
119+
answer += "current Requests in Done : " + SpringClass.serviceInstance.getDONE_LIST().size() + "\n";
92120
answer += "current working Requests : \n";
93-
for (QueryRequest r:
94-
SpringClass.serviceInstance.getWORKER_LIST()) {
95-
answer += "ID: " + r.getRequestedByID() + "\n";
96-
answer += "requestName: " + r.getMapName() + "\n";
97-
answer += "status: " + r.getStatus() + "\n\n";
98-
answer += "time passed since start" + new SimpleDateFormat("yyyy-MM-dd at HH-mm-ss").format(System.currentTimeMillis() - r.getStartTime());
121+
for (QueryRequest r: SpringClass.serviceInstance.getWORKER_LIST()) {
122+
answer += " - ID: " + r.getRequestedByID() + "\n";
123+
answer += " - requestName: " + r.getMapName() + "\n";
124+
answer += " - status: " + r.getStatus() + "\n";
125+
answer += " - time passed since start " + StaticVariables.formatDateTimeDif(r.getRequestTime(), LocalDateTime.now()) + "\n\n";
126+
}
127+
return answer;
128+
129+
case STATUS_DONE_KEY:
130+
answer += "current done requests : \n";
131+
for (QueryRequest r: SpringClass.serviceInstance.getDONE_LIST()) {
132+
answer += " - ID: " + r.getRequestedByID() + "\n";
133+
answer += " - requestName: " + r.getMapName() + "\n";
134+
answer += " - request Time" + r.getRequestTime() + "\n";
135+
answer += " - start Time: " + r.getRuntimeStart() + "\n";
136+
answer += " - end Time: " + r.getEndTime() + "\n\n";
137+
}
138+
return answer;
139+
140+
case STATUS_ERROR_KEY:
141+
answer += "current error requests : \n";
142+
for (QueryRequest r: SpringClass.serviceInstance.getERROR_LIST()) {
143+
answer += " - ID: " + r.getRequestedByID() + "\n";
144+
answer += " - requestName: " + r.getMapName() + "\n";
145+
answer += " - start Time: " + r.getRuntimeStart() + "\n";
146+
answer += " - end Time: " + r.getEndTime() + "\n";
147+
answer += " - error message: " + r.getErrorMessage() + "\n\n";
148+
}
149+
return answer;
150+
151+
case STATUS_BUFFER_KEY:
152+
answer += "current buffer requests : \n";
153+
int i = 0;
154+
for (QueryRequest r: SpringClass.serviceInstance.getBUFFER_LIST()) {
155+
i++;
156+
answer += " - ID: " + r.getRequestedByID() + "\n";
157+
answer += " - requestName: " + r.getMapName() + "\n";
158+
answer += " - request Time: " + r.getRequestTime() + "\n";
159+
answer += " - Query number: " + i + "\n\n";
99160
}
100161
return answer;
101162

102-
case "current log" :
163+
case ID_KEY :
164+
answer += "All IDs\n";
165+
answer += "-------------------------------\n";
166+
answer += IDSystem.getAllIDs();
167+
return answer;
168+
169+
case LOG_KEY :
103170
File loggerFile = Logger.instance.currentWritingFile;
104171
br = new BufferedReader(new InputStreamReader(new FileInputStream(loggerFile)));
105172
while (br.ready())
106173
answer += br.readLine() + "\n";
107174

108175
return answer;
109176

110-
case "daemon log" :
177+
case DAEMON_KEY :
111178
File daemonLogFile = new File("daemonLog.txt");
112179
br = new BufferedReader(new InputStreamReader(new FileInputStream(daemonLogFile)));
113180
while (br.ready())
114181
answer += br.readLine() + "\n";
115182

116183
return answer;
117184

118-
case "reload requestService":
185+
case RELOAD_S_KEY:
119186
return SpringClass.reloadRequestService();
120187

121-
case "reload log":
188+
case RELOAD_LOG_KEY:
122189
return SpringClass.reloadLog();
123190

124-
case "reload id":
191+
case RELOAD_ID_KEY:
125192
return SpringClass.reloadID();
126193

127-
case "restart":
194+
case CLEAR_BUFFER_LIST:
195+
return SpringClass.clearBuffer();
196+
197+
case CLEAN_ERROR_LIST:
198+
return SpringClass.cleanError();
199+
200+
case CLEAN_DONE_LIST:
201+
return SpringClass.cleanDone();
202+
203+
case RESTART_KEY:
128204
return SpringClass.restart();
129205

206+
case STOP_WORKER_LIST:
207+
return SpringClass.serviceInstance.stopRunningThread(0);
208+
209+
case "testRequest":
210+
return SpringClass.request("controllerRequest", "13.3772707,52.5092213_13.3772707,52.5245509_13.4065819,52.5245509_13.4065819,52.5092213_13.3772707,52.5092213", "2016-12-31", "CONTROLR");
211+
130212
default:
213+
// special requests with values attached to them
214+
String[] requestSplit = request.split(" ");
215+
if (requestSplit[0].equals("stop") && requestSplit[1].equals("worker"))
216+
if (requestSplit[2].equals("nr")) {
217+
int j;
218+
try { j = Integer.parseInt(requestSplit[3]); } catch (NumberFormatException e) { return requestSplit[3] + " is not a number..."; }
219+
return SpringClass.serviceInstance.stopRunningThread(j);
220+
}
131221
return "couldn't process request " + request;
132222
}
133223
}
134-
135224
private class ControllerRequest {
136225
String id;
137226
String value;
@@ -150,7 +239,6 @@ public String getReturnValue() {
150239
return returnValue;
151240
}
152241
}
153-
154242
@Override
155243
public synchronized void run() {
156244
while (true) {
Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
package Server.CustomObjects;
2-
3-
public class Coords {
4-
public Double x;
5-
public Double y;
6-
7-
public Coords(double x, double y) {
8-
this.x = x;
9-
this.y = y;
10-
}
11-
12-
@Override
13-
public String toString() {
14-
return String.valueOf(x + ' ' + y);
15-
}
16-
}
1+
package Server.CustomObjects;
2+
3+
import java.text.DecimalFormat;
4+
5+
public class Coords {
6+
public Double x;
7+
public Double y;
8+
9+
public Coords(double x, double y) {
10+
this.x = Double.valueOf(new DecimalFormat("##.#####").format(x).replaceAll(",", "."));
11+
this.y = Double.valueOf(new DecimalFormat("##.#####").format(y).replaceAll(",", "."));
12+
}
13+
14+
@Override
15+
public String toString() {
16+
return String.valueOf(x + ' ' + y);
17+
}
18+
}

0 commit comments

Comments
 (0)