Package org.jboss.messaging.core.contract

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


          
           List targets = new ArrayList();
          
           while (iter.hasNext())
           {
             Queue queue = (Queue)iter.next();
            
             if (trace) { log.trace(this + " considering queue " + queue); }
            
             if (queue.getNodeID() == thisNodeID)
             {
               if (trace) { log.trace(this + " is a local queue"); }
            
               //Local queue

               boolean routeLocal = false;
              
               if (!fromCluster)
               {
                 //Same node
                 routeLocal = true;
               }
               else
               {
                 //From the cluster
                 if (!queue.isRecoverable() && queue.isClustered())
                 {
                   //When routing from the cluster we only route to non recoverable queues
                   //who haven't already been routed to on the sending node (same name)
                   //Also we don't route to non clustered queues
                   if (names == null || !names.contains(queue.getName()))
                   {
                     routeLocal = true;
                   }
                 }
               }
              
               if (routeLocal)
               {
                 //If we're not routing from the cluster OR the queue is unreliable then we consider it
                
                 //When we route from the cluster we never route to reliable queues
                
                 Filter filter = queue.getFilter();
                
                 if (filter == null || filter.accept(ref.getMessage()))
                 {                   
                   if (trace) { log.trace(this + " Added queue " + queue + " to list of targets"); }
                  
                  targets.add(queue);
                 
                  if (ref.getMessage().isReliable() && queue.isRecoverable())
                   {
                     localReliableCount++;
                   }                
                 }  
               }
             }
             else if (!fromCluster)
             {
               //Remote queue
              
               if (trace) { log.trace(this + " is a remote queue"); }
              
               if (!queue.isRecoverable() && queue.isClustered())
               {                
                 //When we send to the cluster we never send to reliable queues
                
                 Filter filter = queue.getFilter();
                
                 if (filter == null || filter.accept(ref.getMessage()))
                 {
                   if (remoteSet == null)
                   {
                     remoteSet = new HashSet();
                   }
                  
                   remoteSet.add(new Integer(queue.getNodeID()));
                  
                   if (trace) { log.trace(this + " added it to the remote set for casting"); }
                 }
               }
               else
               {
                 if (trace) { log.trace(this + " is recoverable so not casting"); }
               }
             }
           }
                                
           //If the ref is reliable and there is more than one reliable local queue that accepts the message then we need
           //to route in a transaction to guarantee once and only once reliability guarantee
          
           boolean startedTx = false;
          
           if (tx == null && localReliableCount > 1)
           {
             if (trace) { log.trace("Starting internal tx, reliableCount = " + localReliableCount); }
            
             tx = tr.createTransaction();
            
             startedTx = true;
           }
          
           //Now actually route the ref
          
           iter = targets.iterator();
          
           Set queueNames = null;
          
           while (iter.hasNext())
           {
             Queue queue = (Queue)iter.next();
            
             if (trace) { log.trace(this + " Routing ref to queue " + queue); }
                       
             Delivery del = queue.handle(null, ref, tx);
            
             if (trace) { log.trace("Queue returned " + del); }

               if (del != null && del.isSelectorAccepted())
               {
                  routed = true;
                 
                  if (remoteSet != null)
                  {
                    if (queueNames == null)
                    {
                      queueNames = new HashSet();
                    }
                   
                    //We put the queue name in a set - this is used on other nodes after routing from the cluster so it
                    //doesn't route to queues with the same name on other nodes
                    queueNames.add(queue.getName());
                  }
               }
           }
                      
            if (remoteSet != null)
View Full Code Here


      return binding;
   }
  
   private boolean addBindingInMemory(Binding binding) throws Exception
   {
     Queue queue = binding.queue;
         
     if (trace) { log.trace(this + " Adding binding in memory " + binding); }
    
      boolean intr = Thread.interrupted();
      for (;;)
      {
         try
         {
            lock.writeLock().acquire();
            break;
         }
         catch (InterruptedException ex)
         {
            intr = true;
         }
      }
    
     try
     {   
       Integer nid = new Integer(queue.getNodeID());
      
       Map nameMap = (Map)nameMaps.get(nid);
             
       if (nameMap != null && nameMap.containsKey(queue.getName()))
       {
         return false;
       }
      
       Long cid = new Long(queue.getChannelID());
      
       if (channelIDMap.containsKey(cid))
       {
         throw new IllegalStateException("Channel id map for node " + nid + " already contains binding for queue " + cid);
       }
      
       if (nameMap == null)
       {
         nameMap = new HashMap();
        
         nameMaps.put(nid, nameMap);
        
         if (queue.getNodeID() == thisNodeID)
         {
           localNameMap = nameMap;
         }
       }
      
       nameMap.put(queue.getName(), binding);
      
       channelIDMap.put(cid, binding);
             
       Condition condition = binding.condition;    
      
       List queues = (List)mappings.get(condition);
      
       if (queues == null)
       {
         queues = new ArrayList();
        
         if (queues.contains(queue))
         {
           throw new IllegalArgumentException("Queue is already bound with condition " + condition);
         }
        
         mappings.put(condition, queues);
       }
      
       queues.add(queue)
     }
     finally
     {
       lock.writeLock().release();
       if (intr) Thread.currentThread().interrupt();
     }
    
     if (trace) { log.trace(this + " Sending cluster notification"); }
    
      //Send a notification
      ClusterNotification notification = new ClusterNotification(ClusterNotification.TYPE_BIND, queue.getNodeID(), queue.getName());
     
      clusterNotifier.sendNotification(notification);
     
      return true;
   }
View Full Code Here

      }
   }

   public synchronized Queue getDefaultDLQInstance() throws Exception
   {
      Queue dlq = null;
     
      if (defaultDLQObjectName != null)
      {
         ManagedQueue dest = null;

         // This can be null... JMXAccessor will return null if InstanceNotFoundException is caught
         dest = (ManagedQueue) JMXAccessor.getJMXAttributeOverSecurity(getServer(), defaultDLQObjectName, "Instance");

         if (dest != null && dest.getName() != null)
         {           
            Binding binding = postOffice.getBindingForQueueName(dest.getName());
           
            if (binding == null)
            {
              throw new IllegalStateException("Cannot find binding for queue " + dest.getName());
            }
           
            Queue queue = binding.queue;
           
            if (queue.isActive())
            {
              dlq = queue;
            }
         }
      }
View Full Code Here

      return dlq;
   }
  
   public synchronized Queue getDefaultExpiryQueueInstance() throws Exception
   {
      Queue expiryQueue = null;
     
      if (defaultExpiryQueueObjectName != null)
      {
         ManagedQueue dest = null;
        
         try
         {

            dest = (ManagedQueue)JMXAccessor.getJMXAttributeOverSecurity(getServer(), defaultExpiryQueueObjectName, "Instance");
         }
         catch (InstanceNotFoundException e)
         {
            //Ok
         }

         if (dest != null && dest.getName() != null)
         {           
           Binding binding = postOffice.getBindingForQueueName(dest.getName());
           
            if (binding == null)
            {
              throw new IllegalStateException("Cannot find binding for queue " + dest.getName());
            }
           
            Queue queue = binding.queue;           
          
            if (queue.isActive())
            {
              expiryQueue = queue;
            }
         }
      }
View Full Code Here

     
      Iterator iter = queues.iterator();
     
      while (iter.hasNext())           
      {
         Queue queue = (Queue)iter.next();
        
         queue.removeAllReferences();
      }
                      
      //undeploy the mbean
      if (!undeployDestination(isQueue, name))
      {
         return false;
      }
           
      //Unbind the destination's queues
     
      while (iter.hasNext())           
      {
         Queue queue = (Queue)iter.next();
        
         queue.removeAllReferences();
        
         //Durable subs need to be removed on all nodes
         boolean all = !isQueue && queue.isRecoverable();
        
         postOffice.removeBinding(queue.getName(), all);
      }
     
      return true;
   }
View Full Code Here

         Iterator iter = queues.iterator();

         while (iter.hasNext())
         {
           Queue queue = (Queue)iter.next();

           if (!localOnly || (queue.getNodeID() == thisNodeID))
           {
             list.add(queue);
           }
         }
View Full Code Here

         if (mapping.getFilterString() != null)
         {
           filter = filterFactory.createFilter(mapping.getFilterString());
         }
        
         Queue queue = new MessagingQueue(mapping.getNodeId(), mapping.getQueueName(), mapping.getChannelId(),
                                          mapping.isRecoverable(), filter, true);
        
         Condition condition = conditionFactory.createCondition(mapping.getConditionText());
        
         addBindingInMemory(new Binding(condition, queue, false));
        
         if (mapping.isAllNodes())
         {
           // insert into db if not already there
           if (!loadedBindings.containsKey(queue.getName()))
           {
             //Create a local binding too
            
            long channelID = channelIDManager.getID();
                       
            Queue queue2 = new MessagingQueue(thisNodeID, mapping.getQueueName(), channelID, ms, pm,
                                             mapping.isRecoverable(), mapping.getMaxSize(), filter,
                                             mapping.getFullSize(), mapping.getPageSize(), mapping.getDownCacheSize(),
                                             true, mapping.getRecoverDeliveriesTimeout());    
           
            Binding localBinding = new Binding(condition, queue2, true);
View Full Code Here

         
          while (iter2.hasNext())
          {
            Binding binding = (Binding)iter2.next();
         
            Queue queue = binding.queue;
           
            //We only get the clustered queues
            if (queue.isClustered())
            {             
              String filterString = queue.getFilter() == null ? null : queue.getFilter().getFilterString();
             
              MappingInfo mapping;
             
              if (binding.allNodes)
              {
                mapping = new MappingInfo(queue.getNodeID(), queue.getName(), binding.condition.toText(), filterString,
                                           queue.getChannelID(), queue.isRecoverable(), true, true,
                                    queue.getFullSize(), queue.getPageSize(), queue.getDownCacheSize(),
                                    queue.getMaxSize(), queue.getRecoverDeliveriesTimeout());
              }
              else
              {
                mapping = new MappingInfo(queue.getNodeID(), queue.getName(), binding.condition.toText(),
                                        filterString, queue.getChannelID(), queue.isRecoverable(),
                                        true, false);    
              }
              list.add(mapping);
            }
          }
View Full Code Here

      if (mapping.getFilterString() != null)
      {
        filter = filterFactory.createFilter(mapping.getFilterString());
      }
     
      Queue queue = new MessagingQueue(mapping.getNodeId(), mapping.getQueueName(), mapping.getChannelId(),
                                       mapping.isRecoverable(), filter, mapping.isClustered());
     
      Condition condition = conditionFactory.createCondition(mapping.getConditionText());
     
      //addBindingInMemory(new Binding(condition, queue, mapping.isAllNodes()));
      addBindingInMemory(new Binding(condition, queue, false));
     
      if (allNodes)
     {
       if (trace) { log.trace("allNodes is true, so also forcing a local bind"); }
      
       //There is the possibility that two nodes send a bind all with the same name simultaneously OR
       //a node starts and sends a bind "ALL" and the other nodes already have a queue with that name
       //This is ok - but we must check for this and not create the local binding in this case
                            
       //Bind locally

       long channelID = channelIDManager.getID();
      
       Queue queue2 = new MessagingQueue(thisNodeID, mapping.getQueueName(), channelID, ms, pm,
                                        mapping.isRecoverable(), mapping.getMaxSize(), filter,
                                        mapping.getFullSize(), mapping.getPageSize(), mapping.getDownCacheSize(), true,
                                        mapping.getRecoverDeliveriesTimeout());

       //We must cast back asynchronously to avoid deadlock
       boolean added = internalAddBinding(new Binding(condition, queue2, true), false, false);
      
       if (added)
       {        
         if (trace) { log.trace(this + " inserted in binding locally"); }     
        
         queue2.load();
          
          queue2.activate();        
       }
     }
     
      synchronized (waitForBindUnbindLock)
      {
View Full Code Here

       //will request for deliveries to be sent to it in a batch
       //We still send back a response though to prevent the sender blocking waiting for a reply
     }
     else
     {    
       Queue queue = binding.queue;
      
       queue.addToRecoveryArea(nodeID, messageID, sessionID);    
     }
    
     if (trace) { log.trace(this + " reply address is " + replyAddress); }
    
     if (replyAddress != null)
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.