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

org.wildfly.clustering.session.infinispan.remote.HotRodSessionManager Maven / Gradle / Ivy

The newest version!
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */
package org.wildfly.clustering.session.infinispan.remote;

import java.util.Optional;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.server.Registrar;
import org.wildfly.clustering.server.Registration;
import org.wildfly.clustering.session.ImmutableSession;
import org.wildfly.clustering.session.SessionManagerConfiguration;
import org.wildfly.clustering.session.cache.AbstractSessionManager;
import org.wildfly.clustering.session.cache.SessionFactory;
import org.wildfly.common.function.Functions;

/**
 * Generic HotRod-based session manager implementation - independent of cache mapping strategy.
 * @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 class HotRodSessionManager extends AbstractSessionManager {
	private final Registrar> expirationListenerRegistrar;
	private final Consumer expirationListener;
	private final Supplier batchFactory;

	private AtomicReference expirationListenerRegistration = new AtomicReference<>();

	public HotRodSessionManager(SessionManagerConfiguration configuration, SessionFactory factory, HotRodSessionManagerConfiguration hotrod) {
		super(configuration, hotrod, factory, Functions.discardingConsumer());
		this.expirationListenerRegistrar = hotrod.getExpirationListenerRegistrar();
		this.expirationListener = configuration.getExpirationListener();
		this.batchFactory = hotrod.getBatchFactory();
	}

	@Override
	public boolean isStarted() {
		return this.expirationListenerRegistration.get() != null;
	}

	@Override
	public void start() {
		this.expirationListenerRegistration.set(this.expirationListenerRegistrar.register(this.expirationListener));
	}

	@Override
	public void stop() {
		Optional.ofNullable(this.expirationListenerRegistration.getAndSet(null)).ifPresent(Registration::close);
	}

	@Override
	public Supplier getBatchFactory() {
		return this.batchFactory;
	}

	@Override
	public Set getActiveSessions() {
		return Set.of();
	}

	@Override
	public Set getSessions() {
		return Set.of();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy