Package org.apache.activemq

Examples of org.apache.activemq.ActiveMQConnection


        ByteSequence content = getContent();
        if (content == null && text != null) {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            OutputStream os = bytesOut;
            ActiveMQConnection connection = getConnection();
            if (connection != null && connection.isUseCompression()) {
                compressed = true;
                os = new DeflaterOutputStream(os);
            }
            DataOutputStream dataOut = new DataOutputStream(os);
            MarshallingSupport.writeUTF8(dataOut, this.text);
View Full Code Here


                error("Producer failed", e);
            }
        }

        private void sendMessages() throws JMSException {
            ActiveMQConnection connection = null;

            try {
                connection = (ActiveMQConnection) connectionFactory.createConnection();
                connection.setExceptionListener(this);
                connection.start();

                sendMessages(connection);
            } finally {
                if (connection != null) {
                    try {
                        connection.close();
                    } catch (JMSException e) {
                        error("Problem closing connection", e);
                    }
                }
            }
View Full Code Here

       * Test the case where the broker is blocked due to a memory limit
       * and a producer timeout is set on the connection.
       * @throws Exception
       */
      public void testBlockedProducerConnectionTimeout() throws Exception {
          final ActiveMQConnection cx = (ActiveMQConnection)createConnection();
          final ActiveMQDestination queue = createDestination("testqueue");
         
          // we should not take longer than 10 seconds to return from send
          cx.setSendTimeout(10000);
           
          Runnable r = new Runnable() {
              public void run() {
                  try {
                    LOG.info("Sender thread starting");
                      Session session = cx.createSession(false, 1);
                      MessageProducer producer = session.createProducer(queue);
                      producer.setDeliveryMode(DeliveryMode.PERSISTENT);
                     
                      TextMessage message = session.createTextMessage(createMessageText());
                      for(int count=0; count<messageCount; count++){
                        producer.send(message);
                      }   
                      LOG.info("Done sending..");
                    } catch (JMSException e) {
                        if (e.getCause() instanceof RequestTimedOutIOException) {
                          exceptionCount.incrementAndGet();
                        } else {
                            e.printStackTrace();
                        }
                      return;
                  }

              }
          };
          cx.start();
          Thread producerThread = new Thread(r);
          producerThread.start();
          producerThread.join(30000);
          cx.close();
          // We should have a few timeout exceptions as memory store will fill up
          assertTrue("No exception from the broker", exceptionCount.get() > 0);
      }
View Full Code Here

       * Test the case where the broker is blocked due to a memory limit
       * with a fail timeout
       * @throws Exception
       */
      public void testBlockedProducerUsageSendFailTimeout() throws Exception {
          final ActiveMQConnection cx = (ActiveMQConnection)createConnection();
          final ActiveMQDestination queue = createDestination("testqueue");

            broker.getSystemUsage().setSendFailIfNoSpaceAfterTimeout(5000);
          Runnable r = new Runnable() {
              public void run() {
                  try {
                    LOG.info("Sender thread starting");
                      Session session = cx.createSession(false, 1);
                      MessageProducer producer = session.createProducer(queue);
                      producer.setDeliveryMode(DeliveryMode.PERSISTENT);

                      TextMessage message = session.createTextMessage(createMessageText());
                      for(int count=0; count<messageCount; count++){
                        producer.send(message);
                      }
                      LOG.info("Done sending..");
                    } catch (JMSException e) {
                        if (e instanceof ResourceAllocationException || e.getCause() instanceof RequestTimedOutIOException) {
                          exceptionCount.incrementAndGet();
                        } else {
                            e.printStackTrace();
                        }
                      return;
                  }

              }
          };
          cx.start();
          Thread producerThread = new Thread(r);
          producerThread.start();
          producerThread.join(30000);
          cx.close();
          // We should have a few timeout exceptions as memory store will fill up
          assertTrue("No exception from the broker", exceptionCount.get() > 0);
      }
View Full Code Here

    }
   
    protected void createClients() throws Exception {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(CLIENT_URL);
        for (int i =0;i < NUMBER; i++) {
            ActiveMQConnection c = (ActiveMQConnection) factory.createConnection();
            c.start();
            Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
            Queue queue  = s.createQueue(getClass().getName());
            MessageConsumer consumer = s.createConsumer(queue);
            connections.add(c);
        }
    }
View Full Code Here

    private void initializeWriting() throws MessageNotWriteableException {
        checkReadOnlyBody();
        if (this.dataOut == null) {
            this.bytesOut = new ByteArrayOutputStream();
            OutputStream os = bytesOut;
            ActiveMQConnection connection = getConnection();
            if (connection!=null && connection.isUseCompression()) {
                compressed = true;
                os = new DeflaterOutputStream(os);
            }
            this.dataOut = new DataOutputStream(os);
        }
View Full Code Here

    protected void checkValidObject(Object value) throws MessageFormatException {
        if (!(value instanceof Boolean || value instanceof Byte || value instanceof Short || value instanceof Integer || value instanceof Long
                || value instanceof Float || value instanceof Double || value instanceof Character || value instanceof String || value == null)) {

            ActiveMQConnection conn = getConnection();
            // conn is null if we are in the broker rather than a JMS client
            if (conn == null || conn.isNestedMapAndListEnabled()) {
                if (!(value instanceof Map || value instanceof List)) {
                    throw new MessageFormatException("Only objectified primitive objects, String, Map and List types are allowed but was: " + value + " type: "
                            + value.getClass());
                }
            }
View Full Code Here

    private void storeContent() {
        try {
            if( getContent()==null && !map.isEmpty()) {
                ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
                OutputStream os = bytesOut;
                ActiveMQConnection connection = getConnection();
                if( connection!= null && connection.isUseCompression() ) {
                    compressed = true;
                    os = new DeflaterOutputStream(os);
                }
                DataOutputStream dataOut = new DataOutputStream(os);
                MarshallingSupport.marshalPrimitiveMap(map, dataOut);
View Full Code Here

       
        ByteSequence content = getContent();
        if (content == null && text!=null ) {
            ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
            OutputStream os = bytesOut;
            ActiveMQConnection connection = getConnection();
            if( connection!=null && connection.isUseCompression() ) {
                compressed = true;
                os = new DeflaterOutputStream(os);
            }
            DataOutputStream dataOut = new DataOutputStream(os);
            MarshallingSupport.writeUTF8(dataOut, text);
View Full Code Here

    private int rollbackCount;

    protected void doTest() throws Exception {
        connection.start();

        ActiveMQConnection amqConnection = (ActiveMQConnection) connection;
        rollbackCount = amqConnection.getRedeliveryPolicy().getMaximumRedeliveries() + 1;
        log.info("Will redeliver messages: " + rollbackCount + " times");

        makeConsumer();
        makeDlqConsumer();
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.