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

org.wildfly.clustering.session.cache.ImmutableSessionFactory 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.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

import org.wildfly.clustering.cache.BiCacheEntryLocator;
import org.wildfly.clustering.cache.CacheProperties;
import org.wildfly.clustering.session.ImmutableSession;
import org.wildfly.clustering.session.ImmutableSessionMetaData;
import org.wildfly.clustering.session.cache.attributes.ImmutableSessionAttributesFactory;
import org.wildfly.clustering.session.cache.metadata.ImmutableSessionMetaDataFactory;

/**
 * Factory for creating an {@link ImmutableSession}.
 * @param  the session metadata value type
 * @param  the session attribute value type
 * @author Paul Ferraro
 */
public interface ImmutableSessionFactory extends BiCacheEntryLocator {

	ImmutableSessionMetaDataFactory getMetaDataFactory();
	ImmutableSessionAttributesFactory getAttributesFactory();
	CacheProperties getCacheProperties();

	@Override
	default Map.Entry, CompletionStage> findEntry(String id) {
		CompletionStage metaDataStage = this.getMetaDataFactory().findValueAsync(id);
		// If cache locks on read, find meta data first
		CompletionStage attributesStage = this.getCacheProperties().isLockOnRead() ? metaDataStage.thenCompose(metaData -> (metaData != null) ? this.getAttributesFactory().findValueAsync(id) : CompletableFuture.completedStage(null)) : this.getAttributesFactory().findValueAsync(id);
		return Map.entry(metaDataStage, attributesStage);
	}

	@Override
	default Map.Entry, CompletionStage> tryEntry(String id) {
		CompletionStage metaDataStage = this.getMetaDataFactory().tryValueAsync(id);
		// If cache locks on read, find meta data first
		CompletionStage attributesStage = this.getCacheProperties().isLockOnRead() ? metaDataStage.thenCompose(metaData -> (metaData != null) ? this.getAttributesFactory().findValueAsync(id) : CompletableFuture.completedStage(null)) : this.getAttributesFactory().tryValueAsync(id);
		return Map.entry(metaDataStage, attributesStage);
	}

	default ImmutableSession createImmutableSession(String id, Map.Entry entry) {
		MV metaDataValue = entry.getKey();
		AV attributesValue = entry.getValue();
		if ((metaDataValue == null) || (attributesValue == null)) return null;
		ImmutableSessionMetaData metaData = this.getMetaDataFactory().createImmutableSessionMetaData(id, metaDataValue);
		Map attributes = this.getAttributesFactory().createImmutableSessionAttributes(id, attributesValue);
		return this.createImmutableSession(id, metaData, attributes);
	}

	ImmutableSession createImmutableSession(String id, ImmutableSessionMetaData metaData, Map attributes);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy