use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class ExchangeControllerTest method convertNextVersionLegacyConfiguredObject.
@Test
public void convertNextVersionLegacyConfiguredObject() {
final ExchangeController exchangeController = new ExchangeController(_legacyManagementController, Collections.emptySet());
final String exchangeName = "testExchange";
final String alternateExchangeName = "altExchange";
final String queueName = "testQueue";
final String bindingKey = "testBindingKey";
final LegacyConfiguredObject nextVersionExchange = mock(LegacyConfiguredObject.class);
final AlternateBinding alternateBinding = mock(AlternateBinding.class);
final Binding nextVersionBinding = mock(Binding.class);
final LegacyConfiguredObject nextVersionAlternateExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject nextVersionVirtualHost = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject queue = mock(LegacyConfiguredObject.class);
when(alternateBinding.getDestination()).thenReturn(alternateExchangeName);
when(nextVersionExchange.getCategory()).thenReturn(ExchangeController.TYPE);
when(nextVersionExchange.getAttribute("alternateBinding")).thenReturn(alternateBinding);
when(nextVersionExchange.getAttribute(AbstractConfiguredObject.NAME)).thenReturn(exchangeName);
when(nextVersionExchange.getAttribute("bindings")).thenReturn(Collections.singletonList(nextVersionBinding));
when(nextVersionExchange.getParent(VirtualHostController.TYPE)).thenReturn(nextVersionVirtualHost);
when(nextVersionBinding.getDestination()).thenReturn(queueName);
when(nextVersionBinding.getBindingKey()).thenReturn(bindingKey);
when(nextVersionAlternateExchange.getCategory()).thenReturn(ExchangeController.TYPE);
when(nextVersionAlternateExchange.getAttribute(LegacyConfiguredObject.NAME)).thenReturn(alternateExchangeName);
when(nextVersionVirtualHost.getChildren(ExchangeController.TYPE)).thenReturn(Arrays.asList(nextVersionExchange, nextVersionAlternateExchange));
when(nextVersionVirtualHost.getChildren(QueueController.TYPE)).thenReturn(Collections.singletonList(queue));
final LegacyConfiguredObject convertedExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject convertedAltExchange = mock(LegacyConfiguredObject.class);
final LegacyConfiguredObject convertedQueue = mock(LegacyConfiguredObject.class);
when(_legacyManagementController.convertFromNextVersion(nextVersionExchange)).thenReturn(convertedExchange);
when(_legacyManagementController.convertFromNextVersion(nextVersionAlternateExchange)).thenReturn(convertedAltExchange);
when(_legacyManagementController.convertFromNextVersion(queue)).thenReturn(convertedQueue);
final LegacyConfiguredObject destination = exchangeController.convertFromNextVersion(nextVersionExchange);
assertThat(destination.getAttribute("alternateExchange"), is(equalTo(convertedAltExchange)));
final Collection<LegacyConfiguredObject> children = destination.getChildren(BindingController.TYPE);
assertThat(children.size(), is(equalTo(1)));
final LegacyConfiguredObject o = children.iterator().next();
assertThat(o.getCategory(), is(equalTo(BindingController.TYPE)));
assertThat(o.getAttribute(AbstractConfiguredObject.NAME), is(equalTo(bindingKey)));
assertThat(o.getAttribute("queue"), is(equalTo(convertedQueue)));
assertThat(o.getAttribute("exchange"), is(equalTo(convertedExchange)));
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method bindInternal.
private boolean bindInternal(final String destination, final String bindingKey, Map<String, Object> arguments, final boolean replaceExistingArguments) throws AMQInvalidArgumentException {
MessageDestination messageDestination = getAttainedMessageDestination(destination);
if (messageDestination == null) {
throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
}
if (arguments == null) {
arguments = Collections.emptyMap();
}
Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
Binding previousBinding = null;
for (Binding b : _bindings) {
if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
previousBinding = b;
break;
}
}
if (previousBinding != null && !replaceExistingArguments) {
return false;
}
final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
if (previousBinding != null) {
onBindingUpdated(bindingIdentifier, arguments);
} else {
final Map<String, Object> bindArguments = BIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination, arguments);
getEventLogger().message(_logSubject, BindingMessages.CREATED(String.valueOf(bindArguments)));
onBind(bindingIdentifier, arguments);
messageDestination.linkAdded(this, newBinding);
}
if (previousBinding != null) {
_bindings.remove(previousBinding);
}
_bindings.add(newBinding);
if (isDurable() && messageDestination.isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
return true;
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method onOpen.
@Override
protected void onOpen() {
super.onOpen();
final ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>> durableBindingsAttribute = (ConfiguredDerivedMethodAttribute<Exchange<?>, Collection<Binding>>) getModel().getTypeRegistry().getAttributeTypes(getTypeClass()).get(DURABLE_BINDINGS);
final Collection<Binding> bindings = durableBindingsAttribute.convertValue(getActualAttributes().get(DURABLE_BINDINGS), this);
if (bindings != null) {
_bindings.addAll(bindings);
for (Binding b : _bindings) {
final MessageDestination messageDestination = getOpenedMessageDestination(b.getDestination());
if (messageDestination != null) {
Map<String, Object> arguments = b.getArguments() == null ? Collections.emptyMap() : b.getArguments();
try {
onBind(new BindingIdentifier(b.getBindingKey(), messageDestination), arguments);
} catch (AMQInvalidArgumentException e) {
throw new IllegalConfigurationException("Unexpected bind argument : " + e.getMessage(), e);
}
messageDestination.linkAdded(this, b);
}
}
}
if (getLifetimePolicy() == LifetimePolicy.DELETE_ON_CREATING_LINK_CLOSE) {
if (_creatingLinkInfo != null) {
final LinkModel link;
if (_creatingLinkInfo.isSendingLink()) {
link = _virtualHost.getSendingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
} else {
link = _virtualHost.getReceivingLink(_creatingLinkInfo.getRemoteContainerId(), _creatingLinkInfo.getLinkName());
}
addLifetimeConstraint(link);
} else {
throw new IllegalArgumentException("Exchanges created with a lifetime policy of " + getLifetimePolicy() + " must be created from a AMQP 1.0 link.");
}
}
if (getAlternateBinding() != null) {
String alternateDestination = getAlternateBinding().getDestination();
_alternateBindingDestination = getOpenedMessageDestination(alternateDestination);
if (_alternateBindingDestination != null) {
_alternateBindingDestination.addReference(this);
} else {
LOGGER.warn("Cannot find alternate binding destination '{}' for exchange '{}'", alternateDestination, toString());
}
}
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method unbind.
@Override
public boolean unbind(@Param(name = "destination", mandatory = true) final String destination, @Param(name = "bindingKey") String bindingKey) {
MessageDestination messageDestination = getAttainedMessageDestination(destination);
if (messageDestination != null) {
Iterator<Binding> bindingIterator = _bindings.iterator();
while (bindingIterator.hasNext()) {
Binding binding = bindingIterator.next();
if (binding.getBindingKey().equals(bindingKey) && binding.getDestination().equals(destination)) {
_bindings.remove(binding);
messageDestination.linkRemoved(this, binding);
onUnbind(new BindingIdentifier(bindingKey, messageDestination));
if (!autoDeleteIfNecessary()) {
if (isDurable() && messageDestination.isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
}
final Map<String, Object> bindArguments = UNBIND_ARGUMENTS_CREATOR.createMap(bindingKey, destination);
getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
return true;
}
}
}
return false;
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractVirtualHost method hasDifferentBindings.
private boolean hasDifferentBindings(final Exchange<?> exchange, final Queue queue, final Map<String, Map<String, Object>> bindings) {
for (String binding : bindings.keySet()) {
boolean theSameBindingFound = false;
for (Binding publishingLink : exchange.getPublishingLinks(queue)) {
if (publishingLink.getBindingKey().equals(binding)) {
Map<String, Object> expectedArguments = bindings.get(binding);
Map<String, Object> actualArguments = publishingLink.getArguments();
if (new HashMap<>(expectedArguments == null ? Collections.emptyMap() : expectedArguments).equals(new HashMap<>(actualArguments == null ? Collections.emptyMap() : actualArguments))) {
theSameBindingFound = true;
}
}
}
if (!theSameBindingFound) {
return true;
}
}
return false;
}
Aggregations