Example usage for com.vaadin.util CurrentInstance restoreInstances

List of usage examples for com.vaadin.util CurrentInstance restoreInstances

Introduction

In this page you can find the example usage for com.vaadin.util CurrentInstance restoreInstances.

Prototype

public static void restoreInstances(Map<Class<?>, CurrentInstance> old) 

Source Link

Document

Restores the given instances to the given values.

Usage

From source file:com.peergreen.webconsole.core.vaadin7.BaseUI.java

License:Open Source License

@Override
public void accessSynchronously(Runnable runnable) {
    Map<Class<?>, CurrentInstance> old = null;

    VaadinSession session = getSession();

    if (session == null) {
        throw new UIDetachedException();
    }/* w  ww  .j a  v a2s .  c o  m*/

    // TODO PGWK-7 - hack to avoid exception when another session had lock
    //VaadinService.verifyNoOtherSessionLocked(session);

    session.lock();
    try {
        if (getSession() == null) {
            // UI was detached after fetching the session but before we
            // acquired the lock.
            throw new UIDetachedException();
        }
        old = CurrentInstance.setCurrent(this);
        runnable.run();
    } finally {
        session.unlock();
        if (old != null) {
            CurrentInstance.restoreInstances(old);
        }
    }
}