if (!m.matches()) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, "QueueName " + queueName + " is invalid. Only alphanumeric and hyphen and underscore allowed.");
}
String relativeQueueUrl = new CQSQueue(queueName, userId).getRelativeUrl();
CQSQueue queue = PersistenceFactory.getQueuePersistence().getQueue(relativeQueueUrl);
if (queue != null) {
return queue;
}
queue = new CQSQueue(queueName, userId);
if (visibilityTimeout != null) {
if (visibilityTimeout < 0 || visibilityTimeout > CMBProperties.getInstance().getCQSMaxVisibilityTimeOut()) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.VISIBILITY_TIMEOUT + " should be between 0 and " + CMBProperties.getInstance().getCQSMaxVisibilityTimeOut());
}
queue.setVisibilityTO(visibilityTimeout);
}
if (policy != null) {
//TODO: validate policy
queue.setPolicy(policy);
}
if (messageRetentionPeriod != null) {
if (messageRetentionPeriod < 0 || messageRetentionPeriod > CMBProperties.getInstance().getCQSMaxMessageRetentionPeriod()) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.MESSAGE_RETENTION_PERIOD + " should be between 0 and " + CMBProperties.getInstance().getCQSMaxMessageRetentionPeriod());
}
queue.setMsgRetentionPeriod(messageRetentionPeriod);
}
if (delaySeconds != null) {
if (delaySeconds < 0 || delaySeconds > CMBProperties.getInstance().getCQSMaxMessageDelaySeconds()) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.DELAY_SECONDS + " should be between 0 and " + CMBProperties.getInstance().getCQSMaxMessageDelaySeconds());
}
queue.setDelaySeconds(delaySeconds);
}
if (receiveMessageWaitTimeSeconds != null) {
if (receiveMessageWaitTimeSeconds < 0 || receiveMessageWaitTimeSeconds > CMBProperties.getInstance().getCMBRequestTimeoutSec()) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.RECEIVE_MESSAGE_WAIT_TIME_SECONDS + " should be between 0 and " + CMBProperties.getInstance().getCQSMaxMessageDelaySeconds());
}
queue.setReceiveMessageWaitTimeSeconds(receiveMessageWaitTimeSeconds);
}
if (numberOfPartitions != null) {
if (numberOfPartitions < 1) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.NUMBER_OF_PARTITIONS + " should be at least 1");
}
queue.setNumberOfPartitions(numberOfPartitions);
}
if (numberOfShards != null) {
if (numberOfShards < 1 || numberOfShards > 100) {
throw new CMBException(CMBErrorCodes.InvalidParameterValue, CQSConstants.NUMBER_OF_SHARDS + " should be between 1 and 100");
}
queue.setNumberOfShards(numberOfShards);
}
if (isCompressed != null) {
queue.setCompressed(isCompressed);
}
PersistenceFactory.getQueuePersistence().createQueue(queue);
for (int shard = 0; shard < numberOfShards; shard++) {
PersistenceFactory.getCQSMessagePersistence().checkCacheConsistency(queue.getRelativeUrl(), shard, false);
}
long ts2 = System.currentTimeMillis();
emitLogLine(userId, "SendMessage", relativeQueueUrl, null, ts2-ts1);