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

org.hibernate.search.engine.environment.bean.DependencyClosingBeanHolder Maven / Gradle / Ivy

The newest version!
/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright Red Hat Inc. and Hibernate Authors
 */
package org.hibernate.search.engine.environment.bean;

import java.util.List;

import org.hibernate.search.util.common.impl.Closer;

final class DependencyClosingBeanHolder implements BeanHolder {

	private final BeanHolder delegate;
	private final List> dependencies;

	DependencyClosingBeanHolder(BeanHolder delegate, List> dependencies) {
		this.delegate = delegate;
		this.dependencies = dependencies;
	}

	@Override
	public String toString() {
		return getClass().getSimpleName() + "["
				+ "delegate=" + delegate
				+ ", dependencies=" + dependencies
				+ "]";
	}

	@Override
	public T get() {
		return delegate.get();
	}

	@Override
	public void close() {
		try ( Closer closer = new Closer<>() ) {
			closer.push( BeanHolder::close, delegate );
			closer.pushAll( BeanHolder::close, dependencies );
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy