All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.imunity.furms.ui.config.UIInSessionHolder Maven / Gradle / Ivy

There is a newer version: 4.3.1
Show newest version
/*
 * Copyright (c) 2021 Bixbit - Krzysztof Benedyczak. All rights reserved.
 * See LICENCE.txt file for licensing information.
 */
package io.imunity.furms.ui.config;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import javax.servlet.http.HttpSession;

import com.vaadin.flow.component.UI;
import com.vaadin.flow.server.WrappedHttpSession;

public class UIInSessionHolder
{
	private static final String SESSION_ATTR = UIInSessionHolder.class.getCanonicalName();
	
	public static void addUIToSession(UI ui, WrappedHttpSession session) {
		synchronized(session.getHttpSession()) {
			@SuppressWarnings("unchecked")
			List uiList = (List) session.getAttribute(SESSION_ATTR);
			if (uiList == null) {
				uiList = new ArrayList<>();
				session.setAttribute(SESSION_ATTR, uiList);
			}
			uiList.add(ui);
		}
	}
	
	public static List getUIsFromSession(HttpSession session) {
		synchronized(session) {
			@SuppressWarnings("unchecked")
			List uiList = (List) session.getAttribute(SESSION_ATTR);
			return uiList == null ? Collections.emptyList() : List.copyOf(uiList);
		}		
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy