use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method bind.
@Override
public boolean bind(final String destination, String bindingKey, Map<String, Object> arguments, boolean replaceExistingArguments) {
MessageDestination messageDestination = getAttainedMessageDestination(destination);
if (messageDestination == null) {
throw new IllegalArgumentException(String.format("Destination '%s' is not found.", destination));
}
if (bindingKey == null) {
bindingKey = "";
}
if (arguments == null) {
arguments = Collections.emptyMap();
}
Binding newBinding = new BindingImpl(bindingKey, destination, arguments);
boolean modified = false;
for (Binding b : _bindings) {
if (b.getBindingKey().equals(bindingKey) && b.getDestination().equals(messageDestination.getName())) {
if (replaceExistingArguments) {
_bindings.remove(b);
modified = true;
break;
} else {
return false;
}
}
}
_bindings.add(newBinding);
if (isDurable() && messageDestination.isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
final BindingIdentifier bindingIdentifier = new BindingIdentifier(bindingKey, messageDestination);
if (modified) {
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);
}
return true;
}
use of org.apache.qpid.server.model.Binding in project qpid by apache.
the class QmfManagementAgent method childRemoved.
/**
* ConfigurationChangeListener method called when a child ConfiguredObject is removed.
* <p>
* This method checks the type of the child ConfiguredObject that has been removed and raises the appropriate
* QMF2 Events, it then destroys the QMF2 Management Object and removes the mapping between child and the QMF Object.
*
* @param object the parent object that the child is being removed from.
* @param child the child object being removed.
*/
@Override
public void childRemoved(final ConfiguredObject object, final ConfiguredObject child) {
if (_log.isDebugEnabled()) {
_log.debug("childRemoved: " + child.getClass().getSimpleName() + "." + child.getName());
}
child.removeChangeListener(this);
// Look up the associated QmfAgentData and mark it for deletion by the Agent.
QmfAgentData data = _objects.get(child);
if (data != null) {
if (child instanceof Connection) {
// Raise a Client Disconnect Event.
_agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Connection) data).createClientDisconnectEvent());
} else if (child instanceof Session) {
// no-op, don't need to do anything specific when Session is removed.
} else if (child instanceof Exchange) {
// Raise an Exchange Delete Event.
_agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Exchange) data).createExchangeDeleteEvent());
} else if (child instanceof Queue) {
// Raise a Queue Delete Event.
_agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Queue) data).createQueueDeleteEvent());
} else if (child instanceof Binding) {
String eName = ((Binding) child).getExchange().getName();
if (// Don't send Event for Unbinding from default direct.
!eName.equals("<<default>>")) {
// Raise an Unbind Event.
_agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Binding) data).createUnbindEvent());
}
} else if (child instanceof Consumer) {
// Raise an Unsubscribe Event.
_agent.raiseEvent(((org.apache.qpid.server.qmf2.agentdata.Subscription) data).createUnsubscribeEvent());
}
data.destroy();
}
// Remove the mapping from the internal ConfiguredObject->QmfAgentData Map.
_objects.remove(child);
}
use of org.apache.qpid.server.model.Binding in project qpid by apache.
the class Broker method invokeMethod.
/**
* This method acts as a single entry point for QMF methods invoked on the Broker Object.
*
* @param agent the org.apache.qpid.qmf2.agent.Agent instance that we call methodResponse() and raiseException() on.
* @param handle the reply handle used by methodResponse() and raiseException().
* @param methodName the name of the QMF method being invoked.
* @param inArgs a Map of input arguments wrapped in a QmfData Object.
*/
@SuppressWarnings("unchecked")
public void invokeMethod(Agent agent, Handle handle, String methodName, QmfData inArgs) {
if (methodName.equals("create") || methodName.equals("delete")) {
QmfData outArgs = new QmfData();
String name = inArgs.getStringValue("name");
String type = inArgs.getStringValue("type");
NameParser nameParser = new NameParser(name, type);
String vhostName = nameParser.getVirtualHostName();
VirtualHost vhost = nameParser.getVirtualHost();
if (vhost == null) {
if (vhostName == null) {
agent.raiseException(handle, "VirtualHost names for exchange and queue must match.");
} else {
agent.raiseException(handle, "VirtualHost " + vhostName + " not found.");
}
} else {
if (// method = create
methodName.equals("create")) {
try {
// boolean strict = inArgs.getBooleanValue("strict");
Map<String, Object> properties = inArgs.getValue("properties");
boolean durable = false;
Object property = properties.get("durable");
if (property != null && property instanceof Boolean) {
Boolean durableProperty = (Boolean) property;
durable = durableProperty.booleanValue();
properties.remove("durable");
}
if (// create exchange.
type.equals("exchange")) {
/*
System.out.println("Create Exchange");
System.out.println("vhostName = " + vhostName);
System.out.println("exchange name = " + nameParser.getExchangeName());
System.out.println("properties = " + properties);
*/
String exchangeType = "";
property = properties.get("exchange-type");
if (property != null && property instanceof String) {
exchangeType = property.toString();
properties.remove("exchange-type");
}
String alternateExchange = parseAlternateExchange(vhostName, properties);
if (alternateExchange != null && alternateExchange.equals("invalid")) {
agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Exchange being added.");
return;
}
// Note that for Qpid 0.20 the "qpid.msg_sequence=1" and "qpid.ive=1" properties are
// not suppored, indeed no exchange properties seem to be supported yet.
Map<String, Object> attributes = new HashMap<>();
attributes.put(Exchange.NAME, nameParser.getExchangeName());
attributes.put(Exchange.STATE, State.ACTIVE);
attributes.put(Exchange.DURABLE, durable);
attributes.put(Exchange.LIFETIME_POLICY, LifetimePolicy.PERMANENT);
attributes.put(Exchange.TYPE, exchangeType);
attributes.put(Exchange.ALTERNATE_EXCHANGE, alternateExchange);
vhost.createExchange(attributes);
} else // End of create exchange.
if (// create queue.
type.equals("queue")) {
/*
System.out.println("Create Queue");
System.out.println("vhostName = " + vhostName);
System.out.println("queue name = " + nameParser.getQueueName());
System.out.println("properties = " + properties);
*/
// TODO Try to map from the QMF create queue properties to the closest equivalents on
// the Java Broker. Unfortunately there are a *lot* of frustrating little differences.
String alternateExchange = parseAlternateExchange(vhostName, properties);
if (alternateExchange != null && alternateExchange.equals("invalid")) {
agent.raiseException(handle, "Alternate Exchange must belong to the same Virtual Host as the Queue being added.");
return;
}
// I don't *think* that it make sense to allow setting exclusive or autoDelete to
// a queue created from config.
Map<String, Object> attributes = new HashMap<String, Object>(properties);
attributes.put(Queue.NAME, nameParser.getQueueName());
attributes.put(Queue.DURABLE, durable);
attributes.put(Queue.LIFETIME_POLICY, LifetimePolicy.PERMANENT);
// to work, so we may as well make use of this convenience here too.
if (alternateExchange != null) {
ObjectId objectId = new ObjectId("", "org.apache.qpid.broker:exchange:" + alternateExchange, 0);
// Look up Exchange QmfAgentData by ObjectId from the Agent's internal Object store.
QmfAgentData object = agent.getObject(objectId);
if (object != null) {
org.apache.qpid.server.qmf2.agentdata.Exchange ex = (org.apache.qpid.server.qmf2.agentdata.Exchange) object;
Exchange altEx = ex.getExchange();
attributes.put(Queue.ALTERNATE_EXCHANGE, altEx.getId());
}
}
Queue queue = vhost.createQueue(attributes);
} else if (// create binding.
type.equals("binding")) {
Exchange exchange = nameParser.getExchange();
if (exchange == null) {
agent.raiseException(handle, "Cannot create binding on Exchange " + nameParser.getExchangeName());
return;
} else {
Map<String, Object> attributes = Collections.emptyMap();
exchange.createBinding(nameParser.getBindingKey(), nameParser.getQueue(), properties, attributes);
}
}
agent.methodResponse(methodName, handle, outArgs, null);
} catch (Exception e) {
agent.raiseException(handle, e.getMessage());
}
} else // method = delete
{
try {
if (// delete exchange.
type.equals("exchange")) {
Exchange exchange = nameParser.getExchange();
if (exchange != null) {
exchange.delete();
}
} else if (// delete queue.
type.equals("queue")) {
Queue queue = nameParser.getQueue();
if (queue != null) {
queue.deleteAndReturnCount();
}
} else if (// delete binding.
type.equals("binding")) {
Binding binding = nameParser.getBinding();
if (binding != null) {
binding.delete();
}
}
agent.methodResponse(methodName, handle, outArgs, null);
} catch (Exception e) {
agent.raiseException(handle, e.getMessage());
}
}
}
} else // If methodName is not create or delete.
{
agent.raiseException(handle, methodName + " not yet implemented on Broker.");
}
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method destinationRemoved.
@Override
@DoOnConfigThread
public void destinationRemoved(@Param(name = "destination") final MessageDestination destination) {
Iterator<Binding> bindingIterator = _bindings.iterator();
while (bindingIterator.hasNext()) {
Binding b = bindingIterator.next();
if (b.getDestination().equals(destination.getName())) {
final Map<String, Object> bindArguments = UNBIND_ARGUMENTS_CREATOR.createMap(b.getBindingKey(), destination);
getEventLogger().message(_logSubject, BindingMessages.DELETED(String.valueOf(bindArguments)));
onUnbind(new BindingIdentifier(b.getBindingKey(), destination));
_bindings.remove(b);
}
}
if (!autoDeleteIfNecessary()) {
if (destination.isDurable() && isDurable()) {
final Collection<Binding> durableBindings = getDurableBindings();
attributeSet(DURABLE_BINDINGS, durableBindings, durableBindings);
}
}
}
use of org.apache.qpid.server.model.Binding in project qpid-broker-j by apache.
the class AbstractExchange method getPublishingLinks.
@Override
public Collection<Binding> getPublishingLinks(MessageDestination destination) {
List<Binding> bindings = new ArrayList<>();
final String destinationName = destination.getName();
for (Binding b : _bindings) {
if (b.getDestination().equals(destinationName)) {
bindings.add(b);
}
}
return bindings;
}
Aggregations