Java Code Examples for org.messaginghub.pooled.jms.JmsPoolConnectionFactory#setMaxConnections()

The following examples show how to use org.messaginghub.pooled.jms.JmsPoolConnectionFactory#setMaxConnections() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MQConnectionFactoryConfiguration.java    From mq-jms-spring with Apache License 2.0 6 votes vote down vote up
private JmsPoolConnectionFactory create(ConnectionFactory connectionFactory, JmsPoolConnectionFactoryProperties poolProperties) {

      JmsPoolConnectionFactory pooledConnectionFactory = new JmsPoolConnectionFactory();
      pooledConnectionFactory.setConnectionFactory(connectionFactory);

      pooledConnectionFactory.setBlockIfSessionPoolIsFull(poolProperties.isBlockIfFull());

      if (poolProperties.getBlockIfFullTimeout() != null) {
        pooledConnectionFactory.setBlockIfSessionPoolIsFullTimeout(poolProperties.getBlockIfFullTimeout().toMillis());
      }

      if (poolProperties.getIdleTimeout() != null) {
        pooledConnectionFactory.setConnectionIdleTimeout((int) poolProperties.getIdleTimeout().toMillis());
      }

      pooledConnectionFactory.setMaxConnections(poolProperties.getMaxConnections());
      pooledConnectionFactory.setMaxSessionsPerConnection(poolProperties.getMaxSessionsPerConnection());

      if (poolProperties.getTimeBetweenExpirationCheck() != null) {
        pooledConnectionFactory.setConnectionCheckInterval(poolProperties.getTimeBetweenExpirationCheck().toMillis());
      }

      pooledConnectionFactory.setUseAnonymousProducers(poolProperties.isUseAnonymousProducers());
      return pooledConnectionFactory;
    }
 
Example 2
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testMaxConnectionsAreCreated() throws Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    cf.setMaxConnections(3);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn3 = (JmsPoolConnection) cf.createConnection();

    assertNotSame(conn1.getConnection(), conn2.getConnection());
    assertNotSame(conn1.getConnection(), conn3.getConnection());
    assertNotSame(conn2.getConnection(), conn3.getConnection());

    assertEquals(3, cf.getNumConnections());

    cf.stop();
}
 
Example 3
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConnectionsAreRotated() throws Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    cf.setMaxConnections(10);

    Connection previous = null;

    // Front load the pool.
    for (int i = 0; i < 10; ++i) {
        cf.createConnection();
    }

    for (int i = 0; i < 100; ++i) {
        Connection current = ((JmsPoolConnection) cf.createConnection()).getConnection();
        assertNotSame(previous, current);
        previous = current;
    }

    cf.stop();
}
 
Example 4
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testConnectionsArePooled() throws Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    cf.setMaxConnections(1);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn3 = (JmsPoolConnection) cf.createConnection();

    assertSame(conn1.getConnection(), conn2.getConnection());
    assertSame(conn1.getConnection(), conn3.getConnection());
    assertSame(conn2.getConnection(), conn3.getConnection());

    assertEquals(1, cf.getNumConnections());

    cf.stop();
}
 
Example 5
Source File: AMQP10JMSProperties.java    From amqp-10-jms-spring-boot with Apache License 2.0 6 votes vote down vote up
public void configurePooledFactory(JmsPoolConnectionFactory factory) {
    factory.setBlockIfSessionPoolIsFull(isBlockIfSessionPoolIsFull());
    if (getBlockIfSessionPoolIsFullTimeout() != null) {
        factory.setBlockIfSessionPoolIsFullTimeout(getBlockIfSessionPoolIsFullTimeout().toMillis());
    }
    if (getConnectionCheckInterval() != null) {
        factory.setConnectionCheckInterval(getConnectionCheckInterval().toMillis());
    }
    if (getConnectionIdleTimeout() != null) {
        factory.setConnectionIdleTimeout((int) getConnectionIdleTimeout().toMillis());
    }
    factory.setExplicitProducerCacheSize(getExplicitProducerCacheSize());
    factory.setMaxConnections(getMaxConnections());
    factory.setMaxSessionsPerConnection(getMaxSessionsPerConnection());
    factory.setUseAnonymousProducers(isUseAnonymousProducers());
    factory.setUseProviderJMSContext(isUseProviderJMSContext());
}
 
Example 6
Source File: JmsPoolSessionExhaustionTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Override
@Before
   public void setUp() throws Exception {
       factory = new MockJMSConnectionFactory();
       cf = new JmsPoolConnectionFactory();
       cf.setConnectionFactory(factory);
       cf.setMaxConnections(1);
       cf.setBlockIfSessionPoolIsFull(false);
       cf.setMaxSessionsPerConnection(1);
   }
 
Example 7
Source File: JmsPoolConnectionTemporaryDestinationTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    mock = new MockJMSConnectionFactory();

    // Ensure only one connection for that tests validate that shared connections
    // only destroy their own created temporary destinations.
    cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(mock);
    cf.setMaxConnections(1);
}
 
Example 8
Source File: JmsPoolTestSupport.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
    LOG.info("========== start test: " + getTestName() + " ==========");

    factory = new MockJMSConnectionFactory();
    cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(factory);
    cf.setMaxConnections(1);
}
 
Example 9
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testClearAllConnections() throws Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    cf.setMaxConnections(3);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();
    JmsPoolConnection conn3 = (JmsPoolConnection) cf.createConnection();

    assertNotSame(conn1.getConnection(), conn2.getConnection());
    assertNotSame(conn1.getConnection(), conn3.getConnection());
    assertNotSame(conn2.getConnection(), conn3.getConnection());

    assertEquals(3, cf.getNumConnections());

    cf.clear();

    assertEquals(0, cf.getNumConnections());

    conn1 = (JmsPoolConnection) cf.createConnection();
    conn2 = (JmsPoolConnection) cf.createConnection();
    conn3 = (JmsPoolConnection) cf.createConnection();

    assertNotSame(conn1.getConnection(), conn2.getConnection());
    assertNotSame(conn1.getConnection(), conn3.getConnection());
    assertNotSame(conn2.getConnection(), conn3.getConnection());

    cf.stop();
}
 
Example 10
Source File: QpidJmsPoolTestSupport.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
protected JmsPoolConnectionFactory createPooledConnectionFactory() {
    JmsPoolConnectionFactory cf = new JmsPoolConnectionFactory();
    cf.setConnectionFactory(qpidJmsConnectionFactory);
    cf.setMaxConnections(1);
    LOG.debug("ConnectionFactory initialized.");
    return cf;
}
 
Example 11
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout = 60000)
public void testFactoryStopStart() throws Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    cf.setMaxConnections(1);

    JmsPoolConnection conn1 = (JmsPoolConnection) cf.createConnection();

    cf.stop();

    assertNull(cf.createConnection());

    cf.start();

    JmsPoolConnection conn2 = (JmsPoolConnection) cf.createConnection();

    assertNotSame(conn1.getConnection(), conn2.getConnection());

    assertEquals(1, cf.getNumConnections());

    cf.stop();
}