Package org.jboss.messaging.core.contract

Examples of org.jboss.messaging.core.contract.Queue


         
          Iterator iter2 = queues.iterator();
         
          while (iter2.hasNext())
          {
            Queue queue = (Queue)iter2.next();
           
            if (queue.getNodeID() == nodeToRemove.intValue())
            {
              toRemove.add(new Binding(condition, queue, false));
            }
          }
        }
View Full Code Here


         
          while (iter.hasNext())
          {
            Binding binding = (Binding)iter.next();
           
            Queue queue = binding.queue;
           
            if (queue.isRecoverable() && queue.getNodeID() == failedNodeID.intValue())
            {
              toRemove.add(binding);
            }           
          }
        }
                  
        Iterator iter = toRemove.iterator();

        while (iter.hasNext())
        {
          Binding binding = (Binding)iter.next();
         
          Condition condition = binding.condition;
         
          Queue queue = binding.queue;
         
          // Sanity check
            if (!queue.isRecoverable())
            {
               throw new IllegalStateException("Found non recoverable queue " +
                                               queue.getName() + " in map, these should have been removed!");
            }

            // Sanity check
            if (!queue.isClustered())
            {
               throw new IllegalStateException("Queue " + queue.getName() + " is not clustered!");
            }
           
            //Remove from the in-memory map - no need to broadcast anything - they will get removed from other nodes in memory
            //maps when the other nodes detect failure
            removeBindingInMemory(binding.queue.getNodeID(), binding.queue.getName());
         
            //Find if there is a local queue with the same name
           
            Queue localQueue = null;
           
            if (localNameMap != null)
            {
              Binding b = (Binding)localNameMap.get(queue.getName());
              if (b != null)
              {
                localQueue = b.queue;
              }
            }
             
            if (localQueue != null)
            {
               //need to merge the queues
             
              log.debug(this + " has already a queue: " + queue.getName() + " queue so merging queues");
               
               localQueue.mergeIn(queue.getChannelID(), failedNodeID.intValue());
              
               log.debug("Merged queue");      
              
               //Delete from storage
              
View Full Code Here

                  if (selector != null)
                  {
                     filter = filterFactory.createFilter(selector);
                  }

                  Queue queue = new MessagingQueue(thisNodeID, queueName, channelID, ms, pm,
                                                   true, filter, bindingClustered && clustered);

                  if (trace) { log.trace(this + " loaded binding from storage: " + queueName); }

                  Condition condition = conditionFactory.createCondition(conditionText);
View Full Code Here

            //Look up the queue

            Binding binding = postOffice.getBindingForQueueName(queueName);

            Queue queue = binding.queue;

            if (queue == null)
            {
               throw new IllegalStateException("Cannot find queue with queue name: " + queueName);
            }

            List acks = (List)entry.getValue();

            List ids = new ArrayList(acks.size());

            for (Iterator iter2 = acks.iterator(); iter2.hasNext(); )
            {
               DeliveryRecovery info = (DeliveryRecovery)iter2.next();

               ids.add(new Long(info.getMessageID()));
            }

            JMSCondition cond = (JMSCondition)binding.condition;

            ManagedDestination dest =
               sp.getDestinationManager().getDestination(cond.getName(), cond.isQueue());

            if (dest == null)
            {
               throw new IllegalStateException("Cannot find managed destination with name " +
                  cond.getName() + " isQueue" + cond.isQueue());
            }

            Queue dlqToUse =
               dest.getDLQ() == null ? defaultDLQ : dest.getDLQ();

            Queue expiryQueueToUse =
               dest.getExpiryQueue() == null ? defaultExpiryQueue : dest.getExpiryQueue();

            int maxDeliveryAttemptsToUse =
               dest.getMaxDeliveryAttempts() == -1 ? defaultMaxDeliveryAttempts : dest.getMaxDeliveryAttempts();
View Full Code Here

         dm.registerDestination(mDest);

         if (dest.isQueue())
         {
            Queue coreQueue = new MessagingQueue(nodeId, dest.getName(),
                                     idm.getID(), ms, pm, false, -1, null,
                                       fullSize, pageSize, downCacheSize, postOffice.isClustered(),
                                       sp.getRecoverDeliveriesTimeout());


            Condition cond = new JMSCondition(true, dest.getName());

           // make a binding for this temporary queue

            // temporary queues need to bound on ALL nodes of the cluster
            postOffice.addBinding(new Binding(cond, coreQueue, true), postOffice.isClustered());

            coreQueue.activate();
         }
      }
      catch (Throwable t)
      {
         throw ExceptionUtil.handleJMSInvocation(t, this + " addTemporaryDestination");
View Full Code Here

         {
            throw new InvalidDestinationException("Cannot find durable subscription with name " +
                                                  subscriptionName + " to unsubscribe");
         }

         Queue sub = binding.queue;

         // Section 6.11. JMS 1.1.
         // "It is erroneous for a client to delete a durable subscription while it has an active
         // TopicSubscriber for it or while a message received by it is part of a current
         // transaction or has not been acknowledged in the session."

         if (sub.getLocalDistributor().getNumberOfReceivers() != 0)
         {
            throw new IllegalStateException("Cannot unsubscribe durable subscription " +
                                            subscriptionName + " since it has active subscribers");
         }

         //Also if it is clustered we must disallow unsubscribing if it has active consumers on other nodes

         if (sub.isClustered() && postOffice.isClustered())
         {
           Replicator rep = (Replicator)postOffice;

           Map map = rep.get(sub.getName());

           if (!map.isEmpty())
           {
             throw new IllegalStateException("Cannot unsubscribe durable subscription " +
                     subscriptionName + " since it has active subscribers on other nodes");
           }
         }

         postOffice.removeBinding(sub.getName(), sub.isClustered() && postOffice.isClustered());

         String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + sub.getName();

         MessageCounter counter = sp.getMessageCounterManager().unregisterMessageCounter(counterName);

         if (counter == null)
         {
View Full Code Here

         Collection queues = po.getQueuesForCondition(new JMSCondition(false, destination.getName()), true);
       
         Iterator iter = queues.iterator();
         while (iter.hasNext())
         {
            Queue queue = (Queue)iter.next();
           
            boolean actuallyClustered = po.isClustered() && destination.isClustered();
           
            if (actuallyClustered != queue.isClustered())
           {
             throw new IllegalArgumentException("Topic " + destination.getName() + " is already deployed as clustered = " +
                                              queue.isClustered() + " so cannot redeploy as clustered=" + destination.isClustered() +
                                              " . You must delete the destination first before redeploying");
            
           }
                    
            //TODO We need to set the paging params this way since the post office doesn't store them
            //instead we should never create queues inside the postoffice - only do it at deploy time
            queue.setPagingParams(destination.getFullSize(), destination.getPageSize(), destination.getDownCacheSize());
           
            queue.load();
                       
            queue.activate()
              
            //Must be done after load
            queue.setMaxSize(destination.getMaxSize())
           
            //Create a counter
            String counterName = SUBSCRIPTION_MESSAGECOUNTER_PREFIX + queue.getName();
           
            String subName = MessageQueueNameHelper.createHelper(queue.getName()).getSubName();
           
            int dayLimitToUse = destination.getMessageCounterHistoryDayLimit();
            if (dayLimitToUse == -1)
            {
               //Use override on server peer
               dayLimitToUse = serverPeer.getDefaultMessageCounterHistoryDayLimit();
            }
           
            MessageCounter counter =
               new MessageCounter(counterName, subName, queue, true, true,
                                  dayLimitToUse);
           
            serverPeer.getMessageCounterManager().registerMessageCounter(counterName, counter);   
           
            //Now we need to trigger a delivery - this is because message suckers might have
            //been create *before* the queue was deployed - this is because message suckers can be
            //created when the clusterpullconnectionfactory deploy is detected which then causes
            //the clusterconnectionmanager to inspect the bindings for queues to create suckers
            //to - but these bindings will exist before the queue or topic is deployed and before
            //it has had its messages loaded
            //Therefore we need to trigger a delivery now so remote suckers get messages
            //See http://jira.jboss.org/jira/browse/JBMESSAGING-1136
            //For JBM we should remove the distinction between activation and deployment to
            //remove these annoyances and edge cases.
            //The post office should load(=deploy) all bindings on startup including loading their
            //state before adding the binding - there should be no separate deployment stage
            //If the queue can be undeployed there should be a separate flag for this on the
            //binding
            queue.deliver();
         }

         serverPeer.getDestinationManager().registerDestination(destination);
        
         log.debug(this + " security configuration: " + (destination.getSecurityConfig() == null ?
View Full Code Here

       
         Iterator iter = queues.iterator();
        
         while (iter.hasNext())           
         {
            Queue queue = (Queue)iter.next();
           
            if (!queue.isRecoverable())
            {
               // Unbind
               po.removeBinding(queue.getName(), false);
            }
                       
            queue.deactivate();
           
            queue.unload();
           
            //unregister counter
            String counterName = SUBSCRIPTION_MESSAGECOUNTER_PREFIX + queue.getName();
           
            serverPeer.getMessageCounterManager().unregisterMessageCounter(counterName);                       
         }
         
         started = false;
View Full Code Here

      if (selectorString != null)
      {
         selector = new Selector(selectorString);
      }

      Queue queue;

      if (jmsDestination.isTopic())
      {
         if (subscriptionName == null)
         {
            // non-durable subscription
            if (log.isTraceEnabled()) { log.trace(this + " creating new non-durable subscription on " + jmsDestination); }

            // Create the non durable sub

            queue = new MessagingQueue(nodeId, GUIDGenerator.generateGUID(),
                                idm.getID(), ms, pm, false,
                                mDest.getMaxSize(), selector,
                                mDest.getFullSize(),
                                mDest.getPageSize(),
                                mDest.getDownCacheSize(),
                                mDest.isClustered(),
                                sp.getRecoverDeliveriesTimeout());

            JMSCondition topicCond = new JMSCondition(false, jmsDestination.getName());

            postOffice.addBinding(new Binding(topicCond, queue, false), false);

            queue.activate();

            String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + queue.getName();

            int dayLimitToUse = mDest.getMessageCounterHistoryDayLimit();
            if (dayLimitToUse == -1)
            {
               //Use override on server peer
               dayLimitToUse = sp.getDefaultMessageCounterHistoryDayLimit();
            }

            //We don't create message counters on temp topics
            if (!mDest.isTemporary())
            {
              MessageCounter counter =  new MessageCounter(counterName, null, queue, 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 binding = postOffice.getBindingForQueueName(name);

            if (binding == null)
            {
               // Does not already exist

               if (trace) { log.trace(this + " creating new durable subscription on " + jmsDestination); }

               queue = new MessagingQueue(nodeId, name, idm.getID(),
                                          ms, pm, true,
                                          mDest.getMaxSize(), selector,
                                          mDest.getFullSize(),
                                          mDest.getPageSize(),
                                          mDest.getDownCacheSize(),
                                          mDest.isClustered(),
                                          sp.getRecoverDeliveriesTimeout());

               // Durable subs must be bound on ALL nodes of the cluster (if clustered)

               postOffice.addBinding(new Binding(new JMSCondition(false, jmsDestination.getName()), queue, true),
                                     postOffice.isClustered() && mDest.isClustered());

               queue.activate();

               //We don't create message counters on temp topics
               if (!mDest.isTemporary())
               {
                 String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + queue.getName();

                 MessageCounter counter =
                    new MessageCounter(counterName, subscriptionName, queue, true, true,
                                       mDest.getMessageCounterHistoryDayLimit());

                 sp.getMessageCounterManager().registerMessageCounter(counterName, counter);
               }
            }
            else
            {
               //Durable sub already exists

              queue = binding.queue;

               if (trace) { log.trace(this + " subscription " + subscriptionName + " already exists"); }

              //Check if it is already has a subscriber
              //We can't have more than one subscriber at a time on the durable sub unless it is clustered
               //we need this for clustered since otherwise we wouldn't be able to fail over subcribers for the same durable
               //sub onto a node which already has one

               if (queue.getLocalDistributor().getNumberOfReceivers() > 0 && !mDest.isClustered())
               {
                 throw new IllegalStateException("Cannot create a subscriber on the durable subscription since it already has subscriber(s)");
               }

               // If the durable sub exists because it is clustered and was created on this node due to a bind on another node
               // then it will have no message counter

               String counterName = TopicService.SUBSCRIPTION_MESSAGECOUNTER_PREFIX + queue.getName();

               boolean createCounter = false;

               if (sp.getMessageCounterManager().getMessageCounter(counterName) == null)
               {
                 createCounter = true;
               }

               // 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 = queue.getFilter() != null ? queue.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"); }

               String oldTopicName = ((JMSCondition)binding.condition).getName();

               boolean topicChanged = !oldTopicName.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

                  // Durable subs must be unbound on ALL nodes of the cluster

                  postOffice.removeBinding(queue.getName(), postOffice.isClustered() && mDest.isClustered());

                  // create a fresh new subscription

                  queue = new MessagingQueue(nodeId, name, idm.getID(), ms, pm, true,
                                        mDest.getMaxSize(), selector,
                                        mDest.getFullSize(),
                                        mDest.getPageSize(),
                                        mDest.getDownCacheSize(),
                                        mDest.isClustered(),
                                        sp.getRecoverDeliveriesTimeout());

                  // Durable subs must be bound on ALL nodes of the cluster

                  postOffice.addBinding(new Binding(new JMSCondition(false, jmsDestination.getName()), queue, true),
                                      postOffice.isClustered() && mDest.isClustered());

                  queue.activate();

                  if (!mDest.isTemporary())
                  {
                    createCounter = true;
                  }
               }

               if (createCounter)
               {
                 MessageCounter counter =
                     new MessageCounter(counterName, subscriptionName, queue, true, true,
                                        mDest.getMessageCounterHistoryDayLimit());

                  sp.getMessageCounterManager().registerMessageCounter(counterName, counter);
               }
            }
         }
      }
      else
      {
         // Consumer on a jms queue

         // Let's find the queue

        queue = postOffice.getBindingForQueueName(jmsDestination.getName()).queue;

         if (queue == null)
         {
            throw new IllegalStateException("Cannot find queue: " + jmsDestination.getName());
         }
      }

      int prefetchSize = connectionEndpoint.getPrefetchSize();

      Queue dlqToUse = mDest.getDLQ() == null ? defaultDLQ : mDest.getDLQ();

      Queue expiryQueueToUse = mDest.getExpiryQueue() == null ? defaultExpiryQueue : mDest.getExpiryQueue();

      int maxDeliveryAttemptsToUse = mDest.getMaxDeliveryAttempts() == -1 ? defaultMaxDeliveryAttempts : mDest.getMaxDeliveryAttempts();

      long redeliveryDelayToUse = mDest.getRedeliveryDelay() == -1 ? defaultRedeliveryDelay : mDest.getRedeliveryDelay();
View Full Code Here

          
         PostOffice po = serverPeer.getPostOfficeInstance();
                          
         Binding binding = po.getBindingForQueueName(destination.getName());
        
         Queue queue;
        
         if (binding != null)
         {                    
           queue = binding.queue;
          
           if (queue.isActive())
           {
             throw new IllegalStateException("Cannot deploy queue " + destination.getName() + " it is already deployed");
           }
          
           //Sanity check - currently it is not possible to change the clustered attribute of a destination
           //See http://jira.jboss.org/jira/browse/JBMESSAGING-1235
          
           boolean actuallyClustered = po.isClustered() && destination.isClustered();
          
           if (actuallyClustered != queue.isClustered())
           {
             throw new IllegalArgumentException("Queue " + destination.getName() + " is already deployed as clustered = " +
                                              queue.isClustered() + " so cannot redeploy as clustered=" + destination.isClustered() +
                                              " . You must delete the destination first before redeploying");
            
           }
          
            queue.setPagingParams(destination.getFullSize(),
                                  destination.getPageSize(),
                                  destination.getDownCacheSize())
           
            queue.load();
              
            // Must be done after load
            queue.setMaxSize(destination.getMaxSize());
           
            queue.activate();          
         }
         else
         {          
            // Create a new queue

            JMSCondition queueCond = new JMSCondition(true, destination.getName());
           
            queue = new MessagingQueue(nodeId, destination.getName(),
                                     serverPeer.getChannelIDManager().getID(),
                                       serverPeer.getMessageStore(), serverPeer.getPersistenceManagerInstance(),
                                       true,
                                       destination.getMaxSize(), null,
                                       destination.getFullSize(), destination.getPageSize(),
                                       destination.getDownCacheSize(), destination.isClustered(),
                                       serverPeer.getRecoverDeliveriesTimeout());
            po.addBinding(new Binding(queueCond, queue, false), false);        
           
            queue.activate();
         }
        
         ((ManagedQueue)destination).setQueue(queue);
        
         String counterName = QUEUE_MESSAGECOUNTER_PREFIX + destination.getName();
        
         int dayLimitToUse = destination.getMessageCounterHistoryDayLimit();
         if (dayLimitToUse == -1)
         {
            //Use override on server peer
            dayLimitToUse = serverPeer.getDefaultMessageCounterHistoryDayLimit();
         }
        
         MessageCounter counter =
            new MessageCounter(counterName, null, queue, false, false,
                               dayLimitToUse);
        
         ((ManagedQueue)destination).setMessageCounter(counter);
                 
         serverPeer.getMessageCounterManager().registerMessageCounter(counterName, counter);
                      
         serverPeer.getDestinationManager().registerDestination(destination);
       
         log.debug(this + " security configuration: " + (destination.getSecurityConfig() == null ?
            "null" : "\n" + XMLUtil.elementToString(destination.getSecurityConfig())));
        
         started = true;        
        
         //Now we need to trigger a delivery - this is because message suckers might have
         //been create *before* the queue was deployed - this is because message suckers can be
         //created when the clusterpullconnectionfactory deploy is detected which then causes
         //the clusterconnectionmanager to inspect the bindings for queues to create suckers
         //to - but these bindings will exist before the queue or topic is deployed and before
         //it has had its messages loaded
         //Therefore we need to trigger a delivery now so remote suckers get messages
         //See http://jira.jboss.org/jira/browse/JBMESSAGING-1136
         //For JBM we should remove the distinction between activation and deployment to
         //remove these annoyances and edge cases.
         //The post office should load(=deploy) all bindings on startup including loading their
         //state before adding the binding - there should be no separate deployment stage
         //If the queue can be undeployed there should be a separate flag for this on the
         //binding
         queue.deliver();
        
         log.info(this + " started, fullSize=" + destination.getFullSize() +
                  ", pageSize=" + destination.getPageSize() + ", downCacheSize=" + destination.getDownCacheSize());
      }
      catch (Throwable t)
View Full Code Here

TOP

Related Classes of org.jboss.messaging.core.contract.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.