[Minor] Code formatting

This commit is contained in:
Robert von Burg 2023-07-24 13:35:30 +02:00
parent 17df054aae
commit aa358b40e5
Signed by: eitch
GPG Key ID: 75DB9C85C74331F7
1 changed files with 21 additions and 22 deletions

View File

@ -179,10 +179,10 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
if (rootCause.getMessage() != null && rootCause.getMessage().contains("Connection refused")) { if (rootCause.getMessage() != null && rootCause.getMessage().contains("Connection refused")) {
logger.error( logger.error(
"Connection refused to connect to server. Will try to connect again in " + RETRY_DELAY + "s: " "Connection refused to connect to server. Will try to connect again in " + RETRY_DELAY + "s: " +
+ getExceptionMessageWithCauses(e)); getExceptionMessageWithCauses(e));
} else if (rootCause.getMessage() != null && rootCause.getMessage() } else if (rootCause.getMessage() != null &&
.contains("Response code was not 101: 404.")) { rootCause.getMessage().contains("Response code was not 101: 404.")) {
logger.error("Connection failed with 404 error code. Is URL " + this.gwServerUrl + " correct?"); logger.error("Connection failed with 404 error code. Is URL " + this.gwServerUrl + " correct?");
logger.error("Server not yet ready with 404 error. Will try again in " + RETRY_DELAY + "s"); logger.error("Server not yet ready with 404 error. Will try again in " + RETRY_DELAY + "s");
} else { } else {
@ -190,8 +190,8 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
} }
closeBrokenGwSessionUpdateState("Failed to connect to server", closeBrokenGwSessionUpdateState("Failed to connect to server",
"Connection refused to connect to server. Will try to connect again in " + RETRY_DELAY + "s: " "Connection refused to connect to server. Will try to connect again in " + RETRY_DELAY + "s: " +
+ getExceptionMessageWithCauses(e)); getExceptionMessageWithCauses(e));
delayConnect(RETRY_DELAY, TimeUnit.SECONDS); delayConnect(RETRY_DELAY, TimeUnit.SECONDS);
return; return;
} }
@ -440,8 +440,8 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
sendDataToClient(telegramJ); sendDataToClient(telegramJ);
if (this.verbose) if (this.verbose)
logger.info("Sent Telegram response for " + (plcAddress == null ? "unknown" : plcAddress.toKey()) logger.info("Sent Telegram response for " + (plcAddress == null ? "unknown" : plcAddress.toKey()) +
+ " to server"); " to server");
} }
private void handleAuthResponse(PrivilegeContext ctx, JsonObject response) { private void handleAuthResponse(PrivilegeContext ctx, JsonObject response) {
@ -449,12 +449,12 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
if (!response.has(PARAM_STATE) || !response.has(PARAM_STATE_MSG) || !response.has(PARAM_AUTH_TOKEN)) { if (!response.has(PARAM_STATE) || !response.has(PARAM_STATE_MSG) || !response.has(PARAM_AUTH_TOKEN)) {
closeBrokenGwSessionUpdateState(ctx, "Auth failed!", closeBrokenGwSessionUpdateState(ctx, "Auth failed!",
"Failed to authenticated with Server: At least one of " + PARAM_STATE + ", " + PARAM_STATE_MSG "Failed to authenticated with Server: At least one of " + PARAM_STATE + ", " + PARAM_STATE_MSG +
+ ", " + PARAM_AUTH_TOKEN + " params is missing on Auth Response"); ", " + PARAM_AUTH_TOKEN + " params is missing on Auth Response");
throw new IllegalStateException( throw new IllegalStateException(
"Failed to authenticated with Server: At least one of " + PARAM_STATE + ", " + PARAM_STATE_MSG "Failed to authenticated with Server: At least one of " + PARAM_STATE + ", " + PARAM_STATE_MSG +
+ ", " + PARAM_AUTH_TOKEN + " params is missing on Auth Response"); ", " + PARAM_AUTH_TOKEN + " params is missing on Auth Response");
} }
if (PlcResponseState.valueOf(response.get(PARAM_STATE).getAsString()) != PlcResponseState.Sent) { if (PlcResponseState.valueOf(response.get(PARAM_STATE).getAsString()) != PlcResponseState.Sent) {
@ -493,13 +493,13 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
public void onWsClose(Session session, CloseReason closeReason) { public void onWsClose(Session session, CloseReason closeReason) {
this.authenticated = false; this.authenticated = false;
logger.info("Session closed with ID " + session.getId() + " due to " + closeReason.getCloseCode() + " " logger.info("Session closed with ID " + session.getId() + " due to " + closeReason.getCloseCode() + " " +
+ closeReason.getReasonPhrase() + ". Reconnecting in " + RETRY_DELAY + "s."); closeReason.getReasonPhrase() + ". Reconnecting in " + RETRY_DELAY + "s.");
if (this.gwSession != null) { if (this.gwSession != null) {
closeBrokenGwSessionUpdateState(closeReason.getReasonPhrase(), closeBrokenGwSessionUpdateState(closeReason.getReasonPhrase(),
"Session closed with ID " + session.getId() + " due to " + closeReason.getCloseCode() + " " "Session closed with ID " + session.getId() + " due to " + closeReason.getCloseCode() + " " +
+ closeReason.getReasonPhrase() + ". Reconnecting in " + RETRY_DELAY + "s."); closeReason.getReasonPhrase() + ". Reconnecting in " + RETRY_DELAY + "s.");
} }
delayConnect(RETRY_DELAY, TimeUnit.SECONDS); delayConnect(RETRY_DELAY, TimeUnit.SECONDS);
@ -583,18 +583,17 @@ public class PlcGwClientHandler extends StrolchComponent implements GlobalPlcLis
VersionQueryResult versionQueryResult = getContainer().getAgent().getVersion(); VersionQueryResult versionQueryResult = getContainer().getAgent().getVersion();
this.versions.add(AGENT_VERSION, versionQueryResult.getAgentVersion().toJson()); this.versions.add(AGENT_VERSION, versionQueryResult.getAgentVersion().toJson());
this.versions.add(APP_VERSION, versionQueryResult.getAppVersion().toJson()); this.versions.add(APP_VERSION, versionQueryResult.getAppVersion().toJson());
this.versions.add(COMPONENT_VERSIONS, versionQueryResult.getComponentVersions() this.versions.add(COMPONENT_VERSIONS,
.stream() versionQueryResult.getComponentVersions().stream().map(ComponentVersion::toJson)
.map(ComponentVersion::toJson) .collect(JsonArray::new, JsonArray::add, JsonArray::addAll));
.collect(JsonArray::new, JsonArray::add, JsonArray::addAll));
} }
return this.versions; return this.versions;
} }
public JsonArray getIpAddresses() { public JsonArray getIpAddresses() {
if (this.ipAddresses == null || this.ipAddresses.size() == 0 || ( if (this.ipAddresses == null || this.ipAddresses.size() == 0 ||
System.currentTimeMillis() - this.ipAddressesUpdateTime > 10000L)) { (System.currentTimeMillis() - this.ipAddressesUpdateTime > 10000L)) {
try { try {
this.ipAddresses = NetworkHelper.findInet4Addresses().stream().map(add -> { this.ipAddresses = NetworkHelper.findInet4Addresses().stream().map(add -> {
String mac; String mac;