boolean keepID = args.length>5? ((Boolean)args[5]).booleanValue() : false;
// configure the message for sending, using attributes stored as metadata
ProducerState producerState = getProducerState(mi);
if (deliveryMode == -1)
{
// Use the delivery mode of the producer
deliveryMode = producerState.getDeliveryMode();
if (trace) { log.trace("Using producer's default delivery mode: " + deliveryMode); }
}
m.setJMSDeliveryMode(deliveryMode);
if (priority == -1)
{
// Use the priority of the producer
priority = producerState.getPriority();
if (trace) { log.trace("Using producer's default priority: " + priority); }
}
if (priority < 0 || priority > 9)
{
throw new MessageFormatException("Invalid message priority (" + priority + "). " +
"Valid priorities are 0-9");
}
m.setJMSPriority(priority);
if (producerState.isDisableMessageTimestamp())
{
m.setJMSTimestamp(0l);
}
else
{
m.setJMSTimestamp(System.currentTimeMillis());
}
if (timeToLive == Long.MIN_VALUE)
{
// Use time to live value from producer
timeToLive = producerState.getTimeToLive();
if (trace) { log.trace("Using producer's default timeToLive: " + timeToLive); }
}
if (timeToLive == 0)
{
// Zero implies never expires
m.setJMSExpiration(0);
}
else
{
m.setJMSExpiration(System.currentTimeMillis() + timeToLive);
}
if (destination == null)
{
// use destination from producer
destination = producerState.getDestination();
if (destination == null)
{
throw new UnsupportedOperationException("Destination not specified");
}
if (trace) { log.trace("Using producer's default destination: " + destination); }
}
else
{
// if a default destination was already specified then this must be same destination as
// that specified in the arguments
if (producerState.getDestination() != null &&
!producerState.getDestination().equals(destination))
{
throw new UnsupportedOperationException("Where a default destination is specified " +
"for the sender and a destination is " +
"specified in the arguments to the send, " +
"these destinations must be equal");
}
}
// destination should aways be a JBossDestination as this is tested on the MessageProducer creation
// and on the send, so it should be safe to just do this cast
if (((JBossDestination)destination).isTemporary())
{
validateTemporaryDestination(destination);
}
SessionState sessionState = (SessionState)producerState.getParent();
// Generate the message id
ConnectionState connectionState = (ConnectionState)sessionState.getParent();
JBossMessage messageToSend;