org.wildfly.clustering.session.cache.affinity.NarySessionAffinity Maven / Gradle / Ivy
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/
package org.wildfly.clustering.session.cache.affinity;
import java.util.List;
import java.util.function.Function;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import org.wildfly.clustering.server.GroupMember;
/**
* Session affinity to multiple members.
* @param the group member type
* @author Paul Ferraro
*/
public class NarySessionAffinity implements UnaryOperator {
private Function> affinity;
private Function mapper;
private String delimiter;
private int maxMembers;
public NarySessionAffinity(Function> affinity, Function mapper, NarySessionAffinityConfiguration config) {
this.affinity = affinity;
this.mapper = mapper;
this.delimiter = config.getDelimiter();
this.maxMembers = config.getMaxMembers();
}
@Override
public String apply(String id) {
return this.affinity.apply(id).stream().map(this.mapper).distinct().limit(this.maxMembers).collect(Collectors.joining(this.delimiter));
}
}