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

org.wildfly.clustering.ejb.cache.bean.OnCloseBean 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: 35.0.0.Final
Show newest version
/*
 * Copyright The WildFly Authors
 * SPDX-License-Identifier: Apache-2.0
 */

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

import java.util.function.Consumer;

import org.wildfly.clustering.ejb.bean.Bean;
import org.wildfly.clustering.ejb.bean.BeanInstance;
import org.wildfly.clustering.ejb.bean.BeanMetaData;

/**
 * A bean decorator that executes a given task on close.
 * @author Paul Ferraro
 * @param  the bean identifier type
 * @param  the bean instance type
 */
public class OnCloseBean> implements Bean {

    private final Bean bean;
    private final Consumer> task;

    public OnCloseBean(Bean bean, Consumer> task) {
        this.bean = bean;
        this.task = task;
    }

    @Override
    public K getId() {
        return this.bean.getId();
    }

    @Override
    public V getInstance() {
        return this.bean.getInstance();
    }

    @Override
    public BeanMetaData getMetaData() {
        return this.bean.getMetaData();
    }

    @Override
    public boolean isValid() {
        return this.bean.isValid();
    }

    @Override
    public void remove(Consumer removeTask) {
        this.bean.remove(removeTask);
    }

    @Override
    public void close() {
        try {
            this.task.accept(this.bean);
        } finally {
            this.bean.close();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy