@Override
public void addConnection(ConnectionContext context, ConnectionInfo info) throws Exception {
String clientId = info.getClientId();
if (clientId == null) {
throw new InvalidClientIDException("No clientID specified for connection request");
}
synchronized (clientIdSet) {
ConnectionContext oldContext = clientIdSet.get(clientId);
if (oldContext != null) {
if (context.isAllowLinkStealing()){
clientIdSet.remove(clientId);
if (oldContext.getConnection() != null) {
LOG.warn("Stealing link for clientId {} From Connection {}", clientId, oldContext.getConnection());
oldContext.getConnection().stop();
}else{
LOG.error("Not Connection for {}", oldContext);
}
}else{
throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected from "
+ oldContext.getConnection().getRemoteAddress());
}
} else {
clientIdSet.put(clientId, context);
}