Erweiterungen
This commit is contained in:
@@ -133,6 +133,10 @@ public class LoginView extends VerticalLayout {
|
||||
Application.activeSessions.put(sessionId, niederlassung);
|
||||
Application.activeNiederlassungen.put(niederlassung, sessionId);
|
||||
|
||||
// Log that Niederlassung is now blocked
|
||||
logger.info("Niederlassung '{}' wurde gesperrt für Session {}", niederlassung, sessionId);
|
||||
logger.info("Aktive Niederlassungen: {}", Application.activeNiederlassungen.keySet());
|
||||
|
||||
// Spring Security Authentifizierung setzen
|
||||
var authorities = List.of(new SimpleGrantedAuthority("ROLE_USER"));
|
||||
var authentication = new UsernamePasswordAuthenticationToken(Application.SINGLE_USERNAME, password, authorities);
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.vaadin.flow.component.UI;
|
||||
import com.vaadin.flow.component.html.Main;
|
||||
import com.vaadin.flow.router.Route;
|
||||
import com.vaadin.flow.server.auth.AnonymousAllowed;
|
||||
import com.vaadin.flow.server.VaadinSession;
|
||||
import de.assecutor.emulatorstation.pojo.ExecResponse;
|
||||
import de.assecutor.emulatorstation.pojo.NiederlassungInfo;
|
||||
import de.assecutor.emulatorstation.Application;
|
||||
@@ -79,7 +80,76 @@ public final class MainView extends Main implements BeforeEnterObserver
|
||||
setupButtonLayout(contentContainer);
|
||||
|
||||
add(contentContainer);
|
||||
addAttachListener(event -> loadSessionData());
|
||||
addAttachListener(event -> {
|
||||
loadSessionData();
|
||||
setupSessionCleanupListener();
|
||||
});
|
||||
|
||||
// Add detach listener to cleanup resources when view is detached
|
||||
addDetachListener(event -> {
|
||||
logger.info("MainView detached - cleaning up resources");
|
||||
cleanupResources();
|
||||
});
|
||||
}
|
||||
|
||||
private void setupSessionCleanupListener() {
|
||||
VaadinSession session = VaadinSession.getCurrent();
|
||||
if (session != null) {
|
||||
session.addSessionDestroyListener(event -> {
|
||||
logger.info("Session destroy event triggered - cleaning up resources");
|
||||
// Cleanup will be done in a background thread to avoid blocking
|
||||
executor.submit(() -> {
|
||||
try {
|
||||
cleanupResources();
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error during session cleanup", ex);
|
||||
}
|
||||
});
|
||||
});
|
||||
logger.info("Session cleanup listener registered for session: {}", session.getSession().getId());
|
||||
}
|
||||
}
|
||||
|
||||
private void cleanupResources() {
|
||||
try {
|
||||
logger.info("Starting resource cleanup");
|
||||
|
||||
// Get session information before cleanup
|
||||
String sessionId = null;
|
||||
String niederlassungName = null;
|
||||
|
||||
if (getUI().isPresent()) {
|
||||
VaadinSession session = getUI().get().getSession();
|
||||
if (session != null) {
|
||||
sessionId = (String) session.getAttribute("sessionId");
|
||||
if (niederlassung != null) {
|
||||
niederlassungName = niederlassung.name();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown containers
|
||||
logger.info("Shutting down containers for niederlassung: {}", niederlassungName);
|
||||
shutdown();
|
||||
|
||||
// Remove from active sessions and niederlassungen
|
||||
if (sessionId != null) {
|
||||
Application.activeSessions.remove(sessionId);
|
||||
logger.info("Session {} removed from active sessions", sessionId);
|
||||
}
|
||||
|
||||
if (niederlassungName != null) {
|
||||
Application.activeNiederlassungen.remove(niederlassungName);
|
||||
logger.info("Niederlassung '{}' wurde freigegeben und ist wieder verfügbar für neue Anmeldungen", niederlassungName);
|
||||
logger.info("Aktive Niederlassungen nach Freigabe: {}", Application.activeNiederlassungen.keySet());
|
||||
}
|
||||
|
||||
logger.info("Resource cleanup completed successfully");
|
||||
logger.info("Active sessions after cleanup: {}/{}", Application.activeSessions.size(), Application.MAX_ACTIVE_SESSIONS);
|
||||
|
||||
} catch (Exception ex) {
|
||||
logger.error("Error during resource cleanup", ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupInactivityTimer() {
|
||||
|
||||
Reference in New Issue
Block a user