REO progress

This commit is contained in:
rusefi 2020-08-14 21:10:30 -04:00
parent e86606e38f
commit d11ee07e25
2 changed files with 47 additions and 2 deletions

View File

@ -59,7 +59,7 @@ public class Backend implements Closeable {
*/
private static final int APPLICATION_INACTIVITY_TIMEOUT = 3 * Timeouts.MINUTE;
static final String AGE = "age";
private static final ThreadFactory APPLLICATION_CONNECTION_CLEANUP = new NamedThreadFactory("rusEFI Application connections Cleanup");
private static final ThreadFactory APPLICATION_CONNECTION_CLEANUP = new NamedThreadFactory("rusEFI Application connections Cleanup");
private static final ThreadFactory GAUGE_POKER = new NamedThreadFactory("rusEFI gauge poker");
private final FkRegex showOnlineControllers = new FkRegex(ProxyClient.LIST_CONTROLLERS_PATH,
@ -107,6 +107,7 @@ public class Backend implements Closeable {
showOnlineApplications,
new Monitoring(this).showStatistics,
new FkRegex(ProxyClient.VERSION_PATH, ProxyClient.BACKEND_VERSION),
new FkRegex("/update", new UpdateRequestHandler()),
new FkRegex("/", new RsHtml("<html><body>\n" +
"<br/><a href='https://rusefi.com/online/'>rusEFI Online</a>\n" +
"<br/><br/><br/>\n" +
@ -130,7 +131,7 @@ public class Backend implements Closeable {
}, "Http Server Thread").start();
APPLLICATION_CONNECTION_CLEANUP.newThread(() -> {
APPLICATION_CONNECTION_CLEANUP.newThread(() -> {
while (!isClosed()) {
log.info(getApplicationsCount() + " applications, " + getControllersCount() + " controllers");
runApplicationConnectionsCleanup();

View File

@ -0,0 +1,44 @@
package com.rusefi.server;
import com.devexperts.logging.Logging;
import org.takes.Request;
import org.takes.Response;
import org.takes.Take;
import org.takes.rq.RqForm;
import org.takes.rq.form.RqFormBase;
import org.takes.rs.RsJson;
import javax.json.Json;
import javax.json.JsonObjectBuilder;
import java.io.IOException;
import static com.devexperts.logging.Logging.getLogging;
public class UpdateRequestHandler implements Take {
private static final Logging log = getLogging(UpdateRequestHandler.class);
private static final String AUTH_TOKEN = "auth_token";
private static final String VEHICLE_TOKEN = "vehicle_token";
@Override
public Response act(Request req) throws IOException {
JsonObjectBuilder objectBuilder = Json.createObjectBuilder();
try {
RqForm rqForm = new RqFormBase(req);
String authToken = get(rqForm, AUTH_TOKEN);
String vehicleToken = get(rqForm, VEHICLE_TOKEN);
log.debug("Update request " + authToken + " " + vehicleToken);
} catch (IOException e) {
objectBuilder.add("result", "error");
return new RsJson(objectBuilder.build());
}
objectBuilder.add("result", "OK");
return new RsJson(objectBuilder.build());
}
private String get(RqForm rqForm, String name) throws IOException {
return rqForm.param(name).iterator().next();
}
}