use of org.apache.activemq.artemis.core.postoffice.Binding 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.Binding in project activemq-artemis by apache.
the class PostOfficeImpl method removeBinding.
@Override
public synchronized Binding removeBinding(final SimpleString uniqueName, Transaction tx, boolean deleteData) throws Exception {
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.beforeRemoveBinding(uniqueName, tx, deleteData));
}
addressSettingsRepository.clearCache();
Binding binding = addressManager.removeBinding(uniqueName, tx);
if (binding == null) {
throw new ActiveMQNonExistentQueueException();
}
if (deleteData && addressManager.getBindingsForRoutingAddress(binding.getAddress()) == null) {
pagingManager.deletePageStore(binding.getAddress());
deleteDuplicateCache(binding.getAddress());
}
if (binding.getType() == BindingType.LOCAL_QUEUE) {
Queue queue = (Queue) binding.getBindable();
managementService.unregisterQueue(uniqueName, binding.getAddress(), queue.getRoutingType());
} else if (binding.getType() == BindingType.DIVERT) {
managementService.unregisterDivert(uniqueName, binding.getAddress());
}
if (binding.getType() != BindingType.DIVERT) {
TypedProperties props = new TypedProperties();
props.putSimpleStringProperty(ManagementHelper.HDR_ADDRESS, binding.getAddress());
props.putSimpleStringProperty(ManagementHelper.HDR_CLUSTER_NAME, binding.getClusterName());
props.putSimpleStringProperty(ManagementHelper.HDR_ROUTING_NAME, binding.getRoutingName());
props.putIntProperty(ManagementHelper.HDR_DISTANCE, binding.getDistance());
props.putLongProperty(ManagementHelper.HDR_BINDING_ID, binding.getID());
if (binding.getFilter() == null) {
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, null);
} else {
props.putSimpleStringProperty(ManagementHelper.HDR_FILTERSTRING, binding.getFilter().getFilterString());
}
managementService.sendNotification(new Notification(null, CoreNotificationType.BINDING_REMOVED, props));
}
binding.close();
if (server.hasBrokerPlugins()) {
server.callBrokerPlugins(plugin -> plugin.afterRemoveBinding(binding, tx, deleteData));
}
return binding;
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class WildcardAddressManager method removeBinding.
/**
* If the address is a wild card then the binding will be removed from the actual mappings for any linked address.
* otherwise it will be removed as normal.
*
* @param uniqueName the name of the binding to remove
* @return true if this was the last mapping for a specific address
*/
@Override
public Binding removeBinding(final SimpleString uniqueName, Transaction tx) throws Exception {
Binding binding = super.removeBinding(uniqueName, tx);
if (binding != null) {
Address add = getAddress(binding.getAddress());
if (add.containsWildCard()) {
for (Address theAddress : add.getLinkedAddresses()) {
super.removeBindingInternal(theAddress.getAddress(), uniqueName);
}
}
removeAndUpdateAddressMap(add);
}
return binding;
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class BindingsImpl method routeFromCluster.
private void routeFromCluster(final Message message, final RoutingContext context, final byte[] ids) throws Exception {
byte[] idsToAck = (byte[]) message.removeProperty(Message.HDR_ROUTE_TO_ACK_IDS);
List<Long> idsToAckList = new ArrayList<>();
if (idsToAck != null) {
ByteBuffer buff = ByteBuffer.wrap(idsToAck);
while (buff.hasRemaining()) {
long bindingID = buff.getLong();
idsToAckList.add(bindingID);
}
}
ByteBuffer buff = ByteBuffer.wrap(ids);
while (buff.hasRemaining()) {
long bindingID = buff.getLong();
Binding binding = bindingsMap.get(bindingID);
if (binding != null) {
if (idsToAckList.contains(bindingID)) {
binding.routeWithAck(message, context);
} else {
binding.route(message, context);
}
} else {
ActiveMQServerLogger.LOGGER.bindingNotFound(bindingID, message.toString(), this.toString());
}
}
}
use of org.apache.activemq.artemis.core.postoffice.Binding in project activemq-artemis by apache.
the class BindingsImpl method route.
private void route(final Message message, final RoutingContext context, final boolean groupRouting) throws Exception {
/* This is a special treatment for scaled-down messages involving SnF queues.
* See org.apache.activemq.artemis.core.server.impl.ScaleDownHandler.scaleDownMessages() for the logic that sends messages with this property
*/
byte[] ids = (byte[]) message.removeExtraBytesProperty(Message.HDR_SCALEDOWN_TO_IDS);
if (ids != null) {
ByteBuffer buffer = ByteBuffer.wrap(ids);
while (buffer.hasRemaining()) {
long id = buffer.getLong();
for (Map.Entry<Long, Binding> entry : bindingsMap.entrySet()) {
if (entry.getValue() instanceof RemoteQueueBinding) {
RemoteQueueBinding remoteQueueBinding = (RemoteQueueBinding) entry.getValue();
if (remoteQueueBinding.getRemoteQueueID() == id) {
message.putBytesProperty(Message.HDR_ROUTE_TO_IDS, ByteBuffer.allocate(8).putLong(remoteQueueBinding.getID()).array());
}
}
}
}
}
boolean routed = false;
for (Binding binding : exclusiveBindings) {
if (binding.getFilter() == null || binding.getFilter().match(message)) {
binding.getBindable().route(message, context);
routed = true;
}
}
if (!routed) {
// Remove the ids now, in order to avoid double check
ids = message.removeExtraBytesProperty(Message.HDR_ROUTE_TO_IDS);
// Fetch the groupId now, in order to avoid double checking
SimpleString groupId = message.getGroupID();
if (ids != null) {
routeFromCluster(message, context, ids);
} else if (groupingHandler != null && groupRouting && groupId != null) {
routeUsingStrictOrdering(message, context, groupingHandler, groupId, 0);
} else {
if (logger.isTraceEnabled()) {
logger.trace("Routing message " + message + " on binding=" + this);
}
for (Map.Entry<SimpleString, List<Binding>> entry : routingNameBindingMap.entrySet()) {
SimpleString routingName = entry.getKey();
List<Binding> bindings = entry.getValue();
if (bindings == null) {
// ConcurrentHashMap behaviour!
continue;
}
Binding theBinding = getNextBinding(message, routingName, bindings);
if (theBinding != null) {
theBinding.route(message, context);
}
}
}
}
}
Aggregations