long visibilityTimeout, Map<String, String> attributes)
throws MessageBoxException {
// Check permission to receive messages
if (!authorizationHandler.isAuthorized(
messageBoxId, MessageBoxConstants.SQS_OPERATION_RECEIVE_MESSAGE)) {
throw new MessageBoxException("AccessDenied");
}
if (!registryMessageBoxHandler.isMessageBoxExists(messageBoxId)) {
throw new MessageBoxException("AWS.SimpleQueueService.NonExistentQueue");
}
if (visibilityTimeout == 0) {
visibilityTimeout = registryMessageBoxHandler.getMessageBoxDetails(messageBoxId).
getDefaultVisibilityTimeout();
}
try {
List<SQSMessage> sqsMessageList = new ArrayList<SQSMessage>();
// Fetch messages
while (0 < maximumNumberOfMessages) {
// Create and store lock
MessageLock messageLock = JMSQueueHandler.popMessage(messageBoxId, visibilityTimeout);
if (messageLock == null) {
break;
}
messageLock.setLockStore(getMessageLocks());
getMessageLocks().put(messageLock.getReceiptHandle(), messageLock);
// Create and store SQS message
SQSMessage sqsMessage = jmsMessageToSQSMessage(messageLock.getJmsMessage());
sqsMessage.setReceiptHandle(messageLock.getReceiptHandle());
// set visibility timeout of message as default visibility timeout of messageBox
if (sqsMessage.getDefaultVisibilityTimeout() == 0) {
MessageBoxDetails messageBoxDetails =
registryMessageBoxHandler.getMessageBoxDetails(messageBoxId);
sqsMessage.setDefaultVisibilityTimeout(
messageBoxDetails.getDefaultVisibilityTimeout());
}
sqsMessage.setDefaultVisibilityTimeout(visibilityTimeout);
sqsMessageList.add(sqsMessage);
maximumNumberOfMessages--;
}
queueManager.setQueueUpdatedTime(JMSQueueHandler.getJMSQueueName(messageBoxId));
return sqsMessageList;
} catch (JMSQueueHandlerException e) {
throw new MessageBoxException("InternalError", e);
}
}