use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class PostOfficeImpl method removeAddressInfo.
@Override
public AddressInfo removeAddressInfo(SimpleString address, boolean force) throws Exception {
synchronized (addressLock) {
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeRemoveAddress(address));
}
final Bindings bindingsForAddress = getDirectBindings(address);
if (force) {
for (Binding binding : bindingsForAddress.getBindings()) {
if (binding instanceof QueueBinding) {
((QueueBinding) binding).getQueue().deleteQueue(true);
}
}
} else {
if (bindingsForAddress.getBindings().size() > 0) {
throw ActiveMQMessageBundle.BUNDLE.addressHasBindings(address);
}
}
managementService.unregisterAddress(address);
final AddressInfo addressInfo = addressManager.removeAddressInfo(address);
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterRemoveAddress(address, addressInfo));
}
return addressInfo;
}
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class PostOfficeImpl method updateQueue.
@Override
public QueueBinding updateQueue(SimpleString name, RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception {
synchronized (addressLock) {
final QueueBinding queueBinding = (QueueBinding) addressManager.getBinding(name);
if (queueBinding == null) {
return null;
}
final Queue queue = queueBinding.getQueue();
boolean changed = false;
// validate update
if (maxConsumers != null && maxConsumers.intValue() != Queue.MAX_CONSUMERS_UNLIMITED) {
final int consumerCount = queue.getConsumerCount();
if (consumerCount > maxConsumers) {
throw ActiveMQMessageBundle.BUNDLE.invalidMaxConsumersUpdate(name.toString(), maxConsumers, consumerCount);
}
}
if (routingType != null) {
final SimpleString address = queue.getAddress();
final AddressInfo addressInfo = addressManager.getAddressInfo(address);
final EnumSet<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
if (!addressRoutingTypes.contains(routingType)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes);
}
}
// atomic update
if (maxConsumers != null && queue.getMaxConsumers() != maxConsumers.intValue()) {
changed = true;
queue.setMaxConsumer(maxConsumers);
}
if (routingType != null && queue.getRoutingType() != routingType) {
changed = true;
queue.setRoutingType(routingType);
}
if (purgeOnNoConsumers != null && queue.isPurgeOnNoConsumers() != purgeOnNoConsumers.booleanValue()) {
changed = true;
queue.setPurgeOnNoConsumers(purgeOnNoConsumers);
}
if (exclusive != null && queue.isExclusive() != exclusive.booleanValue()) {
changed = true;
queue.setExclusive(exclusive);
}
if (changed) {
final long txID = storageManager.generateID();
try {
storageManager.updateQueueBinding(txID, queueBinding);
storageManager.commitBindings(txID);
} catch (Throwable throwable) {
storageManager.rollback(txID);
logger.warn(throwable.getMessage(), throwable);
throw throwable;
}
}
return queueBinding;
}
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class SimpleAddressManager method validateRoutingTypes.
private void validateRoutingTypes(SimpleString addressName, EnumSet<RoutingType> routingTypes) {
final Bindings bindings = this.mappings.get(addressName);
if (bindings != null) {
for (Binding binding : bindings.getBindings()) {
if (binding instanceof QueueBinding) {
final QueueBinding queueBinding = (QueueBinding) binding;
final RoutingType routingType = queueBinding.getQueue().getRoutingType();
if (!routingTypes.contains(routingType) && binding.getAddress().equals(addressName)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeDelete(routingType, addressName.toString());
}
}
}
}
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class AddressControlImpl method getQueueNames.
@Override
public String[] getQueueNames() throws Exception {
clearIO();
try {
Bindings bindings = postOffice.getBindingsForAddress(addressInfo.getName());
List<String> queueNames = new ArrayList<>();
for (Binding binding : bindings.getBindings()) {
if (binding instanceof QueueBinding) {
queueNames.add(binding.getUniqueName().toString());
}
}
return queueNames.toArray(new String[queueNames.size()]);
} catch (Throwable t) {
throw new IllegalStateException(t.getMessage());
} finally {
blockOnIO();
}
}
use of org.apache.activemq.artemis.core.postoffice.QueueBinding in project activemq-artemis by apache.
the class ActiveMQServerImpl method createQueue.
public Queue createQueue(final AddressInfo addrInfo, final SimpleString queueName, final SimpleString filterString, final SimpleString user, final boolean durable, final boolean temporary, final boolean ignoreIfExists, final boolean transientQueue, final boolean autoCreated, final int maxConsumers, final boolean purgeOnNoConsumers, final boolean exclusive, final boolean lastValue, final boolean autoCreateAddress) throws Exception {
final QueueBinding binding = (QueueBinding) postOffice.getBinding(queueName);
if (binding != null) {
if (ignoreIfExists) {
return binding.getQueue();
} else {
throw ActiveMQMessageBundle.BUNDLE.queueAlreadyExists(queueName, binding.getAddress());
}
}
final Filter filter = FilterImpl.createFilter(filterString);
final long txID = storageManager.generateID();
final long queueID = storageManager.generateID();
final QueueConfig.Builder queueConfigBuilder;
final SimpleString addressToUse = addrInfo == null ? queueName : addrInfo.getName();
queueConfigBuilder = QueueConfig.builderWith(queueID, queueName, addressToUse);
AddressInfo info = postOffice.getAddressInfo(addressToUse);
RoutingType routingType = addrInfo == null ? null : addrInfo.getRoutingType();
RoutingType rt = (routingType == null ? ActiveMQDefaultConfiguration.getDefaultRoutingType() : routingType);
if (autoCreateAddress) {
if (info == null) {
final AddressInfo addressInfo = new AddressInfo(addressToUse, rt);
addressInfo.setAutoCreated(true);
addressInfo.setInternal(addrInfo == null ? false : addrInfo.isInternal());
addAddressInfo(addressInfo);
} else if (!info.getRoutingTypes().contains(rt)) {
EnumSet<RoutingType> routingTypes = EnumSet.copyOf(info.getRoutingTypes());
routingTypes.add(rt);
updateAddressInfo(info.getName(), routingTypes);
}
} else if (info == null) {
throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressToUse);
} else if (!info.getRoutingTypes().contains(rt)) {
throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeForAddress(rt, info.getName().toString(), info.getRoutingTypes());
}
final QueueConfig queueConfig = queueConfigBuilder.filter(filter).pagingManager(pagingManager).user(user).durable(durable).temporary(temporary).autoCreated(autoCreated).routingType(addrInfo.getRoutingType()).maxConsumers(maxConsumers).purgeOnNoConsumers(purgeOnNoConsumers).exclusive(exclusive).lastValue(lastValue).build();
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.beforeCreateQueue(queueConfig) : null);
final Queue queue = queueFactory.createQueueWith(queueConfig);
if (transientQueue) {
queue.setConsumersRefCount(new TransientQueueManagerImpl(this, queue.getName()));
} else {
queue.setConsumersRefCount(new QueueManagerImpl(this, queue.getName()));
}
final QueueBinding localQueueBinding = new LocalQueueBinding(queue.getAddress(), queue, nodeManager.getNodeId());
if (queue.isDurable()) {
storageManager.addQueueBinding(txID, localQueueBinding);
}
try {
postOffice.addBinding(localQueueBinding);
if (queue.isDurable()) {
storageManager.commitBindings(txID);
}
} catch (Exception e) {
try {
if (durable) {
storageManager.rollbackBindings(txID);
}
final PageSubscription pageSubscription = queue.getPageSubscription();
try {
queue.close();
} finally {
if (pageSubscription != null) {
pageSubscription.destroy();
}
}
} catch (Throwable ignored) {
logger.debug(ignored.getMessage(), ignored);
}
throw e;
}
if (addrInfo == null || !addrInfo.isInternal()) {
managementService.registerQueue(queue, queue.getAddress(), storageManager);
}
callBrokerPlugins(hasBrokerPlugins() ? plugin -> plugin.afterCreateQueue(queue) : null);
callPostQueueCreationCallbacks(queue.getName());
return queue;
}
Aggregations