-
Notifications
You must be signed in to change notification settings - Fork 555
Improve Session Management for Charge Point Connections #2908
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,8 +43,8 @@ public class MyJsonServer { | |
| /** | ||
| * The JSON OCPP server. | ||
| * | ||
| * <p> | ||
| * Responsible for sending and receiving OCPP JSON commands. | ||
| * | ||
| * <p>Responsible for sending and receiving OCPP JSON commands. | ||
| */ | ||
| private final JSONServer server; | ||
|
|
||
|
|
@@ -90,6 +90,23 @@ public void newSession(UUID sessionIndex, SessionInformation information) { | |
|
|
||
| var ocppIdentifier = information.getIdentifier().replace("/", ""); | ||
|
|
||
| // Check if there is already a session for this ocppIdentifier | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Over the weekend, we tested both our patch(#2908 (comment)) and this one, and both appeared to work properly. However, I’m concerned about the following point in this patch. What do you think?
|
||
| UUID oldSessionIndex = MyJsonServer.this.parent.ocppSessions.get(ocppIdentifier); | ||
| if (oldSessionIndex != null && !oldSessionIndex.equals(sessionIndex)) { | ||
| // Remove old session | ||
| MyJsonServer.this.logDebug("Removing old session [" + oldSessionIndex + "] for ocppIdentifier [" | ||
| + ocppIdentifier + "]"); | ||
| List<AbstractManagedOcppEvcsComponent> oldEvcss = MyJsonServer.this.parent.activeEvcsSessions | ||
| .get(oldSessionIndex); | ||
| if (oldEvcss != null) { | ||
| for (AbstractManagedOcppEvcsComponent ocppEvcs : oldEvcss) { | ||
| ocppEvcs.lostSession(); | ||
| } | ||
| MyJsonServer.this.parent.activeEvcsSessions.remove(oldSessionIndex); | ||
| } | ||
| } | ||
|
|
||
| // Update the ocppSessions with the new sessionIndex | ||
| MyJsonServer.this.parent.ocppSessions.put(ocppIdentifier, sessionIndex); | ||
|
|
||
| var presentEvcss = MyJsonServer.this.parent.ocppEvcss.get(ocppIdentifier); | ||
|
|
@@ -122,10 +139,16 @@ public void lostSession(UUID sessionIndex) { | |
| for (Entry<String, UUID> session : MyJsonServer.this.parent.ocppSessions.entrySet()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To address the issue mentioned below, we added the following changes. However, these modifications might not be necessary if our only concern is the brief window between establishing the new session and discarding the old one, as they make the code more complex.
if (sessionEvcss != null) {
for (AbstractManagedOcppEvcsComponent ocppEvcs : sessionEvcss) {
var ocppId = ocppEvcs.getConfiguredOcppId();
UUID latest = MyJsonServer.this.parent.ocppSessions.get(ocppId);
/**
* Since multiple sessions are connected with the same ocppId, if
* `lostSession` is executed with an old session, the `sessionId` of the
* component corresponding to the latest session would be set to null.
*/
if (latest != sessionIndex) {
MyJsonServer.this.logWarn("skip lostSession of old session [" + sessionIndex +
"] for ocppIdentifier [" + ocppId + "]");
continue;
}
ocppEvcs.lostSession();
MyJsonServer.this.logWarn("lostSession [" + sessionIndex + "] for ocppIdentifier [" + ocppId + "]");
}
MyJsonServer.this.parent.activeEvcsSessions.remove(sessionIndex);
MyJsonServer.this.logWarn("remove activeEvcsSessions [" + sessionIndex + "]");
} |
||
| if (session.getValue().equals(sessionIndex)) { | ||
| ocppId = session.getKey(); | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| MyJsonServer.this.parent.ocppSessions.remove(ocppId); | ||
| // Before removing, check if the sessionIndex is still the one mapped to ocppId | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code also deals with the window time between establishing the new session and discarding the old one inside |
||
| UUID currentSessionIndex = MyJsonServer.this.parent.ocppSessions.get(ocppId); | ||
| if (currentSessionIndex != null && currentSessionIndex.equals(sessionIndex)) { | ||
| MyJsonServer.this.parent.ocppSessions.remove(ocppId); | ||
| } | ||
|
|
||
| MyJsonServer.this.parent.activeEvcsSessions.remove(sessionIndex); | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In actual production environments, we rarely remove components, so we went ahead with weekend testing without including this commit. However, I don’t see any issues with the code itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you maybe still test it ?