Package org.hornetq.core.server.impl

Examples of org.hornetq.core.server.impl.QueueImpl$SynchronizedIterator


         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         QueueImpl queue = (QueueImpl)server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];
View Full Code Here


         ClientSessionFactory sf = locator.createSessionFactory();

         ClientSession session = sf.createSession(false, false, false);

         QueueImpl queue = (QueueImpl)server.createQueue(ADDRESS, ADDRESS, null, true, false);

         ClientProducer producer = session.createProducer(PagingTest.ADDRESS);

         byte[] body = new byte[messageSize];

         ByteBuffer bb = ByteBuffer.wrap(body);

         for (int j = 1; j <= messageSize; j++)
         {
            bb.put(getSamplebyte(j));
         }

         for (int i = 0; i < numberOfMessages; i++)
         {
            ClientMessage message = session.createMessage(persistentMessages);

            HornetQBuffer bodyLocal = message.getBodyBuffer();

            bodyLocal.writeBytes(body);

            message.putIntProperty(new SimpleString("id"), i);

            producer.send(message);
            if (i % 1000 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         session = sf.createSession(false, false, 0);

         session.start();

         ClientConsumer consumer = session.createConsumer(ADDRESS);

         // number of references without paging
         int numberOfRefs = queue.getNumberOfReferences();

         // consume all non-paged references
         for (int ref = 0; ref < numberOfRefs; ref++)
         {
            ClientMessage msg = consumer.receive(5000);
View Full Code Here

                            final SimpleString name,
                            final Filter filter,
                            final boolean durable,
                            final boolean temporary)
   {
      return new QueueImpl(persistenceID,
                           address,
                           name,
                           filter,
                           durable,
                           temporary,
View Full Code Here

   // The tests ----------------------------------------------------------------

   public void testScheduledNoConsumer() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  new SimpleString("queue1"),
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());

      // Send one scheduled

      long now = System.currentTimeMillis();

      MessageReference ref1 = generateReference(queue, 1);
      ref1.setScheduledDeliveryTime(now + 7000);
      queue.addLast(ref1);

      // Send some non scheduled messages

      MessageReference ref2 = generateReference(queue, 2);
      queue.addLast(ref2);
      MessageReference ref3 = generateReference(queue, 3);
      queue.addLast(ref3);
      MessageReference ref4 = generateReference(queue, 4);
      queue.addLast(ref4);

      // Now send some more scheduled messages

      MessageReference ref5 = generateReference(queue, 5);
      ref5.setScheduledDeliveryTime(now + 5000);
      queue.addLast(ref5);

      MessageReference ref6 = generateReference(queue, 6);
      ref6.setScheduledDeliveryTime(now + 4000);
      queue.addLast(ref6);

      MessageReference ref7 = generateReference(queue, 7);
      ref7.setScheduledDeliveryTime(now + 3000);
      queue.addLast(ref7);

      MessageReference ref8 = generateReference(queue, 8);
      ref8.setScheduledDeliveryTime(now + 6000);
      queue.addLast(ref8);

      List<MessageReference> refs = new ArrayList<MessageReference>();

      // Scheduled refs are added back to *FRONT* of queue - otherwise if there were many messages in the queue
      // They may get stranded behind a big backlog

      refs.add(ref1);
      refs.add(ref8);
      refs.add(ref5);
      refs.add(ref6);
      refs.add(ref7);

      refs.add(ref2);
      refs.add(ref3);
      refs.add(ref4);

      Thread.sleep(7500);

      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      queue.deliverNow();

      assertRefListsIdenticalRefs(refs, consumer.getReferences());
   }
View Full Code Here

      assertRefListsIdenticalRefs(refs, consumer.getReferences());
   }

   public void testScheduled() throws Exception
   {
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  new SimpleString("queue1"),
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());

      FakeConsumer consumer = null;

   
      // Send one scheduled

      long now = System.currentTimeMillis();

      MessageReference ref1 = generateReference(queue, 1);
      ref1.setScheduledDeliveryTime(now + 7000);
      queue.addLast(ref1);

      // Send some non scheduled messages

      MessageReference ref2 = generateReference(queue, 2);
      queue.addLast(ref2);
      MessageReference ref3 = generateReference(queue, 3);
      queue.addLast(ref3);
      MessageReference ref4 = generateReference(queue, 4);
      queue.addLast(ref4);

      // Now send some more scheduled messages

      MessageReference ref5 = generateReference(queue, 5);
      ref5.setScheduledDeliveryTime(now + 5000);
      queue.addLast(ref5);

      MessageReference ref6 = generateReference(queue, 6);
      ref6.setScheduledDeliveryTime(now + 4000);
      queue.addLast(ref6);

      MessageReference ref7 = generateReference(queue, 7);
      ref7.setScheduledDeliveryTime(now + 3000);
      queue.addLast(ref7);

      MessageReference ref8 = generateReference(queue, 8);
      ref8.setScheduledDeliveryTime(now + 6000);
      queue.addLast(ref8);

      consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      queue.deliverNow();
     

      List<MessageReference> refs = new ArrayList<MessageReference>();

      refs.add(ref2);
View Full Code Here

         {
            countDownLatch.countDown();
            return HandleStatus.HANDLED;
         }
      };
      QueueImpl queue = new QueueImpl(1,
                                  new SimpleString("address1"),
                                  QueueImplTest.queue1,
                                  null,
                                  false,
                                  true,
                                  scheduledExecutor,
                                  null,
                                  null,
                                  null,
                                  Executors.newSingleThreadExecutor());
      MessageReference messageReference = generateReference(queue, 1);
      queue.addConsumer(consumer);
      messageReference.setScheduledDeliveryTime(System.currentTimeMillis() + 2000);
      queue.addFirst(messageReference);

      boolean gotLatch = countDownLatch.await(3000, TimeUnit.MILLISECONDS);
      Assert.assertTrue(gotLatch);
   }
View Full Code Here

   /*
    * Concurrent set consumer not busy, busy then, call deliver while messages are being added and consumed
    */
   public void testConcurrentAddsDeliver() throws Exception
   {
      QueueImpl queue = (QueueImpl)queueFactory.createQueue(1,
                                             new SimpleString("address1"),
                                             new SimpleString("queue1"),
                                             null,
                                             false,
                                             false);

      FakeConsumer consumer = new FakeConsumer();

      queue.addConsumer(consumer);

      final long testTime = 5000;

      Sender sender = new Sender(queue, testTime);

      Toggler toggler = new Toggler(queue, consumer, testTime);

      sender.start();

      toggler.start();

      sender.join();

      toggler.join();

      consumer.setStatusImmediate(HandleStatus.HANDLED);

      queue.deliverNow();

      if (sender.getException() != null)
      {
         throw sender.getException();
      }
View Full Code Here

   public void testName()
   {
      final SimpleString name = new SimpleString("oobblle");

      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      name,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertEquals(name, queue.getName());
   }
View Full Code Here

      Assert.assertEquals(name, queue.getName());
   }

   public void testDurable()
   {
      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      false,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertFalse(queue.isDurable());

      queue = new QueueImpl(1,
                            QueueImplTest.address1,
                            QueueImplTest.queue1,
                            null,
                            true,
                            false,
                            scheduledExecutor,
                            null,
                            null,
                            null,
                            executor);

      Assert.assertTrue(queue.isDurable());
   }
View Full Code Here

      Consumer cons2 = new FakeConsumer();

      Consumer cons3 = new FakeConsumer();

      QueueImpl queue = new QueueImpl(1,
                                      QueueImplTest.address1,
                                      QueueImplTest.queue1,
                                      null,
                                      false,
                                      true,
                                      scheduledExecutor,
                                      null,
                                      null,
                                      null,
                                      executor);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.addConsumer(cons1);

      Assert.assertEquals(1, queue.getConsumerCount());

      queue.removeConsumer(cons1);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.addConsumer(cons1);

      queue.addConsumer(cons2);

      queue.addConsumer(cons3);

      Assert.assertEquals(3, queue.getConsumerCount());

      queue.removeConsumer(new FakeConsumer());

      Assert.assertEquals(3, queue.getConsumerCount());

      queue.removeConsumer(cons1);

      Assert.assertEquals(2, queue.getConsumerCount());

      queue.removeConsumer(cons2);

      Assert.assertEquals(1, queue.getConsumerCount());

      queue.removeConsumer(cons3);

      Assert.assertEquals(0, queue.getConsumerCount());

      queue.removeConsumer(cons3);
   }
View Full Code Here

TOP

Related Classes of org.hornetq.core.server.impl.QueueImpl$SynchronizedIterator

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.