List of usage examples for com.vaadin.server VaadinSession getUIs
public Collection<UI> getUIs()
From source file:com.haulmont.cuba.web.DefaultApp.java
License:Apache License
protected void redirectAfterLogout(String loggedOutUrl) { if (!Strings.isNullOrEmpty(loggedOutUrl)) { AppUI currentUi = AppUI.getCurrent(); // it can be null if we handle request in a custom RequestHandler if (currentUi != null) { currentUi.setContent(null);// w w w . ja v a2s . c o m currentUi.getPage().setLocation(loggedOutUrl); } else { VaadinResponse response = VaadinService.getCurrentResponse(); try { ((VaadinServletResponse) response).getHttpServletResponse().sendRedirect(loggedOutUrl); } catch (IOException e) { log.error("Error on send redirect to client", e); } } VaadinSession vaadinSession = VaadinSession.getCurrent(); for (UI ui : vaadinSession.getUIs()) { if (ui != currentUi) { ui.access(() -> { ui.setContent(null); ui.getPage().setLocation(loggedOutUrl); }); } } } }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliController.java
License:Open Source License
@Override public void receiveMessage(MMessagePacket pkt) { MSysOut.println(MESSAGING_LOGS,/*w w w . j av a 2 s. c o m*/ "AbstractMmowgliController.receiveMessage() handling msg type " + pkt.msgType); // Our session might be down or going down, so check first MmowgliSessionGlobals globs = Mmowgli2UI.getGlobals(); if (globs == null || globs.stopping) return; HSess.init(); // First check session-global handlers switch (pkt.msgType) { case UPDATED_GAME: globs.gameUpdatedExternallyTL(null); break; /* refactor case UPDATED_CARDTYPE: CardType ct = (CardType) HSess.get().get(CardType.class, Long.parseLong(pkt.msg)); CardTypeManager.updateCardType(ct); break; */ /* Not used with new session report case INSTANCEREPORTCOMMAND: helper.doSessionReport(pkt.msg); break; */ } // Now check each UI Mmowgli2UI appui = Mmowgli2UI.getAppUI(); // got some null ptrs here if (appui != null) { VaadinSession vSess = appui.getSession(); if (vSess != null) { Collection<UI> uis = vSess.getUIs(); if (uis != null) { for (UI ui : uis) { if (ui == null || !(ui instanceof Mmowgli2UI) || !((Mmowgli2UI) ui).isUiFullyInitted()) // might be the error ui continue; Mmowgli2UI mui = (Mmowgli2UI) ui; mui.access(mui.getControllerHelper().getAccessRunner(pkt)); } } } } try { HSess.close(); } catch (Throwable t) { MSysOut.println(ERROR_LOGS, "AbstractMmowgliController.receiveMessage():" + t.getClass().getSimpleName() + " " + t.getLocalizedMessage()); } }
From source file:edu.nps.moves.mmowgli.AbstractMmowgliControllerHelper2.java
License:Open Source License
private void doLogOutIn8SecondsTL() { Thread thr = new Thread("KickoutThread") { @Override//ww w .j av a 2s .c om public void run() { try { Thread.sleep(8 * 1000); VaadinSession sess = Mmowgli2UI.getAppUI().getSession(); HSess.init(); GameLinks links = GameLinks.getTL(); HSess.close(); final String terms = links.getTermsLink(); for (final UI ui : sess.getUIs()) ui.access(new Runnable() { public void run() { ui.getPage().setLocation(terms); } }); sess.close(); // bye bye } catch (InterruptedException ex) { } } }; thr.setPriority(Thread.NORM_PRIORITY); thr.start(); }
From source file:edu.nps.moves.mmowgli.AppMaster.java
License:Open Source License
public void killAllSessionsTL() { GameLinks links = GameLinks.getTL(); String thanks = links.getThanksForPlayingLink(); synchronized (sessionsInThisMmowgliNode) { Iterator<VaadinSession> itr = sessionsInThisMmowgliNode.iterator(); while (itr.hasNext()) { VaadinSession sess = itr.next(); for (UI ui : sess.getUIs()) { ui.getPage().setLocation(thanks); ui.close();// www . ja va2 s. com } sess.close(); } } }
From source file:edu.nps.moves.mmowgli.AppMaster.java
License:Open Source License
public void pushPingAllSessionsInThisClusterNode() { synchronized (sessionsInThisMmowgliNode) { Iterator<VaadinSession> itr = sessionsInThisMmowgliNode.iterator(); while (itr.hasNext()) { VaadinSession sess = itr.next(); for (final UI ui : sess.getUIs()) { if (!ui.isClosing() && ui instanceof Mmowgli2UI) { ui.access(new Runnable() { public void run() { ((Mmowgli2UI) ui).pingPush(); ui.push(); // empty push to keep connection alive over Akamai MSysOut.println(TICK_LOGS, "Keep alive push, ui " + ui.hashCode()); }// w w w .j a va 2 s . co m }); } } } } }
From source file:edu.nps.moves.mmowgli.Mmowgli2UI.java
License:Open Source License
public void setWindowTitle(Session sess) { Game game = Game.get(sess);//from w w w. ja va 2 s . co m boolean gameReadOnly = game.isReadonly(); boolean cardsReadOnly = game.isCardsReadonly(); VaadinSession vsess = getSession(); if (vsess != null) { // occasionally see null here ArrayList<UI> uis = new ArrayList<UI>(vsess.getUIs()); String title = Move.getCurrentMove(sess).getCurrentMovePhase().getWindowTitle(); uis.add(this);// Set this one, since we may not be in the list yet if (gameReadOnly) title = title + " (Read-only)"; else if (cardsReadOnly) title = title + " (Cards read-only)"; else ; for (UI ui : uis) { ui.getPage().setTitle(title); } } }
From source file:edu.nps.moves.mmowgli.Mmowgli2UIProvider.java
License:Open Source License
@Override public Class<? extends UI> getUIClass(UIClassSelectionEvent event) { VaadinService serv = event.getService(); VaadinSession vsess; CACData data = (CACData) event.getRequest().getAttribute(CACData.class.getName()); // put in place by Mmowgli2VaadinServlet.sessionInit() if (data != null) // why null sometimes? if (!CACManager.canProceed(data)) { return Mmowgli2CACError.class; }/*from w w w. ja v a2 s .co m*/ try { vsess = serv.findVaadinSession(event.getRequest()); } catch (SessionExpiredException ex) { return Mmowgli2UILogin.class; } catch (ServiceException sex) { return Mmowgli2UIError.class; } Collection<UI> uis = vsess.getUIs(); int count = uis.size(); if (count == 0) return Mmowgli2UILogin.class; MmowgliSessionGlobals globs = vsess.getAttribute(MmowgliSessionGlobals.class); // if globs != null, just means servlet has been hit, shouldn't be here // if globs ! initted, means Mmowgli2UILogin has not finished init ... send error // if glob ! loggedIn, means Mmowgli2UILogin in the sequence of login screens ... send error // else, send Subsequent UI, which is UI for 2nd and further browser windows/tabs in same user session if (globs != null && globs.initted & globs.isLoggedIn()) { for (UI ui : uis) { if (ui instanceof Mmowgli2UILogin) { // so we've got an initted UI, and the user is logged in return Mmowgli2UISubsequent.class; } } } return Mmowgli2UIError.class; // puts up "incomplete login" verbage }
From source file:edu.nps.moves.mmowgli.MmowgliSessionGlobals.java
License:Open Source License
@Override public boolean gameUpdatedExternallyTL(Object nullObj) { Mmowgli2UI.getAppUI().setWindowTitle(HSess.get()); // Got a null ptr exception here once, so do some checking // Collection<UI> uis = Mmowgli2UI.getAppUI().getSession().getUIs(); Mmowgli2UI mui = Mmowgli2UI.getAppUI(); if (mui != null) { VaadinSession sess = mui.getSession(); if (sess != null) { Collection<UI> uis = sess.getUIs(); for (UI ui : uis) { if (ui instanceof Mmowgli2UI) { AppMenuBar menubar = ((Mmowgli2UI) ui).getMenuBar(); if (menubar != null) { // can be at start menubar.gameUpdatedExternallyTL(null); }//from ww w.ja v a2 s . c o m } } } } setGameBooleans(Game.getTL()); return true; }