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;
}
// TODO delete this block when adding an AlternateExchange is implemented.
if (alternateExchange != null)
{
agent.raiseException(handle,
"Setting an Alternate Exchange on an Exchange is not yet implemented.");
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.
vhost.createExchange(nameParser.getExchangeName(), State.ACTIVE, durable,
LifetimePolicy.PERMANENT, 0l, exchangeType, properties);
if (alternateExchange != null)
{
// TODO set Alternate Exchange. There doesn't seem to be a way to do this yet!!!
}
} // 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.
Queue queue = vhost.createQueue(nameParser.getQueueName(), State.ACTIVE, durable, false,
LifetimePolicy.PERMANENT, 0l, properties);
// 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