if (brokerList == null) {
throw new RuntimeException("No broker to remove for [" + notificationType + "]");
}
NeighborBrokerConsumers nbcs = rb.getNeighborBrokerConsumers();
EndpointReference rbEpr = rb.getBrokerConsumerReference().getReference();
if (nbcs != null && nbcs.getReferenceSequence() != null) {
List<Broker> neighborBrokers = new ArrayList<Broker>();
for (EndpointReference neighborBrokerConsumerEpr : nbcs.getReferenceSequence()) {
BrokerStruct neighborBrokerStruct = null;
URL neighborBrokerConsumerEprUrl = neighborBrokerConsumerEpr.getEndpointAddress().getAddress();
for (BrokerStruct brokerStruct : brokerList) {
if (brokerStruct.consumerUrl.equals(neighborBrokerConsumerEprUrl)) {
neighborBrokerStruct = brokerStruct;
break;
}
}
if (neighborBrokerStruct == null) {
throw new RuntimeException("Can't find neighbor broker for consumer EPR [" +
neighborBrokerConsumerEprUrl + "]");
}
BrokerConsumerReference bcr = new BrokerConsumerReference();
bcr.setReference(EncodingUtils.createEndpointReference(neighborBrokerStruct.consumerUrl, neighborBrokerStruct.brokerID));
BrokerProducerReference bpr = new BrokerProducerReference();
bpr.setReference(EncodingUtils.createEndpointReference(neighborBrokerStruct.producerUrl, neighborBrokerStruct.brokerID));
Broker neighborBroker = new Broker();
neighborBroker.setBrokerConsumerReference(bcr);
neighborBroker.setBrokerProducerReference(bpr);
neighborBrokers.add(neighborBroker);
}
int lastIndex = neighborBrokers.size() - 1;
for (int index = lastIndex; index >= 0; index--) {
List<Broker> writeableNeighborBrokers = ((index > 0) ? neighborBrokers.subList(0, index) : null);
WriteableReplaceBrokerConnection wrbc = new WriteableReplaceBrokerConnection(rbEpr, writeableNeighborBrokers);
URL targetUrl =
neighborBrokers.get(index).getBrokerProducerReference().getReference().getEndpointAddress().getAddress();
try {
IOUtils.sendHttpRequest(targetUrl, Constants.REPLACE_BROKER_CONNECTION_OP, wrbc, null);
} catch(Exception e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
}
BrokerStruct removedBrokerStruct = null;
URL rbEprUrl = rbEpr.getEndpointAddress().getAddress();
for (BrokerStruct brokerSruct : brokerList) {
if (brokerSruct.consumerUrl.equals(rbEprUrl)) {
removedBrokerStruct = brokerSruct;
break;
}