_currentMessage.getContentHeader(),
getProtocolSession().getLastReceivedTime());
final StoredMessage<MessageMetaData> handle = _messageStore.addMessage(messageMetaData);
final AMQMessage amqMessage = createAMQMessage(_currentMessage, handle);
MessageReference reference = amqMessage.newReference();
try
{
int bodyCount = _currentMessage.getBodyCount();
if(bodyCount > 0)
{
long bodyLengthReceived = 0;
for(int i = 0 ; i < bodyCount ; i++)
{
ContentBody contentChunk = _currentMessage.getContentChunk(i);
handle.addContent((int)bodyLengthReceived, ByteBuffer.wrap(contentChunk.getPayload()));
bodyLengthReceived += contentChunk.getSize();
}
}
if(!checkMessageUserId(_currentMessage.getContentHeader()))
{
_transaction.addPostTransactionAction(new WriteReturnAction(AMQConstant.ACCESS_REFUSED, "Access Refused", amqMessage));
}
else
{
final boolean immediate = _currentMessage.getMessagePublishInfo().isImmediate();
final InstanceProperties instanceProperties =
new InstanceProperties()
{
@Override
public Object getProperty(final Property prop)
{
switch(prop)
{
case EXPIRATION:
return amqMessage.getExpiration();
case IMMEDIATE:
return immediate;
case PERSISTENT:
return amqMessage.isPersistent();
case MANDATORY:
return _currentMessage.getMessagePublishInfo().isMandatory();
case REDELIVERED:
return false;
}
return null;
}
};
int enqueues = _currentMessage.getDestination().send(amqMessage,
amqMessage.getInitialRoutingAddress(),
instanceProperties, _transaction,
immediate ? _immediateAction : _capacityCheckAction
);
if(enqueues == 0)
{
handleUnroutableMessage(amqMessage);
}
else
{
incrementOutstandingTxnsIfNecessary();
handle.flushToStore();
}
}
}
finally
{
reference.release();
}
}
finally
{