@Override public boolean isAttached() { return getSession() != null; }
@Override public String getConnectorId() { if (connectorId == null) { if (getSession() == null) { throw new RuntimeException( "Component must be attached to a session when getConnectorId() is called for the first time"); } connectorId = getSession().createConnectorId(this); } return connectorId; }
private String buildLockAssertMessage(String method) { if (VaadinService.isOtherSessionLocked(getSession())) { return "The session of this connecor is not locked, but there is another session that is locked. " + "This might be caused by accidentally using a connector that belongs to another session."; } else { return "Session must be locked when " + method + " is called"; } }
@Override public void markAsDirty() { assert getSession() == null || getSession().hasLock() : buildLockAssertMessage( "markAsDirty()"); UI uI = getUI(); if (uI != null) { uI.getConnectorTracker().markDirty(this); } }
@Override public boolean handleConnectorRequest(VaadinRequest request, VaadinResponse response, String path) throws IOException { DownloadStream stream = null; String[] parts = path.split("/", 2); String key = parts[0]; VaadinSession session = getSession(); session.lock(); try { ConnectorResource resource = (ConnectorResource) getResource(key); if (resource == null) { return false; } stream = resource.getStream(); } finally { session.unlock(); } stream.writeResponse(request, response); return true; }
/** * Returns the shared state for this connector. * * @param markAsDirty * true if the connector should automatically be marked dirty, * false otherwise * * @return The shared state for this connector. Never null. * @see #getState() */ protected SharedState getState(boolean markAsDirty) { assert getSession() == null || getSession().hasLock() : buildLockAssertMessage( "getState()"); if (null == sharedState) { sharedState = createState(); } if (markAsDirty) { UI ui = getUI(); if (ui != null && !ui.getConnectorTracker().isDirty(this) && !ui.getConnectorTracker().isWritingResponse()) { ui.getConnectorTracker().markDirty(this); } } return sharedState; }