/** * @deprecated As of 7.1. See #11410. */ @Deprecated public ClientCache getClientCache(UI uI) { Integer uiId = Integer.valueOf(uI.getUIId()); ClientCache cache = uiToClientCache.get(uiId); if (cache == null) { cache = new ClientCache(); uiToClientCache.put(uiId, cache); } return cache; }
/** * Gets a global URI for a resource if it's registered with this handler. * * @param connector * the connector for which the uri should be generated. * @param resource * the resource for which the uri should be generated. * @return an URI string, or <code>null</code> if the resource is not * registered. */ public String getUri(ClientConnector connector, ConnectorResource resource) { // app://APP/global/[ui]/[type]/[id] String uri = legacyResourceKeys.get(resource); if (uri != null && !uri.isEmpty()) { return ApplicationConstants.APP_PROTOCOL_PREFIX + ApplicationConstants.APP_PATH + '/' + RESOURCE_REQUEST_PATH + connector.getUI().getUIId() + '/' + uri; } else { return null; } }
/** * Called by the framework to remove an UI instance from the session because * it has been closed. * * @param ui * the UI to remove */ public void removeUI(UI ui) { assert hasLock() : "Session is locked"; assert UI.getCurrent() != null : "Current UI cannot be null"; assert ui != null : "Removed UI cannot be null"; assert UI.getCurrent().getUIId() == ui.getUIId() : "UIs don't match"; Integer id = Integer.valueOf(ui.getUIId()); ui.setSession(null); uIs.remove(id); String embedId = ui.getEmbedId(); if (embedId != null && id.equals(embedIdMap.get(embedId))) { embedIdMap.remove(embedId); } }
/** * Adds an initialized UI to this session. * * @param ui * the initialized UI to add. */ public void addUI(UI ui) { assert hasLock(); if (ui.getUIId() == -1) { throw new IllegalArgumentException( "Can not add an UI that has not been initialized."); } if (ui.getSession() != this) { throw new IllegalArgumentException( "The UI belongs to a different session"); } Integer uiId = Integer.valueOf(ui.getUIId()); uIs.put(uiId, ui); String embedId = ui.getEmbedId(); if (embedId != null) { Integer previousUiId = embedIdMap.put(embedId, uiId); if (previousUiId != null) { UI previousUi = uIs.get(previousUiId); assert previousUi != null && embedId.equals(previousUi .getEmbedId()) : "UI id map and embed id map not in sync"; // Will fire cleanup events at the end of the request handling. previousUi.close(); } } }
/** * Hack used to return existing LegacyWindow instances without regard for * out-of-sync problems. * * @param event * @return */ public UI getExistingUI(UIClassSelectionEvent event) { UI uiInstance = getUIInstance(event); if (uiInstance == null || uiInstance.getUIId() == -1) { // Not initialized -> Let go through createUIInstance to make it // initialized return null; } else { UI.setCurrent(uiInstance); return uiInstance; } }
private static String getConnectorResourceBase(String filename, ClientConnector connector) { String uri = ApplicationConstants.APP_PROTOCOL_PREFIX + ApplicationConstants.APP_PATH + '/' + ConnectorResource.CONNECTOR_PATH + '/' + connector.getUI().getUIId() + '/' + connector.getConnectorId() + '/' + encodeFileName(filename); return uri; }
/** * Removes those UIs from the given session for which {@link UI#isClosing() * isClosing} yields true. * * @param session */ private void removeClosedUIs(final VaadinSession session) { List<UI> uis = new ArrayList<>(session.getUIs()); for (final UI ui : uis) { if (ui.isClosing()) { ui.accessSynchronously(() -> { getLogger().log(Level.FINER, "Removing closed UI {0}", ui.getUIId()); session.removeUI(ui); }); } } }
private String getStreamVariableTargetUrl(String name, StreamVariable value) { String connectorId = getConnectorId(); UI ui = getUI(); int uiId = ui.getUIId(); String key = uiId + "/" + connectorId + "/" + name; ConnectorTracker connectorTracker = ui.getConnectorTracker(); connectorTracker.addStreamVariable(connectorId, name, value); String secKey = connectorTracker.getSeckey(value); return ApplicationConstants.APP_PROTOCOL_PREFIX + ServletPortletHelper.UPLOAD_URL_PREFIX + key + "/" + secKey; }
/** * @deprecated As of 7.1. See #11411. */ @Deprecated public String getStreamVariableTargetUrl(ClientConnector owner, String name, StreamVariable value) { /* * We will use the same APP/* URI space as ApplicationResources but * prefix url with UPLOAD * * e.g. APP/UPLOAD/[UIID]/[PID]/[NAME]/[SECKEY] * * SECKEY is created on each paint to make URL's unpredictable (to * prevent CSRF attacks). * * NAME and PID from URI forms a key to fetch StreamVariable when * handling post */ String paintableId = owner.getConnectorId(); UI ui = owner.getUI(); int uiId = ui.getUIId(); String key = uiId + "/" + paintableId + "/" + name; ConnectorTracker connectorTracker = ui.getConnectorTracker(); connectorTracker.addStreamVariable(paintableId, name, value); String seckey = connectorTracker.getSeckey(value); return ApplicationConstants.APP_PROTOCOL_PREFIX + ServletPortletHelper.UPLOAD_URL_PREFIX + key + "/" + seckey; }
/** * Closes those UIs in the given session for which {@link #isUIActive} * yields false. * * @since 7.0.0 */ private void closeInactiveUIs(VaadinSession session) { final String sessionId = session.getSession().getId(); for (final UI ui : session.getUIs()) { if (!isUIActive(ui) && !ui.isClosing()) { ui.accessSynchronously(() -> { getLogger().log(Level.FINE, "Closing inactive UI #{0} in session {1}", new Object[] { ui.getUIId(), sessionId }); ui.close(); }); } } }
@Override public boolean synchronizedHandleRequest(VaadinSession session, VaadinRequest request, VaadinResponse response) throws IOException { try { assert UI.getCurrent() == null; // Update browser information from the request session.getBrowser().updateRequestDetails(request); UI uI = getBrowserDetailsUI(request, session); session.getCommunicationManager().repaintAll(uI); JsonObject params = Json.createObject(); params.put(UIConstants.UI_ID_PARAMETER, uI.getUIId()); String initialUIDL = getInitialUidl(request, uI); params.put("uidl", initialUIDL); return commitJsonResponse(request, response, JsonUtil.stringify(params)); } catch (JsonException e) { throw new IOException("Error producing initial UIDL", e); } }
getLogger().log(Level.SEVERE, "Exception while cleaning connector map for ui " + ui.getUIId(), e);
@Override public void execute() { getLogger().log(Level.FINE, "Closing inactive UI #{0} in session {1}", new Object[] { ui.getUIId(), sessionId }); ui.close(); } });
@Override public void execute() { getLogger().log(Level.FINER, "Removing closed UI {0}", ui.getUIId()); session.removeUI(ui); } });
@Override public void clean() { LOG.info("Cleanup delayed event push strategy for UI {}", vaadinUI.getUIId()); jobHandle.cancel(true); queue.clear(); }
@Override public void clean() { LOG.info("Cleanup delayed event push strategy for UI", vaadinUI.getUIId()); jobHandle.cancel(true); queue.clear(); }
UiContextReferenceImpl(UI ui) { this.uiId = String.format("%s:%d", ui.getEmbedId(), ui.getUIId()); }
private UIID getUIID() { final UI currentUI = UI.getCurrent(); if (currentUI != null && currentUI.getUIId() != -1) { return new UIID(currentUI); } else { UIID currentIdentifier = CurrentInstance.get(UIID.class); Assert.notNull(currentIdentifier, String.format("Found no valid %s instance!", UIID.class.getName())); return currentIdentifier; } }
/** * Called by the framework to remove an UI instance from the session because * it has been closed. * * @param ui * the UI to remove */ public void removeUI(UI ui) { assert hasLock(); assert UI.getCurrent() == ui; Integer id = Integer.valueOf(ui.getUIId()); ui.getInternals().setSession(null); uIs.remove(id); }