package org.jboss.mq.server;
import java.util.Iterator;
import javax.jms.InvalidClientIDException;
import javax.jms.JMSException;
import org.jboss.logging.Logger;
import org.jboss.mq.ConnectionToken;
public class ClientReconnectInterceptor extends JMSServerInterceptorSupport {
static protected Logger log =
Logger.getLogger(ClientReconnectInterceptor.class);
private JMSDestinationManager destinationManager;
private JMSDestinationManager getDestinationManager() {
if(destinationManager!=null)
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) iterator.next();
if( dc.getClientID().equals(clientID))
return dc;
}
return null;
}
public void checkID(String ID) throws JMSException {
try {
super.checkID(ID);
} catch (InvalidClientIDException e) {
ConnectionToken dc = findConnectionTokenFor(ID);
if( dc == null )
throw e;
try {
super.connectionClosing(dc);
} catch (Throwable e2) {
log.trace("Disconnect of previously connected client caused an error:",e);
}
super.checkID(ID);
}
}
}