Package org.jboss.messaging.core.plugin.postoffice.cluster

Examples of org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue$MessagePullRequestRunnable


              
               binding = postOffice.bindQueue(topicCond, q);
            }
            else
           
               q = new LocalClusteredQueue((ClusteredPostOffice)postOffice, nodeId, new GUID().toString(),
                                           idm.getID(), ms, pm, true, false,
                                           mDest.getMaxSize(), selector, tr,
                                           mDest.getFullSize(),
                                           mDest.getPageSize(),
                                           mDest.getDownCacheSize());
              
               ClusteredPostOffice cpo = (ClusteredPostOffice)postOffice;

               binding = cpo.bindClusteredQueue(topicCond, (LocalClusteredQueue)q);
            }
            String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + q.getName();
 
            int dayLimitToUse = mDest.getMessageCounterHistoryDayLimit();
            if (dayLimitToUse == -1)
            {
               //Use override on server peer
               dayLimitToUse = sp.getDefaultMessageCounterHistoryDayLimit();
            }
           
            MessageCounter counter =
               new MessageCounter(counterName, null, q, true, false,
                                  dayLimitToUse);
           
            sp.getMessageCounterManager().registerMessageCounter(counterName, counter);
         }
         else
         {
            if (jmsDestination.isTemporary())
            {
               throw new InvalidDestinationException("Cannot create a durable subscription on a temporary topic");
            }
           
            // We have a durable subscription, look it up
            String clientID = connectionEndpoint.getClientID();
            if (clientID == null)
            {
               throw new JMSException("Cannot create durable subscriber without a valid client ID");
            }
           
            // See if there any bindings with the same client_id.subscription_name name
           
            String name = MessageQueueNameHelper.createSubscriptionName(clientID, subscriptionName);
           
            binding = postOffice.getBindingForQueueName(name);
           
            if (binding == null)
            {
               // Does not already exist
              
               if (trace) { log.trace(this + " creating new durable subscription on " + jmsDestination); }
                             
               PagingFilteredQueue q;

               if (postOffice.isLocal())
               {
                  q = new PagingFilteredQueue(name, idm.getID(), ms, pm, true, true,
                                              mDest.getMaxSize(), selector,
                                              mDest.getFullSize(),
                                              mDest.getPageSize(),
                                              mDest.getDownCacheSize());

                  binding = postOffice.bindQueue(topicCond, q);
               }
               else
               {
                  q = new LocalClusteredQueue((ClusteredPostOffice)postOffice, nodeId, name, idm.getID(),
                                              ms, pm, true, true,
                                              mDest.getMaxSize(), selector, tr,
                                              mDest.getFullSize(),
                                              mDest.getPageSize(),
                                              mDest.getDownCacheSize());
                 
                  ClusteredPostOffice cpo = (ClusteredPostOffice)postOffice;
                 
                  if (mDest.isClustered())
                  {
                     binding = cpo.bindClusteredQueue(topicCond, (LocalClusteredQueue)q);
                  }
                  else
                  {
                     binding = cpo.bindQueue(topicCond, q);
                  }
               }
               String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + q.getName();
                      
               MessageCounter counter =
                  new MessageCounter(counterName, subscriptionName, q, true, true,
                                     mDest.getMessageCounterHistoryDayLimit());
              
               sp.getMessageCounterManager().registerMessageCounter(counterName, counter);
            }
            else
            {
               //Durable sub already exists
              
               if (trace) { log.trace(this + " subscription " + subscriptionName + " already exists"); }
              
               // From javax.jms.Session Javadoc (and also JMS 1.1 6.11.1):
               // A client can change an existing durable subscription by creating a durable
               // TopicSubscriber with the same name and a new topic and/or message selector.
               // Changing a durable subscriber is equivalent to unsubscribing (deleting) the old
               // one and creating a new one.
              
               String filterString =
                  binding.getQueue().getFilter() != null ?
                     binding.getQueue().getFilter().getFilterString() : null;
              
               boolean selectorChanged =
                  (selectorString == null && filterString != null) ||
                  (filterString == null && selectorString != null) ||
                  (filterString != null && selectorString != null &&
                           !filterString.equals(selectorString));
              
               if (trace) { log.trace("selector " + (selectorChanged ? "has" : "has NOT") + " changed"); }
              
               JMSCondition cond = (JMSCondition)binding.getCondition();
              
               boolean topicChanged = !cond.getName().equals(jmsDestination.getName());
              
               if (log.isTraceEnabled()) { log.trace("topic " + (topicChanged ? "has" : "has NOT") + " changed"); }
              
               if (selectorChanged || topicChanged)
               {
                  if (trace) { log.trace("topic or selector changed so deleting old subscription"); }
                 
                  // Unbind the durable subscription
                 
                  if (mDest.isClustered() && !postOffice.isLocal())
                  {
                     ClusteredPostOffice cpo = (ClusteredPostOffice)postOffice;
                    
                     cpo.unbindClusteredQueue(name);
                  }
                  else
                  {
                     postOffice.unbindQueue(name);
                  }
                 
                  // create a fresh new subscription
                                   
                  PagingFilteredQueue q;
                 
                  if (postOffice.isLocal())
                  {
                     q = new PagingFilteredQueue(name, idm.getID(), ms, pm, true, true,
                              mDest.getMaxSize(), selector,
                              mDest.getFullSize(),
                              mDest.getPageSize(),
                              mDest.getDownCacheSize());
                     binding = postOffice.bindQueue(topicCond, q);
                  }
                  else
                  {
                     q = new LocalClusteredQueue((ClusteredPostOffice)postOffice, nodeId, name, idm.getID(), ms, pm, true, true,
                              mDest.getMaxSize(), selector, tr,
                              mDest.getFullSize(),
                              mDest.getPageSize(),
                              mDest.getDownCacheSize());
                    
View Full Code Here


            }
            else
            {
               ClusteredPostOffice cpo = (ClusteredPostOffice)postOffice;
              
               queue = new LocalClusteredQueue((ClusteredPostOffice)postOffice, nodeId, destination.getName(),
                        idm.getID(), ms, pm, true, true,
                        destination.getMaxSize(), null, tr,
                        destination.getFullSize(), destination.getPageSize(),
                        destination.getDownCacheSize());
              
View Full Code Here

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);
         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue2", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
            office2.bindClusteredQueue(new SimpleCondition("topic1"), queue2);

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue3", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
            office3.bindClusteredQueue(new SimpleCondition("topic1"), queue3);

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue2.add(receiver2);
         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue3.add(receiver3);

         //This will make it fail after casting but before persisting the message in the db
         office1.setFail(true, false, false);

         Transaction tx = tr.createTransaction();
View Full Code Here

            createClusteredPostOffice(2, "testgroup", sc, ms, pm, tr);

         office3 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(3, "testgroup", sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("topic1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue2", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("topic1"), queue2);

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue3", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office3.bindClusteredQueue(new SimpleCondition("topic1"), queue3);

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue2.add(receiver2);
         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);
         queue3.add(receiver3);

         //This will make it fail after casting and persisting the message in the db
         office1.setFail(false, true, false);

         Transaction tx = tr.createTransaction();
View Full Code Here

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);

         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         // Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         // Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         // Pull from 1 to 2

         receiver2.setMaxRefs(1);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("r2 " + receiver2.getMessages().size());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(1, queue2.getDeliveringCount());

         this.acknowledgeAll(receiver2);

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

      }
View Full Code Here

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         //Force a failure before commit
         office2.setFail(true, false, false);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertEquals(1, office1.getHoldingTransactions().size());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(1, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         //Now kill office 2 - this should cause office1 to remove the dead held transaction

         office2.stop();
         Thread.sleep(2000);
View Full Code Here

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         //Force a failure after commit the ack to storage
         office2.setFail(false, true, false);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         assertEquals(1, office1.getHoldingTransactions().size());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(1, queue1.getDeliveringCount());

         //Now kill office 2 - this should cause office1 to remove the dead held transaction
View Full Code Here

         office2 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(2, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, true, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         Message msg = CoreMessageFactory.createCoreMessage(1, true, null);

         MessageReference ref = ms.reference(msg);

         office1.route(ref, new SimpleCondition("queue1"), null);

         Thread.sleep(2000);

         //Messages should all be in queue1

         List msgs = queue1.browse();
         assertEquals(1, msgs.size());

         msgs = queue2.browse();
         assertTrue(msgs.isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver1.setMaxRefs(0);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         receiver2.setMaxRefs(0);
         queue2.add(receiver2);

         //Prompt delivery so the channels know if the receivers are ready
         queue1.deliver();
         Thread.sleep(2000);

         //Pull from 1 to 2

         receiver2.setMaxRefs(1);

         office2.setFail(false, false, true);

         log.trace("delivering");
         queue2.deliver();

         Thread.sleep(3000);

         //The delivery should be rolled back

         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());

         log.trace("queue1 refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2 refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());

         assertEquals(1, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());
      }
      finally
      {
         if (office1 != null)
         {
View Full Code Here

            createClusteredPostOffice(5, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         log.trace("Created postoffices");

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);

         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);

         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);

         log.trace("Created and bound queues");

         final int NUM_MESSAGES = 100;

         log.trace("sending messages");
         this.sendMessages("queue1", persistent, office1, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office2, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office3, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office4, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office5, NUM_MESSAGES, null);

         log.trace("sent messages");

         Thread.sleep(2000);


         log.trace("Finished small sleep");

         //Check the sizes

         log.trace("Here are the sizes:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         log.trace("Creating receiver");

         SimpleReceiver receiver = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING);

         log.trace("Created receiver");

         queue1.add(receiver);

         log.trace("Added receiver");

         queue1.deliver();

         log.trace("Called deliver");

         log.trace("Waiting for handleInvocations");
         long start = System.currentTimeMillis();
         readOK = receiver.waitForHandleInvocations(NUM_MESSAGES * 5, 60000);
         long end = System.currentTimeMillis();
         log.trace("I waited for " + (end - start) + " ms");

         assertTrue(readOK);

         Thread.sleep(2000);


         log.trace("Here are the sizes:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(NUM_MESSAGES * 5, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(0, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(0, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(0, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         List messages = receiver.getMessages();

         assertNotNull(messages);

View Full Code Here

         office5 = (DefaultClusteredPostOffice)
            createClusteredPostOffice(5, "testgroup", 10000, 10000, new DefaultMessagePullPolicy(),
                                      sc, ms, pm, tr);

         LocalClusteredQueue queue1 =
            new LocalClusteredQueue(office1, 1, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office1.bindClusteredQueue(new SimpleCondition("queue1"), queue1);

         LocalClusteredQueue queue2 =
            new LocalClusteredQueue(office2, 2, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office2.bindClusteredQueue(new SimpleCondition("queue1"), queue2);

         LocalClusteredQueue queue3 =
            new LocalClusteredQueue(office3, 3, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office3.bindClusteredQueue(new SimpleCondition("queue1"), queue3);

         LocalClusteredQueue queue4 =
            new LocalClusteredQueue(office4, 4, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office4.bindClusteredQueue(new SimpleCondition("queue1"), queue4);

         LocalClusteredQueue queue5 =
            new LocalClusteredQueue(office5, 5, "queue1", channelIDManager.getID(), ms, pm,
                                    true, recoverable, -1, null, tr);
         office5.bindClusteredQueue(new SimpleCondition("queue1"), queue5);

         final int NUM_MESSAGES = 100;

         this.sendMessages("queue1", persistent, office1, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office2, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office3, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office4, NUM_MESSAGES, null);
         this.sendMessages("queue1", persistent, office5, NUM_MESSAGES, null);

         Thread.sleep(2000);

         // Check the sizes

         log.trace("Here are the sizes 1:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(NUM_MESSAGES, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         SimpleReceiver receiver1 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue1.add(receiver1);
         SimpleReceiver receiver2 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue2.add(receiver2);
         SimpleReceiver receiver3 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue3.add(receiver3);
         SimpleReceiver receiver4 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue4.add(receiver4);
         SimpleReceiver receiver5 = new SimpleReceiver("blah", SimpleReceiver.ACCEPTING_TO_MAX);
         queue5.add(receiver5);

         receiver1.setMaxRefs(5);
         queue1.deliver();
         readOK = receiver1.waitForHandleInvocations(5, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 5, queue1.memoryRefCount());
         assertEquals(5, queue1.getDeliveringCount());

         acknowledgeAll(receiver1);
         assertEquals(0, queue1.getDeliveringCount());
         receiver1.setMaxRefs(0);

         receiver2.setMaxRefs(10);
         queue2.deliver();
         readOK = receiver2.waitForHandleInvocations(10, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(10, queue2.getDeliveringCount());
         acknowledgeAll(receiver2);
         receiver2.setMaxRefs(0);

         receiver3.setMaxRefs(15);
         queue3.deliver();
         readOK = receiver3.waitForHandleInvocations(15, 20000);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(15, queue3.getDeliveringCount());
         acknowledgeAll(receiver3);
         receiver3.setMaxRefs(0);

         receiver4.setMaxRefs(20);
         queue4.deliver();
         readOK = receiver4.waitForHandleInvocations(20, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(20, queue4.getDeliveringCount());
         acknowledgeAll(receiver4);
         receiver4.setMaxRefs(0);

         receiver5.setMaxRefs(25);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(25, 20000);
         assertTrue(readOK);
         Thread.sleep(1000);
         assertEquals(NUM_MESSAGES - 25, queue5.memoryRefCount());
         assertEquals(25, queue5.getDeliveringCount());
         acknowledgeAll(receiver5);
         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         log.trace("Here are the sizes 2:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         // Consume the rest from queue 5
         receiver5.setMaxRefs(NUM_MESSAGES - 25);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(NUM_MESSAGES - 25, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("receiver5 msgs:" + receiver5.getMessages().size());

         log.trace("Here are the sizes 3:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         // This will result in an extra one being pulled from queue1 - we cannot avoid this. This
         // is because the channel does not know that the receiver is full unless it tries with a
         // ref so it needs to retrieve one

                                                                   // http://jira.jboss.org/jira/browse/JBMESSAGING-901                                                                         
         assertEquals(NUM_MESSAGES - 6, queue1.memoryRefCount())// <-  expected:<94> but was:<93>
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(NUM_MESSAGES - 25, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // Now consume 5 more from queue5, they should come from queue1 which has the most messages

         log.trace("Consume 5 more from queue 5");

         receiver5.setMaxRefs(5);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(5, 20000);
         assertTrue(readOK);

         Thread.sleep(4000);

         log.trace("Here are the sizes 4:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount()); // <--  expected:<89> but was:<88>

         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 10, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(5, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver1.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // Consume 1 more - should pull one from queue2

         receiver5.setMaxRefs(1);
         queue5.deliver();
         readOK = receiver5.waitForHandleInvocations(1, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("Here are the sizes 5:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 11, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 15, queue3.memoryRefCount());
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(NUM_MESSAGES - 20, queue4.memoryRefCount());
         assertEquals(0, queue4.getDeliveringCount());

         assertEquals(1, queue5.memoryRefCount());
         assertEquals(1, queue5.getDeliveringCount());

         acknowledgeAll(receiver5);

         assertEquals(0, queue5.getDeliveringCount());

         receiver5.setMaxRefs(0);

         assertTrue(office1.getHoldingTransactions().isEmpty());
         assertTrue(office2.getHoldingTransactions().isEmpty());
         assertTrue(office3.getHoldingTransactions().isEmpty());
         assertTrue(office4.getHoldingTransactions().isEmpty());
         assertTrue(office5.getHoldingTransactions().isEmpty());

         // From queue 4 consume everything else

         int num = NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1;
         receiver4.setMaxRefs(num);
         queue4.deliver();
         readOK = receiver4.waitForHandleInvocations(num, 20000);
         assertTrue(readOK);

         Thread.sleep(2000);

         log.trace("Here are the sizes 6:");
         log.trace("queue1, refs:" + queue1.memoryRefCount() + " dels:" + queue1.getDeliveringCount());
         log.trace("queue2, refs:" + queue2.memoryRefCount() + " dels:" + queue2.getDeliveringCount());
         log.trace("queue3, refs:" + queue3.memoryRefCount() + " dels:" + queue3.getDeliveringCount());
         log.trace("queue4, refs:" + queue4.memoryRefCount() + " dels:" + queue4.getDeliveringCount());
         log.trace("queue5, refs:" + queue5.memoryRefCount() + " dels:" + queue5.getDeliveringCount());

         assertEquals(0, queue1.memoryRefCount());
         assertEquals(0, queue1.getDeliveringCount());

         assertEquals(0, queue2.memoryRefCount());
         assertEquals(0, queue2.getDeliveringCount());

         assertEquals(0, queue3.memoryRefCount()); // <- sometimes, there is still 1 message left in this queue
         assertEquals(0, queue3.getDeliveringCount());

         assertEquals(0, queue4.memoryRefCount());
         assertEquals(NUM_MESSAGES - 15 + NUM_MESSAGES - 20 + NUM_MESSAGES - 11 + NUM_MESSAGES - 11 + 1, queue4.getDeliveringCount());

         assertEquals(0, queue5.memoryRefCount());
         assertEquals(0, queue5.getDeliveringCount());

         acknowledgeAll(receiver4);

         assertEquals(0, queue4.getDeliveringCount());
View Full Code Here

TOP

Related Classes of org.jboss.messaging.core.plugin.postoffice.cluster.LocalClusteredQueue$MessagePullRequestRunnable

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.