com.vaadin.ui.UI.accessSynchronously()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(136)

本文整理了Java中com.vaadin.ui.UI.accessSynchronously()方法的一些代码示例,展示了UI.accessSynchronously()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。UI.accessSynchronously()方法的具体详情如下:
包路径:com.vaadin.ui.UI
类名称:UI
方法名:accessSynchronously

UI.accessSynchronously介绍

[英]Locks the session of this UI and runs the provided command right away.

It is generally recommended to use #access(Command) instead of this method for accessing a session from a different thread as #access(Command) can be used while holding the lock of another session. To avoid causing deadlocks, this methods throws an exception if it is detected than another session is also locked by the current thread.

This method behaves differently than #access(Command) in some situations:

  • If the current thread is currently holding the lock of the session, #accessSynchronously(Command) runs the task right away whereas #access(Command) defers the task to a later point in time.
  • If some other thread is currently holding the lock for the session, #accessSynchronously(Command) blocks while waiting for the lock to be available whereas #access(Command) defers the task to a later point in time.
    [中]锁定此UI的会话并立即运行提供的命令。
    通常建议使用#access(Command)而不是此方法从其他线程访问会话,因为#access(Command)可以在持有另一个会话的锁时使用。为了避免造成死锁,如果检测到异常,而当前线程也锁定了另一个会话,则此方法会抛出异常。
    在某些情况下,此方法的行为与#访问(命令)不同:
    *如果当前线程当前持有会话锁,#accessSynchronously(命令)立即运行任务,而#access(命令)将任务推迟到稍后的时间点。
    *如果其他线程当前持有会话的锁,#accessSynchronously(命令)会在等待锁可用时阻塞,而#access(命令)会将任务延迟到稍后的时间点。

代码示例

代码示例来源:origin: com.vaadin/vaadin-server

@Override
public void run() {
  accessSynchronously(runnable);
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * 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);
      });
    }
  }
}

代码示例来源:origin: com.vaadin/vaadin-server

/**
 * 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();
      });
    }
  }
}

代码示例来源:origin: com.haulmont.cuba/cuba-web

@Override
  public void accessSynchronously(Runnable runnable) {
    ui.accessSynchronously(runnable);
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

@Override
public void execute() {
  accessSynchronously(command);
}

代码示例来源:origin: com.vaadin/vaadin-server

ui.accessSynchronously(() -> {

代码示例来源:origin: com.vaadin/hummingbird-server

/**
 * Removes those UIs from the given session for which {@link UI#isClosing()
 * isClosing} yields true.
 *
 * @param session
 */
private void removeClosedUIs(final VaadinSession session) {
  ArrayList<UI> uis = new ArrayList<>(session.getUIs());
  for (final UI ui : uis) {
    if (ui.isClosing()) {
      ui.accessSynchronously(new Command() {
        @Override
        public void execute() {
          getLogger().log(Level.FINER, "Removing closed UI {0}",
              ui.getUIId());
          session.removeUI(ui);
        }
      });
    }
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

/**
 * 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(new Command() {
        @Override
        public void execute() {
          getLogger().log(Level.FINE,
              "Closing inactive UI #{0} in session {1}",
              new Object[] { ui.getUIId(), sessionId });
          ui.close();
        }
      });
    }
  }
}

代码示例来源:origin: com.vaadin/hummingbird-server

ui.accessSynchronously(new Command() {
  @Override
  public void execute() {

代码示例来源:origin: OpenNMS/opennms

.withNumberOfRequests(pingRequest.getNumberRequests())
.withProgressCallback((newSequence, summary) -> {
    getUI().accessSynchronously(() -> {
      if (pingFuture != null && !pingFuture.isCancelled()) {
      setRunning(!summary.isComplete());

代码示例来源:origin: org.opennms.features.topology/org.opennms.features.topology.netutils

.withNumberOfRequests(pingRequest.getNumberRequests())
.withProgressCallback((newSequence, summary) -> {
    getUI().accessSynchronously(() -> {
      if (pingFuture != null && !pingFuture.isCancelled()) {
      setRunning(!summary.isComplete());

相关文章