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

org.wildfly.clustering.session.cache.user.MutableUserSessions Maven / Gradle / Ivy

There is a newer version: 4.0.0.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */
package org.wildfly.clustering.session.cache.user;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import org.wildfly.clustering.cache.CacheEntryMutator;
import org.wildfly.clustering.session.user.UserSessions;

/**
 * A mutable user sessions implementation.
 * @param  the deployment type
 * @param  the session type
 */
public class MutableUserSessions implements UserSessions {

	private final Map sessions;
	private final CacheEntryMutator mutator;

	public MutableUserSessions(Map sessions, CacheEntryMutator mutator) {
		this.sessions = sessions;
		this.mutator = mutator;
	}

	@Override
	public Set getDeployments() {
		return Collections.unmodifiableSet(this.sessions.keySet());
	}

	@Override
	public S getSession(D deployment) {
		return this.sessions.get(deployment);
	}

	@Override
	public S removeSession(D deployment) {
		S removed = this.sessions.remove(deployment);
		if (removed != null) {
			this.mutator.mutate();
		}
		return removed;
	}

	@Override
	public boolean addSession(D deployment, S session) {
		boolean added = this.sessions.put(deployment, session) == null;
		if (added) {
			this.mutator.mutate();
		}
		return added;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy