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 (methodName.equals("create")) // method = 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 (type.equals("exchange")) // create 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);
} // End of create exchange.
else if (type.equals("queue")) // create 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);
// Set the queue's alternateExchange, which is just a little bit involved......
// The queue.setAttribute() method needs an org.apache.qpid.server.model.Exchange instance
// not just a name, so we look up org.apache.qpid.server.qmf2.agentdata.Exchange by ID
// and get its associated org.apache.qpid.server.model.Exchange. We can do a look up by ID
// because we needed to use ObjectIds that were based on names in order to allow qpid-config
// 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 (type.equals("binding")) // create binding.
{
Exchange exchange = nameParser.getExchange();
if (exchange == null)