use of com.vaadin.flow.server.communication.PushConnection in project flow by vaadin.
the class UI method push.
/**
* Pushes the pending changes and client RPC invocations of this UI to the
* client-side.
* <p>
* If push is enabled, but the push connection is not currently open, the
* push will be done when the connection is established.
* <p>
* As with all UI methods, the session must be locked when calling this
* method. It is also recommended that {@link UI#getCurrent()} is set up to
* return this UI since writing the response may invoke logic in any
* attached component or extension. The recommended way of fulfilling these
* conditions is to use {@link #access(Command)}.
*
* @throws IllegalStateException
* if push is disabled.
* @throws UIDetachedException
* if this UI is not attached to a session.
*
* @see #getPushConfiguration()
*/
public void push() {
VaadinSession session = getSession();
if (session == null) {
throw new UIDetachedException("Cannot push a detached UI");
}
session.checkHasLock();
if (!getPushConfiguration().getPushMode().isEnabled()) {
throw new IllegalStateException("Push not enabled");
}
PushConnection pushConnection = getInternals().getPushConnection();
assert pushConnection != null;
/*
* Purge the pending access queue as it might mark a connector as dirty
* when the push would otherwise be ignored because there are no changes
* to push.
*/
session.getService().runPendingAccessTasks(session);
if (!getInternals().isDirty()) {
// Do not push if there is nothing to push
return;
}
pushConnection.push();
}
use of com.vaadin.flow.server.communication.PushConnection in project flow by vaadin.
the class UI method close.
/**
* Marks this UI to be {@link #onDetach(DetachEvent) detached} from the
* session at the end of the current request, or the next request if there
* is no current request (if called from a background thread, for instance.)
* <p>
* The UI is detached after the response is sent, so in the current request
* it can still update the client side normally. However, after the response
* any new requests from the client side to this UI will cause an error, so
* usually the client should be asked, for instance, to reload the page
* (serving a fresh UI instance), to close the page, or to navigate
* somewhere else.
* <p>
* Note that this method is strictly for users to explicitly signal the
* framework that the UI should be detached. Overriding it is not a reliable
* way to catch UIs that are to be detached. Instead,
* {@code #onDetach(DetachEvent)} should be overridden.
*/
public void close() {
closing = true;
// FIXME Send info to client
PushConnection pushConnection = getInternals().getPushConnection();
if (pushConnection != null) {
// Can't use UI.push() directly since it checks for a valid session
if (getSession() != null) {
getSession().getService().runPendingAccessTasks(getSession());
}
pushConnection.push();
}
}
Aggregations