Skip to content

Commit

Permalink
remove tabs immediately for clarity; closes #1046
Browse files Browse the repository at this point in the history
  • Loading branch information
jflamy committed Jul 20, 2024
1 parent 1e3574c commit e1dcc4e
Showing 1 changed file with 31 additions and 35 deletions.
66 changes: 31 additions & 35 deletions publicresults/src/main/java/app/owlcms/prutils/SessionCleanup.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,46 +43,44 @@ public void cleanupSession() {
Map<UnloadObserverPR, Long> im = (Map<UnloadObserverPR, Long>) vaadinSession.getAttribute("inactivityMap");
int stillAlive = 0;
if (im != null) {
if (im.entrySet().isEmpty()) {
// // the previous iteration cleaned the map and navigated out of the pages.
// // because of asynchronicity, we wait to the following iteration before closing
// // sessions.
// logger.debug("invalidating session {}", System.identityHashCode(vaadinSession));
// vaadinSession.getSession().invalidate();
// vaadinSession.close();
// stop();
} else {
long now = System.currentTimeMillis();
logger.debug("checking session {}", System.identityHashCode(vaadinSession));
for (Entry<UnloadObserverPR, Long> uiEntry : im.entrySet()) {
if (uiEntry.getValue() == 0) {
// 0 means GONE.
logger.debug(" {} tab {} gone", uiEntry.getKey().getTitle(), System.identityHashCode(uiEntry.getKey()));
} else {
// positive means visible, negative means hidden (don't kill)
long timeElapsed = now - Math.abs(uiEntry.getValue());
long now = System.currentTimeMillis();
logger.debug("checking session {}", System.identityHashCode(vaadinSession));

// Define OWLCMS_INACTIVITY_SEC for testing
var inactivity = StartupUtils.getIntegerParam("inactivity_sec", INACTIVITY_SECONDS) * 1000;
boolean alive = timeElapsed < inactivity;
Component component = uiEntry.getKey().getComponent();
logger.debug(" {} observer {} {} {} timeElapsed={} alive={}",
uiEntry.getKey().getTitle(),
System.identityHashCode(uiEntry.getKey()),
component.getClass().getSimpleName(),
System.identityHashCode(component),
timeElapsed, alive);
if (alive) {
stillAlive++;
}
Iterator<Entry<UnloadObserverPR, Long>> entryIterator = im.entrySet().iterator();
while (entryIterator.hasNext()) {
var uiEntry = entryIterator.next();
if (uiEntry.getValue() == 0) {
// 0 means GONE.
logger.debug(" {} tab {} gone", uiEntry.getKey().getTitle(),
System.identityHashCode(uiEntry.getKey()));
entryIterator.remove();
} else {
// positive means visible, negative means hidden (don't kill)
long timeElapsed = now - Math.abs(uiEntry.getValue());

// Define OWLCMS_INACTIVITY_SEC for testing
var inactivity = StartupUtils.getIntegerParam("inactivity_sec", INACTIVITY_SECONDS) * 1000;
boolean alive = timeElapsed < inactivity;
Component component = uiEntry.getKey().getComponent();
logger.debug(" {} observer {} {} {} timeElapsed={} alive={}",
uiEntry.getKey().getTitle(),
System.identityHashCode(uiEntry.getKey()),
component.getClass().getSimpleName(),
System.identityHashCode(component),
timeElapsed, alive);
if (alive) {
stillAlive++;
}
}
logger.debug(" stillAlive={}", stillAlive);
}
logger.debug(" stillAlive={}", stillAlive);
} else {
logger.error("no registered map");
}

// if all tabs are expired, force them to leave taking care to not reset the Vaadin
// session (which would cause an immediate reload)
// show a reload button so the user can come back.
if (stillAlive == 0) {
Iterator<Entry<UnloadObserverPR, Long>> entryIterator = im.entrySet().iterator();
while (entryIterator.hasNext()) {
Expand All @@ -94,7 +92,6 @@ public void cleanupSession() {
System.identityHashCode(ui),
eventObserver2.getUrl());
if (ui.isAttached()) {
// ui.access(() -> {
String title = eventObserver2.getTitle();
Set<String> fopNames = UpdateReceiverServlet.getUpdateCache().keySet();
if (eventObserver2.getComponent() instanceof MainView || fopNames.size() <= 1) {
Expand All @@ -103,9 +100,8 @@ public void cleanupSession() {
eventObserver2.doReload(
Translator.translate("PublicResults.sessionExpiredTitle"),
Translator.translate("PublicResults.sessionExpiredText"),
Translator.translate("PublicResults.sessionExpiredLabel",title).trim(),
Translator.translate("PublicResults.sessionExpiredLabel", title).trim(),
eventObserver2.getUrl().toExternalForm());
// });
}
entryIterator.remove();
}
Expand Down

0 comments on commit e1dcc4e

Please sign in to comment.