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

nf.fr.eraasoft.pool.impl.PoolFactory Maven / Gradle / Ivy

The newest version!
package nf.fr.eraasoft.pool.impl;

import nf.fr.eraasoft.pool.ObjectPool;
import nf.fr.eraasoft.pool.PoolSettings;
import nf.fr.eraasoft.pool.PoolableObject;

public class PoolFactory {
	final PoolSettings settings;

	AbstractPool pool;
	final PoolableObject poolableObject;

	public PoolFactory(PoolSettings settings, PoolableObject poolableObject) {
		this.settings = settings;
		this.poolableObject = poolableObject;
	}

	public ObjectPool getPool() {
		if (pool == null)
			createPoolInstance();
		return pool;
	}
	
	public void clear() {
		if (getPool() instanceof Controlable) {
			((Controlable) getPool()).clear();
		}
	}

	private static class BBObjectPool extends BlockingQueueObjectPool {

		public BBObjectPool(PoolableObject poolableObject, PoolSettings settings) {
			super(poolableObject, settings);

		}

	}

	private synchronized void createPoolInstance() {
		if (pool == null){
			if (settings.max()>0)
				pool = new BBObjectPool(poolableObject, settings);
			else 
				pool = new ConcurrentLinkedQueuePool(poolableObject, settings);
		}

	}

	public PoolSettings settings() {
		return settings;
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy