more, more logs!
This commit is contained in:
parent
d225b6bd54
commit
ec2accd9d7
|
@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import static com.devexperts.logging.Logging.getLogging;
|
import static com.devexperts.logging.Logging.getLogging;
|
||||||
import static com.rusefi.Timeouts.SECOND;
|
import static com.rusefi.Timeouts.SECOND;
|
||||||
|
import static com.rusefi.server.Birthday.humanReadableFormat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* See NetworkConnectorStartup - NetworkConnector connects an ECU to this backend
|
* See NetworkConnectorStartup - NetworkConnector connects an ECU to this backend
|
||||||
|
@ -254,6 +255,7 @@ public class Backend implements Closeable {
|
||||||
|
|
||||||
register(controllerConnectionState);
|
register(controllerConnectionState);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
log.error("runControllerConnector close " + controllerConnectionState, e);
|
||||||
close(controllerConnectionState);
|
close(controllerConnectionState);
|
||||||
}
|
}
|
||||||
}, serverPortForControllers, "ControllerServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY);
|
}, serverPortForControllers, "ControllerServer", serverSocketCreationCallback, BinaryProtocolServer.SECURE_SOCKET_FACTORY);
|
||||||
|
@ -323,13 +325,13 @@ public class Backend implements Closeable {
|
||||||
applications = new ArrayList<>(this.applications);
|
applications = new ArrayList<>(this.applications);
|
||||||
}
|
}
|
||||||
|
|
||||||
long now = System.currentTimeMillis();
|
|
||||||
for (ApplicationConnectionState client : applications) {
|
for (ApplicationConnectionState client : applications) {
|
||||||
if (now - client.getClientStream().getStreamStats().getPreviousPacketArrivalTime() > applicationTimeout) {
|
long timeSinceLastActivity = System.currentTimeMillis() - client.getClientStream().getStreamStats().getPreviousPacketArrivalTime();
|
||||||
|
if (timeSinceLastActivity > applicationTimeout) {
|
||||||
log.error("Kicking out application " + client);
|
log.error("Kicking out application " + client);
|
||||||
close(client);
|
close(client);
|
||||||
} else {
|
} else {
|
||||||
log.info("Looks alive " + client);
|
log.info("Looks alive " + client + " time since last activity: " + humanReadableFormat(timeSinceLastActivity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,7 +341,8 @@ public class Backend implements Closeable {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ControllerConnectionState controllerConnectionState : controllers) {
|
for (ControllerConnectionState controllerConnectionState : controllers) {
|
||||||
log.info("State: " + controllerConnectionState);
|
long timeSinceLastActivity = System.currentTimeMillis() - controllerConnectionState.getStream().getStreamStats().getPreviousPacketArrivalTime();
|
||||||
|
log.info("State: " + controllerConnectionState + " time since last activity: " + humanReadableFormat(timeSinceLastActivity));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -137,6 +137,7 @@ public class ControllerConnectionState {
|
||||||
getOutputs();
|
getOutputs();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
// todo: this is currently not covered by a unit test
|
// todo: this is currently not covered by a unit test
|
||||||
|
log.error("grabOutputs " + this, e);
|
||||||
backend.close(this);
|
backend.close(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.rusefi.server;
|
package com.rusefi.server;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
import com.rusefi.tools.online.HttpUtil;
|
import com.rusefi.tools.online.HttpUtil;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.json.simple.JSONObject;
|
import org.json.simple.JSONObject;
|
||||||
|
@ -8,6 +9,8 @@ import org.json.simple.parser.ParseException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class JsonUserDetailsResolver implements UserDetailsResolver {
|
public class JsonUserDetailsResolver implements UserDetailsResolver {
|
||||||
|
private final static Logging log = Logging.getLogging(JsonUserDetailsResolver.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public UserDetails apply(String authToken) {
|
public UserDetails apply(String authToken) {
|
||||||
|
@ -15,10 +18,10 @@ public class JsonUserDetailsResolver implements UserDetailsResolver {
|
||||||
try {
|
try {
|
||||||
String responseString = HttpUtil.executeGet(HttpUtil.RUSEFI_ONLINE_JSON_API_PREFIX + "getUserByToken&rusefi_token=" + authToken);
|
String responseString = HttpUtil.executeGet(HttpUtil.RUSEFI_ONLINE_JSON_API_PREFIX + "getUserByToken&rusefi_token=" + authToken);
|
||||||
JSONObject json = HttpUtil.getJsonResponse(responseString);
|
JSONObject json = HttpUtil.getJsonResponse(responseString);
|
||||||
System.out.println("String " + json);
|
log.info("String " + json);
|
||||||
Object getUserByToken = json.get("getUserByToken");
|
Object getUserByToken = json.get("getUserByToken");
|
||||||
if (getUserByToken instanceof String) {
|
if (getUserByToken instanceof String) {
|
||||||
System.out.println("AUTH FAILED: Result " + getUserByToken);
|
log.info("AUTH FAILED: Result " + getUserByToken);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JSONObject details = (JSONObject) getUserByToken;
|
JSONObject details = (JSONObject) getUserByToken;
|
||||||
|
@ -26,10 +29,10 @@ public class JsonUserDetailsResolver implements UserDetailsResolver {
|
||||||
String name = (String) details.get("NAME");
|
String name = (String) details.get("NAME");
|
||||||
|
|
||||||
UserDetails result = new UserDetails(name, Integer.parseInt(id));
|
UserDetails result = new UserDetails(name, Integer.parseInt(id));
|
||||||
System.out.println("AUTH SUCCESS " + result);
|
log.info("AUTH SUCCESS " + result);
|
||||||
return result;
|
return result;
|
||||||
} catch (IOException | ParseException e) {
|
} catch (IOException | ParseException e) {
|
||||||
System.out.println("JsonUserDetailsResolver error" + e);
|
log.error("JsonUserDetailsResolver error" + e);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,13 @@
|
||||||
package com.rusefi.server;
|
package com.rusefi.server;
|
||||||
|
|
||||||
|
import com.devexperts.logging.Logging;
|
||||||
|
|
||||||
import java.util.concurrent.Semaphore;
|
import java.util.concurrent.Semaphore;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class TwoKindSemaphore {
|
public class TwoKindSemaphore {
|
||||||
|
private final static Logging log = Logging.getLogging(TwoKindSemaphore.class);
|
||||||
|
|
||||||
// we have to distinguish between long-term usage by application and short-term usage just to refresh gauges
|
// we have to distinguish between long-term usage by application and short-term usage just to refresh gauges
|
||||||
private final static int LONG_TERM = 2;
|
private final static int LONG_TERM = 2;
|
||||||
private final static int SHORT_TERM = 1;
|
private final static int SHORT_TERM = 1;
|
||||||
|
@ -11,6 +15,7 @@ public class TwoKindSemaphore {
|
||||||
private UserDetails owner;
|
private UserDetails owner;
|
||||||
|
|
||||||
public void releaseFromLongTermUsage() {
|
public void releaseFromLongTermUsage() {
|
||||||
|
log.info("release " + owner);
|
||||||
semaphore.release(LONG_TERM);
|
semaphore.release(LONG_TERM);
|
||||||
// not atomic but that's fine, isUsed is the source of truth
|
// not atomic but that's fine, isUsed is the source of truth
|
||||||
owner = null;
|
owner = null;
|
||||||
|
|
Loading…
Reference in New Issue