// private CmsUserManager cmsUserManager;
// TODO make more optimal or via CmsSession/CmsView
- private Timer janitorTimer = new Timer(true);
+ private static Timer janitorTimer = new Timer(true);
private Map<String, WeakReference<SwtAppUi>> managedUis = new HashMap<>();
// ACR
Objects.requireNonNull(appUserState, "App user state must be provided");
long janitorPeriod = 60 * 60 * 1000;// 1h
+ // long janitorPeriod = 60 * 1000;// min
janitorTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
- Iterator<WeakReference<SwtAppUi>> uiRefs = managedUis.values().iterator();
+ // copy Map in order to avoid concurrent modification exception
+ Iterator<Map.Entry<String, WeakReference<SwtAppUi>>> uiRefs = new HashMap<>(managedUis).entrySet()
+ .iterator();
refs: while (uiRefs.hasNext()) {
- WeakReference<SwtAppUi> uiRef = uiRefs.next();
+ Map.Entry<String, WeakReference<SwtAppUi>> entry = uiRefs.next();
+ String uiUuid = entry.getKey();
+ WeakReference<SwtAppUi> uiRef = entry.getValue();
SwtAppUi ui = uiRef.get();
if (ui == null) {
if (log.isTraceEnabled())
- log.warn("Unreferenced UI in " + appPid + ", removing it");
- uiRefs.remove();
+ log.warn("Unreferenced UI " + uiUuid + " in " + appPid + ", removing it");
+ managedUis.remove(uiUuid);
continue refs;
}
if (!ui.isDisposed() && !ui.getDisplay().isDisposed()) {
- ui.getDisplay().asyncExec(() -> {
- ui.disposeIfTimedout();
- });
- ui.getDisplay().wake();
+ if (ui.isTimedOut()) {
+ if (log.isTraceEnabled())
+ log.trace("Killing timed-out UI " + uiUuid + " in " + appPid);
+ UiContext.killDisplay(ui.getDisplay());
+ }
+ } else {
+ if (log.isTraceEnabled())
+ log.warn("Disposed UI " + uiUuid + " still referenced in " + appPid + ", removing it");
+ managedUis.remove(uiUuid);
}
}
if (log.isTraceEnabled())
log.trace(managedUis.size() + " UIs being managed by app " + appPid);
} catch (Exception e) {
- e.printStackTrace();
+ log.error("Could not clean up timed-out UIs", e);
}
}
}, janitorPeriod, janitorPeriod);
CmsSwtUtils.registerCmsTheme(uiParent.getShell(), theme);
SwtAppUi argeoSuiteUi = new SwtAppUi(uiParent, SWT.INHERIT_DEFAULT);
// TODO make timeout configurable
- argeoSuiteUi.setUiTimeout(12 * 60 * 60 * 1000);// 12 hours
+ argeoSuiteUi.setUiTimeout(6 * 60 * 60 * 1000);// 6 hours
+ // argeoSuiteUi.setUiTimeout(60 * 1000);// 1 min
String uid = cmsView.getUid();
argeoSuiteUi.addDisposeListener(new CleanUpUi(uid));
managedUis.put(uid, new WeakReference<>(argeoSuiteUi));
// }
}
-// private static String listTypes(Node context) {
-// try {
-// StringBuilder sb = new StringBuilder();
-// sb.append(context.getPrimaryNodeType().getName());
-// for (NodeType superType : context.getPrimaryNodeType().getDeclaredSupertypes()) {
-// sb.append(' ');
-// sb.append(superType.getName());
-// }
-//
-// for (NodeType nodeType : context.getMixinNodeTypes()) {
-// sb.append(' ');
-// sb.append(nodeType.getName());
-// if (nodeType.getName().equals(EntityType.local.get()))
-// sb.append('/').append(context.getProperty(EntityNames.ENTITY_TYPE).getString());
-// for (NodeType superType : nodeType.getDeclaredSupertypes()) {
-// sb.append(' ');
-// sb.append(superType.getName());
-// }
-// }
-// return sb.toString();
-// } catch (RepositoryException e) {
-// throw new JcrException(e);
-// }
-// }
-
@Override
public void setState(CmsUi cmsUi, String state) {
AppUi ui = (AppUi) cmsUi;
if (state == null)
return;
if (!state.startsWith("/")) {
-// if (cmsUi instanceof SwtAppUi) {
-// SwtAppUi ui = (SwtAppUi) cmsUi;
if (LOGIN.equals(state)) {
String appTitle = "";
if (ui.getTitle() != null)
properties.put(SuiteUxEvent.LAYER, layerId);
properties.put(SuiteUxEvent.CONTENT_PATH, HOME_STATE);
ui.getCmsView().sendEvent(SuiteUxEvent.switchLayer.topic(), properties);
-// }
return;
}
-// SwtAppUi suiteUi = (SwtAppUi) cmsUi;
if (ui.isLoginScreen()) {
return;
}
ui.getCmsView().stateChanged(nodeToState(node), stateTitle(appTitle, CmsUxUtils.getTitle(node)));
} else if (isTopic(topic, SuiteUxEvent.switchLayer)) {
String layerId = get(event, SuiteUxEvent.LAYER);
- if (layerId != null) {
+ if (layerId != null && !"".equals(layerId.trim())) {
SwtAppLayer suiteLayer = findLayer(layerId);
if (suiteLayer == null)
throw new IllegalArgumentException("No layer '" + layerId + "' available.");