Example usage for org.apache.commons.pool ObjectPool setFactory

List of usage examples for org.apache.commons.pool ObjectPool setFactory

Introduction

In this page you can find the example usage for org.apache.commons.pool ObjectPool setFactory.

Prototype

void setFactory(PoolableObjectFactory p0) throws IllegalStateException, UnsupportedOperationException;

Source Link

Usage

From source file:edu.illinois.enforcemop.examples.apache.pool.TestObjectPool.java

public void testSetFactory() throws Exception {
    ObjectPool pool;
    try {//  w ww. ja v a 2s  .  c o  m
        pool = makeEmptyPool(new MethodCallPoolableObjectFactory());
    } catch (UnsupportedOperationException uoe) {
        return; // test not supported
    }
    final MethodCallPoolableObjectFactory factory = new MethodCallPoolableObjectFactory();
    try {
        pool.setFactory(factory);
    } catch (UnsupportedOperationException uoe) {
        return;
    }
}

From source file:edu.illinois.enforcemop.examples.apache.pool.TestBaseObjectPool.java

public void testUnsupportedOperations() throws Exception {
    if (!getClass().equals(TestBaseObjectPool.class)) {
        return; // skip redundant tests
    }/* ww w .  j a  v  a  2s. co m*/
    ObjectPool pool = new BaseObjectPool() {
        public Object borrowObject() {
            return null;
        }

        public void returnObject(Object obj) {
        }

        public void invalidateObject(Object obj) {
        }
    };

    assertTrue("Negative expected.", pool.getNumIdle() < 0);
    assertTrue("Negative expected.", pool.getNumActive() < 0);

    try {
        pool.clear();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        pool.addObject();
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }

    try {
        pool.setFactory(null);
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
        // expected
    }
}

From source file:org.fusesource.jms.pool.SessionPool.java

public SessionPool(ConnectionPool connectionPool, SessionKey key, ObjectPool sessionPool) {
    this.connectionPool = connectionPool;
    this.key = key;
    this.sessionPool = sessionPool;
    sessionPool.setFactory(this);
}