Skip to content
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

Improve Session Management for Charge Point Connections #2908

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,33 @@ protected void removeEvcs(Evcs evcs) {
return;
}
var ocppEvcs = (AbstractManagedOcppEvcsComponent) evcs;
var evcss = this.activeEvcsSessions.get(ocppEvcs.getSessionId());
if (evcss != null) {
if (evcss.size() < 2) {
this.activeEvcsSessions.remove(ocppEvcs.getSessionId());
} else {
this.activeEvcsSessions.get(ocppEvcs.getSessionId()).remove(ocppEvcs);
var sessionId = ocppEvcs.getSessionId();
if (sessionId != null) {
var evcss = this.activeEvcsSessions.get(sessionId);
if (evcss != null) {
evcss.remove(ocppEvcs);
if (evcss.isEmpty()) {
this.activeEvcsSessions.remove(sessionId);
// Also remove from ocppSessions if needed
Sn0w3y marked this conversation as resolved.
Show resolved Hide resolved
var ocppIdToRemove = "";
for (Entry<String, UUID> entry : this.ocppSessions.entrySet()) {
if (entry.getValue().equals(sessionId)) {
ocppIdToRemove = entry.getKey();
break;
}
}
if (!ocppIdToRemove.isEmpty()) {
this.ocppSessions.remove(ocppIdToRemove);
}
}
}
}
this.ocppEvcss.remove(ocppEvcs.getConfiguredOcppId());
ocppEvcs.lostSession();
}

public EvcsOcppServer() {
super(OpenemsComponent.ChannelId.values() //
);
super(OpenemsComponent.ChannelId.values());
}

@Activate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Sn0w3y marked this conversation as resolved.
Show resolved Hide resolved
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);
Expand Down Expand Up @@ -122,10 +139,16 @@ public void lostSession(UUID sessionIndex) {
for (Entry<String, UUID> session : MyJsonServer.this.parent.ocppSessions.entrySet()) {
Sn0w3y marked this conversation as resolved.
Show resolved Hide resolved
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
Sn0w3y marked this conversation as resolved.
Show resolved Hide resolved
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);
}

Expand Down
Loading