Version 2

    Client Reconnection Interceptor


    See this JIRA Issue


    * 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
    * 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:
    import java.util.Iterator;
    import javax.jms.InvalidClientIDException;
    import javax.jms.JMSException;
    import org.jboss.logging.Logger;
     * The JMS spec does not let a second client with the same clientID connect to
     * the server.  The second client gets an InvalidClientIDException exception.
     * This interceptor modifies the server so that the first client gets
     * disconnected and then the second client can connect successfully.
     * Currently it only works if the client id is set by the client using the
     * setClient method call.
     * @author <a href="">Hiram Chirino</a>
    public class ClientReconnectInterceptor extends JMSServerInterceptorSupport {
         static protected Logger log =
         private JMSDestinationManager destinationManager;
         private JMSDestinationManager getDestinationManager() {
                   return destinationManager;
              JMSServerInterceptor interceptor = getNext(); 
              while( ! (interceptor instanceof JMSDestinationManager) ) 
                   interceptor = getNext();
              destinationManager = (JMSDestinationManager)interceptor;
              return destinationManager;
         private ConnectionToken findConnectionTokenFor(String clientID) {
              Iterator iterator = getDestinationManager().clientConsumers.keySet().iterator();
              while (iterator.hasNext()) {
                   ConnectionToken dc = (ConnectionToken);
                   if( dc.getClientID().equals(clientID))
                        return dc;
              return null;
          * @see
         public void checkID(String ID) throws JMSException {
              try {
              } catch (InvalidClientIDException e) {
                   ConnectionToken dc = findConnectionTokenFor(ID);
                   // The InvalidClientIDException could have been thrown
                   // due to another reason besides a double client connect.
                   if( dc == null ) 
                        throw e;
                   // try to disconnect the previous client
                   try {
                   } catch (Throwable e2) {
                        // Log it in case we ever care to find out the details.
                        log.trace("Disconnect of previously connected client caused an error:",e);
                   // try it again...