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

rpc.turbo.pool.ObjectFactory Maven / Gradle / Ivy

There is a newer version: 0.0.9
Show newest version
package rpc.turbo.pool;

import stormpot.Allocator;
import stormpot.Slot;

@FunctionalInterface
public interface ObjectFactory extends Allocator> {

	public T newInstance();

	@Override
	default public PoolableObject allocate(Slot slot) throws Exception {
		return new PoolableObject(slot, newInstance());
	}

	@Override
	default public void deallocate(PoolableObject poolable) throws Exception {
		if (poolable == null) {
			return;
		}

		T t = poolable.get();

		if (t == null) {
			return;
		}

		if (t instanceof AutoCloseable) {
			((AutoCloseable) t).close();
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy