Version 13

    Receivers Implementation

     

    The receivers implementation used by Queues to record who is waiting for a message

    (and in which order they should be processed) is pluggable. You just need to implement

    the

    org.jboss.mq.server.Receivers

    interface:

     

    Implementations

     

    • org.jboss.mq.server.ReceiversImpl

      - the default implementation using a

      HashSet

       

    • org.jboss.mq.server.ReceiversImplArrayList

      - implemented with an

      ArrayList

       

    • org.jboss.mq.server.ReceiversImplLinkedList

      - implemented with n

      LinkedList

       

     

    Config

     

    • You specify it as an attribute on the DestinationManager, Queue or Topic (

      e.g.: <attribute name= "ReceiversImpl">org.jboss.mq.server.ReceiversImplArrayList</attribute>

      ).

    • If the destination has no configuration it uses the Destination Manager config.

    • If the destination manager has no configuration it uses the default.

     

    Notes

     

    • The default implementation is there for backwards compatibility.

    • It has been reported that the

      List

      implementations provide better load balancing when there are competing receivers. Neither

      List

      implementation has been as thoroughly tested as the

      HashSet

      version.

    • The default implementation will only use other nodes if its own load is too high. Either of the List-based implementations can be used to get "round-robin" (perhaps "fair queueing" is a better term) distribution.

    • The Topic configuration is largely irrelevent since only one receiver can be listening on a subscription, but it is anticipated that something more performant than a

      HashSet

      of 1 could be implemented.

    • The receivers implementation should have "Set" semantics, i.e. if the subscription is already present it shouldn't add it twice.

     

    Usage

     

    <mbean code="org.jboss.mq.server.jmx.DestinationManager" name="jboss.mq:service=DestinationManager">
        <depends optional-attribute-name="MessageCache">jboss.mq:service=MessageCache</depends>
        <depends optional-attribute-name="PersistenceManager">jboss.mq:service=PersistenceManager</depends>
        <depends optional-attribute-name="StateManager">jboss.mq:service=StateManager</depends>
        <attribute name="ReceiversImpl">
          org.jboss.mq.server.ReceiversImplArrayList
        </attribute>
      </mbean>
    

     

    The Receivers interface

    /*
    * JBoss, Home of Professional Open Source
    * Copyright 2005, JBoss Inc., and individual contributors as indicated
    * by the @authors tag. See the copyright.txt in the distribution for a
    * full listing of individual contributors.
    *
    * This is free software; you can redistribute it and/or modify it
    * under the terms of the GNU Lesser General Public License as
    * published by the Free Software Foundation; either version 2.1 of
    * the License, or (at your option) any later version.
    *
    * This software is distributed in the hope that it will be useful,
    * but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
    * Lesser General Public License for more details.
    *
    * You should have received a copy of the GNU Lesser General Public
    * License along with this software; if not, write to the Free
    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
    */
    package org.jboss.mq.server;
    
    import java.util.ArrayList;
    import java.util.Iterator;
    
    import org.jboss.mq.Subscription;
    
    /**
     * Interface to be implemented by a receivers implementation.
     * The implementation should also have a default constructor.<p>
     * 
     * NOTE: There is no need to internally synchronize the caller
     * handles that.<p>
     * 
     * NOTE: This datastructure should have Set semantics. 
     *       i.e. attempts to add a subscriber that is already
     *       present should be ignored. Or more explicitly
     *       a subscriber should present zero or once. 
     *
     * @author <a href="mailto:adrian@jboss.com">Adrian Brock</a>
     * @version $Revision: 1.4 $
     */
    public interface Receivers
    {
    
       /**
        * @return Get the number of receivers
        */
       int size();
       
       /**
        * @return the subscriptions as an array list, this must be a
        * clone of any internal datastructure
        */
       ArrayList listReceivers();
       
       
       /**
        * Add a receiver, ignored if the receiver is already present.
        * 
        * @param sub the receiver to add
        */
       void add(Subscription sub);
       
       /**
        * Remove a receiver
        * 
        * @param sub the receiver to remove
        */
       void remove(Subscription sub);
       
       /**
        * Get an iterator to loop over all receivers
        * 
        * @return the iterator
        */
       Iterator iterator();
    }
    

     

    For a useful discussion of this subject

    See the JBoss Forums (JBoss.com -> JBoss User -> Messaging, JMS & JBossMQ) topic JMS Queue residing in a cluster