org.wildfly.clustering.session.cache.user.DefaultUserManager Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.session.cache.user;
import java.util.Map;
import java.util.function.Supplier;
import org.wildfly.clustering.cache.batch.Batch;
import org.wildfly.clustering.server.manager.IdentifierFactory;
import org.wildfly.clustering.session.user.User;
import org.wildfly.clustering.session.user.UserManager;
/**
* A default user manager implementation that delegates to a user factory.
* @param the user context value type
* @param the persistent context type
* @param the transient context type
* @param the user sessions value type
* @param the deployment type
* @param the session type
*/
public class DefaultUserManager implements UserManager {
private final UserFactory factory;
private final Supplier batchFactory;
private final IdentifierFactory identifierFactory;
public DefaultUserManager(UserFactory factory, IdentifierFactory identifierFactory, Supplier batchFactory) {
this.factory = factory;
this.batchFactory = batchFactory;
this.identifierFactory = identifierFactory;
}
@Override
public User createUser(String id, C context) {
Map.Entry value = this.factory.createValue(id, context);
return this.factory.createUser(id, value);
}
@Override
public User findUser(String id) {
Map.Entry value = this.factory.findValue(id);
return (value != null) ? this.factory.createUser(id, value) : null;
}
@Override
public Supplier getBatchFactory() {
return this.batchFactory;
}
@Override
public Supplier getIdentifierFactory() {
return this.identifierFactory;
}
@Override
public void start() {
this.identifierFactory.start();
}
@Override
public void stop() {
this.identifierFactory.stop();
}
}