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

org.wildfly.clustering.session.cache.SessionFactory 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;

import java.time.Duration;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.function.Supplier;

import org.wildfly.clustering.cache.BiCacheEntryCreator;
import org.wildfly.clustering.cache.CacheEntryRemover;
import org.wildfly.clustering.session.Session;
import org.wildfly.clustering.session.cache.attributes.SessionAttributesFactory;
import org.wildfly.clustering.session.cache.metadata.SessionMetaDataFactory;

/**
 * Factory for creating sessions. Encapsulates the cache mapping strategy for sessions.
 * @param  the session manager context type
 * @param  the meta-data value type
 * @param  the attributes value type
 * @param  the session context type
 * @author Paul Ferraro
 */
public interface SessionFactory extends ImmutableSessionFactory, BiCacheEntryCreator, CacheEntryRemover, AutoCloseable {
	@Override
	SessionMetaDataFactory getMetaDataFactory();
	@Override
	SessionAttributesFactory getAttributesFactory();

	Supplier getContextFactory();

	@Override
	default Map.Entry, CompletionStage> createEntry(String id, Duration context) {
		return Map.entry(this.getMetaDataFactory().createValueAsync(id, context), this.getAttributesFactory().createValueAsync(id, null));
	}

	@Override
	default CompletionStage removeAsync(String id) {
		return CompletableFuture.allOf(this.getMetaDataFactory().removeAsync(id).toCompletableFuture(), this.getAttributesFactory().removeAsync(id).toCompletableFuture());
	}

	@Override
	default CompletionStage purgeAsync(String id) {
		return CompletableFuture.allOf(this.getMetaDataFactory().purgeAsync(id).toCompletableFuture(), this.getAttributesFactory().purgeAsync(id).toCompletableFuture());
	}

	Session createSession(String id, Map.Entry entry, C context);

	@Override
	default void close() {
		this.getMetaDataFactory().close();
		this.getAttributesFactory().close();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy