Package org.hornetq.core.server

Examples of org.hornetq.core.server.Queue


         ClientSessionFactory sf = locator.createSessionFactory();

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

         Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

         Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), 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));
         }

         final AtomicInteger errors = new AtomicInteger(0);

         Thread t1 = new Thread()
         {
            public void run()
            {
               try
               {
                  ServerLocator sl = createInVMNonHALocator();
                  ClientSessionFactory sf = sl.createSessionFactory();
                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < numberOfMessages; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }

                  assertNull(cons.receiveImmediate());
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

         t1.start();

         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 % 20 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         t1.join();

         assertEquals(0, errors.get());

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(0, q1.getMessageCount());
         assertEquals(numberOfMessages, q1.getMessagesAdded());

         session.close();
         sf.close();
         locator.close();

         server.stop();

         server.start();

         Bindings bindings = server.getPostOffice().getBindingsForAddress(ADDRESS);

         q1 = null;
         q2 = null;

         for (Binding bind : bindings.getBindings())
         {
            if (bind instanceof LocalQueueBinding)
            {
               LocalQueueBinding qb = (LocalQueueBinding)bind;
               if (qb.getQueue().getName().equals(ADDRESS))
               {
                  q1 = qb.getQueue();
               }

               if (qb.getQueue().getName().equals(new SimpleString("inactive")))
               {
                  q2 = qb.getQueue();
               }
            }
         }

         assertNotNull(q1);

         assertNotNull(q2);

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(0, q1.getMessageCount());
         // 0, since nothing was sent to the queue after the server was restarted
         assertEquals(0, q1.getMessagesAdded());

      }
View Full Code Here


         ClientSessionFactory sf = locator.createSessionFactory();

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

         Queue q1 = server.createQueue(ADDRESS, ADDRESS, null, true, false);

         Queue q2 = server.createQueue(ADDRESS, new SimpleString("inactive"), 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));
         }

         final AtomicInteger errors = new AtomicInteger(0);

         Thread t1 = new Thread()
         {
            public void run()
            {
               try
               {
                  ServerLocator sl = createInVMNonHALocator();
                  ClientSessionFactory sf = sl.createSessionFactory();
                  ClientSession sess = sf.createSession(true, true, 0);
                  sess.start();
                  ClientConsumer cons = sess.createConsumer(ADDRESS);
                  for (int i = 0; i < 100; i++)
                  {
                     ClientMessage msg = cons.receive(5000);
                     assertNotNull(msg);
                     assertEquals(i, msg.getIntProperty("id").intValue());
                     msg.acknowledge();
                  }
                  sess.close();
                  sl.close();
               }
               catch (Throwable e)
               {
                  e.printStackTrace();
                  errors.incrementAndGet();
               }

            }
         };

         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 % 20 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         t1.start();
         t1.join();

         assertEquals(0, errors.get());
         long timeout = System.currentTimeMillis() + 10000;
         while (numberOfMessages - 100 != q1.getMessageCount() && System.currentTimeMillis() < timeout)
         {
            Thread.sleep(500);

         }

         assertEquals(numberOfMessages, q2.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());
         assertEquals(numberOfMessages - 100, q1.getMessageCount());
         assertEquals(numberOfMessages, q2.getMessagesAdded());

      }
      catch (Throwable e)
      {
         e.printStackTrace();
View Full Code Here

               e.printStackTrace();
            }
         }
      };

      Queue queue = new FakeQueue(new SimpleString("a"));
      t.start();

      for (int i = 0; i < 100; i++)
      {
         if (route)
View Full Code Here

         // Inserting the duplicateIDs so the bridge will fail in a few
         {
            long ids[] = new long[100];

            Queue queue = server0.locateQueue(new SimpleString(queueName0));
            LinkedListIterator<MessageReference> iterator = queue.iterator();

            for (int i = 0; i < 100; i++)
            {
               iterator.hasNext();
               ids[i] = iterator.next().getMessage().getMessageID();
View Full Code Here

      if (binding == null)
      {
         throw new HornetQException(HornetQException.QUEUE_DOES_NOT_EXIST, "No such queue " + queueName);
      }

      Queue queue = (Queue)binding.getBindable();
     
      queue.getPageSubscription().close();

      if (queue.getConsumerCount() != 0)
      {
         throw new HornetQException(HornetQException.ILLEGAL_STATE, "Cannot delete queue " + queue.getName() +
                                                                    " on binding " +
                                                                    queueName +
                                                                    " - it has consumers = " +
                                                                    binding.getClass().getName());
      }

      if (session != null)
      {
         if (queue.isDurable())
         {
            // make sure the user has privileges to delete this queue
            securityStore.check(binding.getAddress(), CheckType.DELETE_DURABLE_QUEUE, session);
         }
         else
         {
            securityStore.check(binding.getAddress(), CheckType.DELETE_NON_DURABLE_QUEUE, session);
         }
      }

      queue.deleteAllReferences();

      if (queue.isDurable())
      {
         storageManager.deleteQueueBinding(queue.getID());
      }

      postOffice.removeBinding(queueName);
   }
View Full Code Here

        
         Filter filter = FilterImpl.createFilter(queueBindingInfo.getFilterString());

         PageSubscription subscription = pagingManager.getPageStore(queueBindingInfo.getAddress()).getCursorProvier().createSubscription(queueBindingInfo.getId(), filter, true);
        
         Queue queue = queueFactory.createQueue(queueBindingInfo.getId(),
                                                queueBindingInfo.getAddress(),
                                                queueBindingInfo.getQueueName(),
                                                filter,
                                                subscription,
                                                true,
View Full Code Here

     
      long queueID = storageManager.generateUniqueID();

      PageSubscription pageSubscription = pagingManager.getPageStore(address).getCursorProvier().createSubscription(queueID, filter, durable);

      final Queue queue = queueFactory.createQueue(queueID,
                                                   address,
                                                   queueName,
                                                   filter,
                                                   pageSubscription,
                                                   durable,
View Full Code Here

         server.start();

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         for (int i = 0; i < numberOfTX; i++)
         {
            ClientSession sessionConsumer = sf.createSession(true, false, false);
            Xid xid = newXID();
            xids.add(xid);
            sessionConsumer.start(xid, XAResource.TMNOFLAGS);
            sessionConsumer.start();
            ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
            for (int msgCount = 0; msgCount < messagesPerTX; msgCount++)
            {
               if (msgReceived == numberOfMessages)
               {
                  break;
               }
               msgReceived++;
               ClientMessage msg = consumer.receive(10000);
               assertNotNull(msg);
               msg.acknowledge();
            }
            sessionConsumer.end(xid, XAResource.TMSUCCESS);
            sessionConsumer.prepare(xid);
            sessionConsumer.close();
         }

         ClientSession sessionCheck = sf.createSession(true, true);

         ClientConsumer consumer = sessionCheck.createConsumer(PagingTest.ADDRESS);

         assertNull(consumer.receiveImmediate());

         sessionCheck.close();

         assertEquals(numberOfMessages, queue.getMessageCount());

         sf.close();
         locator.close();

         server.stop();

         server = createServer(true,
                               config,
                               PagingTest.PAGE_SIZE,
                               PagingTest.PAGE_MAX,
                               new HashMap<String, AddressSettings>());
         server.start();

         waitForServer(server);

         queue = server.locateQueue(ADDRESS);

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

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

         consumer = session.createConsumer(PagingTest.ADDRESS);

         session.start();

         assertEquals(numberOfMessages, queue.getMessageCount());

         ClientMessage msg = consumer.receive(5000);
         if (msg != null)
         {
            System.out.println("Msg " + msg.getIntProperty("id"));

            while (true)
            {
               ClientMessage msg2 = consumer.receive(1000);
               if (msg2 == null)
               {
                  break;
               }
               System.out.println("Msg received again : " + msg2.getIntProperty("id"));

            }
         }
         assertNull(msg);

         for (int i = xids.size() - 1; i >= 0; i--)
         {
            Xid xid = xids.get(i);
            session.rollback(xid);
         }
         System.out.println("msgCount = " + queue.getMessageCount());

         xids.clear();

         session.close();

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

         session.start();

         consumer = session.createConsumer(PagingTest.ADDRESS);

         for (int i = 0; i < numberOfMessages; i++)
         {
            msg = consumer.receive(1000);
            assertNotNull(msg);
            msg.acknowledge();

            assertEquals(i, msg.getIntProperty("id").intValue());

            if (i % 500 == 0)
            {
               session.commit();
            }
         }

         session.commit();

         session.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());

         long timeout = System.currentTimeMillis() + 5000;
         while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging())
         {
            Thread.sleep(100);
         }
         assertFalse(queue.getPageSubscription().getPagingStore().isPaging());
      }
      finally
      {
         try
         {
View Full Code Here

         server.start();

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         ClientSession sessionConsumer = sf.createSession(false, false, false);
         sessionConsumer.start();
         ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
         for (int msgCount = 0; msgCount < numberOfMessages; msgCount++)
         {
            log.info("Received " + msgCount);
            msgReceived++;
            ClientMessage msg = consumer.receiveImmediate();
            if (msg == null)
            {
               log.info("It's null. leaving now");
               sessionConsumer.commit();
               fail("Didn't receive a message");
            }
            msg.acknowledge();

            if (msgCount % 5 == 0)
            {
               log.info("commit");
               sessionConsumer.commit();
            }
         }

         sessionConsumer.commit();

         sessionConsumer.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());

         long timeout = System.currentTimeMillis() + 5000;
         while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging())
         {
            Thread.sleep(100);
         }
         assertFalse(queue.getPageSubscription().getPagingStore().isPaging());
      }
      finally
      {
         try
         {
View Full Code Here

         server.start();

         locator = createInVMNonHALocator();
         sf = locator.createSessionFactory();

         Queue queue = server.locateQueue(ADDRESS);

         assertEquals(numberOfMessages, queue.getMessageCount());

         LinkedList<Xid> xids = new LinkedList<Xid>();

         int msgReceived = 0;
         ClientSession sessionConsumer = sf.createSession(false, false, false);
         sessionConsumer.start();
         ClientConsumer consumer = sessionConsumer.createConsumer(PagingTest.ADDRESS);
         for (int msgCount = 0; msgCount < numberOfMessages; msgCount++)
         {
            log.info("Received " + msgCount);
            msgReceived++;
            ClientMessage msg = consumer.receiveImmediate();
            if (msg == null)
            {
               log.info("It's null. leaving now");
               sessionConsumer.commit();
               fail("Didn't receive a message");
            }
            msg.acknowledge();

            if (msgCount % 5 == 0)
            {
               log.info("commit");
               sessionConsumer.commit();
            }
         }

         sessionConsumer.commit();

         sessionConsumer.close();

         sf.close();

         locator.close();

         assertEquals(0, queue.getMessageCount());

         long timeout = System.currentTimeMillis() + 5000;
         while (timeout > System.currentTimeMillis() && queue.getPageSubscription().getPagingStore().isPaging())
         {
            Thread.sleep(100);
         }
         assertFalse(queue.getPageSubscription().getPagingStore().isPaging());

         server.stop();

         // Deleting the paging data. Simulating a failure
         // a dumb user, or anything that will remove the data
View Full Code Here

TOP

Related Classes of org.hornetq.core.server.Queue

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.