Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQConnection


    }
  }

  public void run() {
    // Connection connection = null;
    ActiveMQConnection connection = null;
    try {
      // Create the connection.
      ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
      connection = (ActiveMQConnection) connectionFactory.createConnection();
      connection.start();
      // Create the session
      Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
      if (topic) {
        destination = session.createTopic(subject);
      }
      else {
        destination = session.createQueue(subject);
      }
      // Create the producer.
      MessageProducer producer = session.createProducer(destination);
      if (persistent) {
        producer.setDeliveryMode(DeliveryMode.PERSISTENT);
      }
      else {
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
      }
      if (timeToLive != 0) {
        producer.setTimeToLive(timeToLive);
      }
      // Start sending messages
      sendLoop4File(connection, destination, session, producer);
      System.out.println("[" + this.getName() + "] Done.");
      synchronized (lockResults) {
        ActiveMQConnection c = (ActiveMQConnection) connection;
        System.out.println("[" + this.getName() + "] Results:\n");
        c.getConnectionStats().dump(new IndentPrinter());
      }
    }
    catch (Exception e) {
      System.out.println("[" + this.getName() + "] Caught: " + e);
      e.printStackTrace();
View Full Code Here


        }
    }

    public void run() {
//        Connection connection = null;
      ActiveMQConnection  connection = null;
        try {
            // Create the connection.
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(user, password, url);
            connection = (ActiveMQConnection) connectionFactory.createConnection();
            connection.start();

            // Create the session
            Session session = connection.createSession(transacted, Session.AUTO_ACKNOWLEDGE);
            if (topic) {
                destination = session.createTopic(subject);
            } else {
                destination = session.createQueue(subject);
            }
           
           
            // Create the producer.
            MessageProducer producer = session.createProducer(destination);
            if (persistent) {
                producer.setDeliveryMode(DeliveryMode.PERSISTENT);
            } else {
                producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
            }
            if (timeToLive != 0) {
                producer.setTimeToLive(timeToLive);
            }

            // Start sending messages
            sendLoop(session, producer);

            System.out.println("[" + this.getName() + "] Done.");

            synchronized (lockResults) {
                ActiveMQConnection c = (ActiveMQConnection) connection;
                System.out.println("[" + this.getName() + "] Results:\n");
                c.getConnectionStats().dump(new IndentPrinter());
            }

        } catch (Exception e) {
            System.out.println("[" + this.getName() + "] Caught: " + e);
            e.printStackTrace();
View Full Code Here

                physConnection = ((PooledConnection)connection).getConnection();
            } catch (JMSException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }
        ActiveMQConnection aConnection = (ActiveMQConnection)physConnection;
        return aConnection;
    }
View Full Code Here

    @Test
    public void testCreateObject() throws Exception {
        ConnectionFactoryResource pool = new ConnectionFactoryResource(1, connectionFactory);
        pool.fillPool();
        assertNotNull(pool);
        ActiveMQConnection connection = (ActiveMQConnection) pool.makeObject();
        assertNotNull(connection);
        assertTrue(connection.isStarted());
        pool.drainPool();
    }
View Full Code Here

    @Test
    public void testDestroyObject() throws Exception {
        ConnectionFactoryResource pool = new ConnectionFactoryResource(1, connectionFactory);
        pool.fillPool();
        assertNotNull(pool);
        ActiveMQConnection connection = (ActiveMQConnection) pool.makeObject();
        assertNotNull(connection);
        assertTrue(connection.isStarted());
        pool.drainPool();
        assertTrue(pool.size() == 0);
    }
View Full Code Here

    @Test(expected = NoSuchElementException.class)
    public void testBorrowObject() throws Exception {
        ConnectionFactoryResource pool = new ConnectionFactoryResource(1, connectionFactory);
        pool.fillPool();
        assertNotNull(pool);
        ActiveMQConnection connection = (ActiveMQConnection) pool.borrowConnection();
        assertNotNull(connection);
        assertTrue(connection.isStarted());
        pool.borrowConnection();
    }
View Full Code Here

    @Test
    public void testReturnObject() throws Exception {
        ConnectionFactoryResource pool = new ConnectionFactoryResource(1, connectionFactory);
        pool.fillPool();
        assertNotNull(pool);
        ActiveMQConnection connection = (ActiveMQConnection) pool.borrowConnection();
        assertNotNull(connection);
        assertTrue(connection.isStarted());
        pool.returnConnection(connection);
        ActiveMQConnection connection2 = (ActiveMQConnection) pool.borrowConnection();
        assertNotNull(connection2);
        pool.drainPool();
    }
View Full Code Here

    @Test
    public void testRoundRobbin() throws Exception {
        ConnectionFactoryResource pool = new ConnectionFactoryResource(2, connectionFactory);
        pool.fillPool();
        assertNotNull(pool);
        ActiveMQConnection connection = (ActiveMQConnection) pool.borrowConnection();
        assertNotNull(connection);
        assertTrue(connection.isStarted());
        pool.returnConnection(connection);
        ActiveMQConnection connection2 = (ActiveMQConnection) pool.borrowConnection();
        assertNotNull(connection2);
        assertNotEquals(connection, connection2);
        pool.drainPool();
    }
View Full Code Here

            sendLoop(session, producer);

            System.out.println("[" + this.getName() + "] Done.");

            synchronized (lockResults) {
                ActiveMQConnection c = (ActiveMQConnection) connection;
                System.out.println("[" + this.getName() + "] Results:\n");
                c.getConnectionStats().dump(new IndentPrinter());
            }

        } catch (Exception e) {
            System.out.println("[" + this.getName() + "] Caught: " + e);
            e.printStackTrace();
View Full Code Here

        return false;
    }

    private BrokerInfo getBrokerInfo(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
        ActiveMQConnectionFactory connectionFactory = createActiveMQConnectionFactory(portletRequest, destinationInfo);
        ActiveMQConnection connection = null;
        try {
            connection = (ActiveMQConnection) connectionFactory.createConnection();
            connection.start();
            return connection.getBrokerInfo();
        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (Exception e) {
                }
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.activemq.ActiveMQConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.