Example usage for org.apache.commons.pool2.impl GenericObjectPool close

List of usage examples for org.apache.commons.pool2.impl GenericObjectPool close

Introduction

In this page you can find the example usage for org.apache.commons.pool2.impl GenericObjectPool close.

Prototype

@Override
public void close() 

Source Link

Document

Closes the pool.

Usage

From source file:com.tremolosecurity.provisioning.core.ProvisioningEngineImpl.java

private void initLocalBroker() throws ProvisioningException {
    if (this.isInternalQueue()) {
        this.broker = BrokerHolder.getInstance(cfgMgr, "local", this);

    } else {/*from  www.j a  v  a 2 s .  c  o  m*/

        this.mpPools = new ArrayList<GenericObjectPool<MessageProducerHolder>>();

        if (this.cfgMgr.getCfg().getProvisioning().getQueueConfig().isMultiTaskQueues()) {
            for (int j = 1; j <= this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getNumQueues(); j++) {
                String name = this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getTaskQueueName()
                        .replace("{x}", Integer.toString(j));
                GenericObjectPool<MessageProducerHolder> lpool = new GenericObjectPool<MessageProducerHolder>(
                        new PooledMessageProducerFactory(this.cfgMgr, this, name));
                lpool.setMaxTotal(this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getMaxProducers());
                this.mpPools.add(lpool);
            }
        } else {
            this.mpPools = new ArrayList<GenericObjectPool<MessageProducerHolder>>();
            GenericObjectPool<MessageProducerHolder> lpool = new GenericObjectPool<MessageProducerHolder>(
                    new PooledMessageProducerFactory(this.cfgMgr, this,
                            this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getTaskQueueName()));
            lpool.setMaxTotal(this.cfgMgr.getCfg().getProvisioning().getQueueConfig().getMaxProducers());
            this.mpPools.add(lpool);
        }

        this.cfgMgr.addThread(new StopableThread() {

            @Override
            public void run() {
                // TODO Auto-generated method stub

            }

            @Override
            public void stop() {
                for (GenericObjectPool<MessageProducerHolder> mpPool : mpPools) {
                    mpPool.close();
                    mpPool.clear();
                }

            }

        });
    }
}