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

org.wildfly.clustering.ejb.cache.bean.DefaultBeanGroup Maven / Gradle / Ivy

Go to download

Contains code common to the wildfly-clustering-ejb-hotrod and wildfly-clustering-ejb-infinispan modules.

There is a newer version: 34.0.1.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package org.wildfly.clustering.ejb.cache.bean;

import java.util.Map;
import java.util.concurrent.CompletionStage;
import java.util.function.Consumer;

import org.wildfly.clustering.cache.CacheEntryMutator;
import org.wildfly.clustering.ejb.bean.BeanInstance;

/**
 * A default {@link BeanGroup} implementation based on a map of bean instances.
 * @author Paul Ferraro
 * @param  the bean identifier type
 * @param  the bean instance type
 */
public class DefaultBeanGroup> extends DefaultImmutableBeanGroup implements MutableBeanGroup {

    private final Map instances;
    private final Consumer> prePassivateTask;
    private final CacheEntryMutator mutator;

    public DefaultBeanGroup(K id, Map instances, Consumer> prePassivateTask, CacheEntryMutator mutator, Runnable closeTask) {
        super(id, instances, closeTask);
        this.instances = instances;
        this.prePassivateTask = prePassivateTask;
        this.mutator = mutator;
    }

    @Override
    public void addBeanInstance(V instance) {
        this.instances.put(instance.getId(), instance);
    }

    @Override
    public V removeBeanInstance(K id) {
        return this.instances.remove(id);
    }

    @Override
    public CompletionStage mutateAsync() {
        this.prePassivateTask.accept(this.instances);
        return this.mutator.mutateAsync();
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy